Notes:  directory structure:  cmake, cmake/Tutorial, cmake/Tutorial/MathLibs

1. File lists in cmake/Tutorial

CMakeLists.txt

TutorialConfig.h.in

tutorial.cxx

2. File lists in cmake/Tutorial/MathLibs

CMakeLists.txt

MathLibs.h

mysqrt.cxx

3. cmake/Tutorial/CMakeLists.txt

cmake_minimum_required (VERSION 2.6)

project (Tutorial)

# The version number.

set (Tutorial_VERSION_MAJOR 1)

set (Tutorial_VERSION_MINOR 0)

set(CMAKE_BUILD_TYPE DEBUG)

set(CMAKE_C_FLAGS "-O0 -ggdb")

set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb")

set(CMAKE_C_FLAGS_RELEASE "-O3")

set(CMAKE_CXX_FLAGS "-O0 -ggdb")

set(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb")

set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# configure a header file to pass some of the CMake settings

# to the source code

configure_file (

  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"

  "${PROJECT_SOURCE_DIR}/TutorialConfig.h"

  )

# add the binary tree to the search path for include files

# so that we will find TutorialConfig.h

include_directories("${PROJECT_SOURCE_DIR}")

# should we use our own math functions?

option (USE_MYMATH

        "Use tutorial provided math implementation" ON)

# add the MathFunctions library?

#

if (USE_MYMATH)

  include_directories ("${PROJECT_SOURCE_DIR}/MathLibs")

  add_subdirectory (MathLibs)

  set (EXTRA_LIBS ${EXTRA_LIBS} MathLibs)

endif (USE_MYMATH)

# add the executable

add_executable (Tutorial.x tutorial.cxx)

target_link_libraries (Tutorial.x  ${EXTRA_LIBS})

4. cmake/Tutorial/MathLibs/CMakeLists.txt

add_library(MathLibs mysqrt.cxx)

5. Configure and Compile

do so  in cmake directory as the followings

cmake -DUSE_MYMATH=on Tutorial

make

6. others

add_library (core
OBJECT ${SOURCES})

add_library
(static STATIC
$<TARGET_OBJECTS:core>)

add_library
(shared SHARED
$<TARGET_OBJECTS:core>)

The above will build static and shared library from the same set of object files.

This improves compilation time considerably as source files will be compiled

only once and used in multiple targets.




CMake Intro - CMakeLists.txt的更多相关文章

  1. CMake之CMakeLists.txt编写入门

    自定义变量 主要有隐式定义和显式定义两种. 隐式定义的一个例子是PROJECT指令,它会隐式的定义< projectname >_BINARY_DIR和< projectname & ...

  2. cmake 学习-cmakelists.txt

    #设置库的路径,电脑里有qt4以及qt5,使用qt5时 设置qt5的环境变量(路径). set(CMAKE_PREFIX_PATH $ENV{QTDIR}) #设定工程名称 Project(prona ...

  3. Cmake知识----编写CMakeLists.txt文件编译C/C++程序

    1.CMake编译原理 CMake是一种跨平台编译工具,比make更为高级,使用起来要方便得多.CMake主要是编写CMakeLists.txt文件,然后用cmake命令将CMakeLists.txt ...

  4. [CMAKE] 详解CMakeLists.txt文件

    [快速查询]https://cmake.org/cmake/help/v2.8.8/cmake.html#section_Commands 1 CMake简介 CMake是跨平台编译工具,比make更 ...

  5. Cmake知识----编写CMakeLists.txt文件编译C/C++程序(转)

    1.CMake编译原理 CMake是一种跨平台编译工具,比make更为高级,使用起来要方便得多.CMake主要是编写CMakeLists.txt文件,然后用cmake命令将CMakeLists.txt ...

  6. CMakeLists.txt使用

    背景:C++代码在编译的过程中需要进行文件的包含,该文主要介绍CMakeLists.txt相关语法 CMake之CMakeLists.txt编写入门

  7. [forward] cmake, CMakeLists.txt梳理

    cmake intro 原文请见 cmake使用总结(转)-工程主目录CMakeList文件编写 在 Linux 下进行开发很多人选择编写 makefile 文件进行项目环境搭建,而makefile ...

  8. CMAKE 生成VS2008静态库工程 与 CMAKE使用,CMakeLists.txt编写总结

    cmake -G"Visual Studio 9 2008 Win64" 以上命令得用cd命令切换到顶层CMakeLists.txt的当前目录,才能生效 以下是CMakeLists ...

  9. make Makefile 与 cmake CMakeLists.txt

    make Makefile 与 cmake CMakeLists.txt 大家都知道,写程序大体步骤为: 1.用编辑器编写源代码,如.c文件. 2.用编译器编译代码生成目标文件,如.o. 3.用链接器 ...

随机推荐

  1. 语法糖(Syntactic sugar)

    语法糖(Syntactic sugar),是由Peter J. Landin(和图灵一样的天才人物,是他最先发现了Lambda演算,由此而创立了函数式编程)创造的一个词语,它意指那些没有给计算机语言添 ...

  2. C#超级有用的一种类型—匿名类型

    顾名思义 匿名类型就是没有名字的类型.当一个新的匿名对象定义与前面已经存在的类型定义的内部变量类型同样时,编译器就会仅仅生成一个类定义,而不是各一个. 匿名类型对象中仍然能够再包括匿名对象. 在C#3 ...

  3. hdu1003 最大连续子序和

    Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...

  4. boost asio io_service学习笔记

    构造函数 构造函数的主要动作就是调用CreateIoCompletionPort创建了一个初始iocp. Dispatch和post的区别 Post一定是PostQueuedCompletionSta ...

  5. LintCode 二叉树的层次遍历 II

    中等 二叉树的层次遍历 II 查看执行结果 42% 通过 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历) 您在真实的面试中是否遇到过这个 ...

  6. c# 使用OracleParameter,同时使用replace函数

    也算不上是手误吧,这个问题竟然困扰了我那么多天,就是更新代码的时候,使用replace,但是oracle在.net下竟然是不支持汉字,所谓使用类似update x set y='m' where y= ...

  7. jquery控制动态生成的gridview中多列checkbox的全选反选及自动判断是否全选状态

    动态生成的Gridview的前台html代码如下:     <table class="usertableborder" cellspacing="0" ...

  8. python与其它语言进行比較

    近期python语言貌似比較火, 今天闲来无事,简单的看了下,算是个入门吧.一门语言之所以值得这么多人去学,必然有它的独到之处,以下我们就用python和其它语言做个比較. Pythond VS C# ...

  9. Ural 1073 Square Country (DP)

    题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...

  10. oracle RAC搭建中的潜规则 该死的app

    oracle RAC 安装目录必须是 ORACLE_BASE=/u01/app/grid ORACLE_HOME=/u01/app/11.2.0/grid 看着中间有个app,又没什么实际用处,就删掉 ...