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. 终于懂了:TWinControl主要是Delphi官方用来封装Windows的官方控件,开发者还是应该是有TCustomControl来开发三方控件

    再具体一点,就是TWinControl一般情况下不需要Canvas和Paint(TForm是个例外),而TCustomControl自带这2个. 同时开发者应该使用TGraphicControl,而不 ...

  2. [课堂实践与项目]NavigationController与TabBarController的综合使用及易错点分析(包含消息提醒,app更新)

    陈述:我们在使用tabbarController的时候,我们总会和NavagationController联合起来.但是不联合的时候又是什么样的一种pool的情况呢?我们就单单的 TabBarCont ...

  3. delphi中覆盖最大化消息(覆盖WM_GETMINMAXINFO消息)

    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; ...

  4. 水平线、垂直线——axure线框图部件库介绍

    1. 将水平线.垂直线拖动到axure页面编辑区域,如图:  2. 水平线.垂直线相关属性设置 主要属性有.线条的颜色.粗细.线条的样式.箭头的样式 来自:非原型不设计

  5. 张佩的Dump服务

    [亦请参考: http://www.yiiyee.cn/Blog/dumpservice/ ] 张佩提供 有偿但 价格极低的Dump文件分析服务 ! . 如果你有一个Dump文件——不管是应用程序还是 ...

  6. try catch finally的执行顺序到底是怎样的?

    首先执行try,如果有异常执行catch,无论如何都会执行finally 一个函数中肯定会执行finally中的部分. 关于一个函数的执行过程是,当有return以后,函数就会把这个数据存储在某个位置 ...

  7. android布局margin和padding差异!

    事实上从使用的时候就能够差别开来. android:padding android:layout_margin padding是在本控件级别的,而margin是在layout级别的. 最好拿有背景的控 ...

  8. hadoop学习;hadoop伪分布搭建

    先前已经做了准备工作安装jdk什么的,以下開始ssh免password登陆.这里我们用的是PieTTY工具,当然你也能够直接在linux下直接操作 ssh(secure shell),运行命令 ssh ...

  9. mysql 分区和集群

    集群和分区:http://han-zw.iteye.com/blog/1662941http://www.php-note.com/article/detail/794 分区:http://lober ...

  10. FairScheduler的任务调度机制——assignTasks

    首先需要了解FairScheduler是如何在各个Pool之间分配资源,以及每个Pool如何在Job之间分配资源的.FairScheduler的分配资源发生在update()方法中,而该方法由一个线程 ...