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. Spring MVC 学习笔记 json格式的输入和输出

    Spring mvc处理json需要使用jackson的类库,因此为支持json格式的输入输出需要先修改pom.xml增加jackson包的引用 <!-- json --> <dep ...

  2. 添加Main-Class到manifest中

    Maven默认打包生成的jar是不能够直接运行的,因为带有main方法的类信息不会添加到manifest中(打开jar文件中的META-INF/MANIFEST.MF文件,将无法看到Main-Clas ...

  3. hdu2492 Ping pong

    hdu2492 Ping pong 题意:一群乒乓爱好者居住在一条直线上,如果两个人想打比赛需要一个裁判,裁判的 位置 必须在两者之间 ,裁判的能力也必须不大于 参赛者最大的,不小于参赛者最小的 白皮 ...

  4. 符号文件(.pdb)——Windows 应用程序调试必备

    最近在做项目需求过程中,时不时会遇到崩溃,总是异常中断,于是学习了windbg进行调试的一些基础,windbg在接下来文章进行更新,先介绍在windbg调试中一个重要文件(符号文件) 一.符号文件定义 ...

  5. 公钥password学中的素数以及对称加密

        password学.一向被人们觉得门槛非常高,特别高端...这也是实际,可是这决不意味着普通人无法了解它的精髓.对于喜欢画圆的人来讲,即便是理解了password技术背后的哪怕一点理论,也是激 ...

  6. 同一个form里,不管哪个 submit 都是直接提交form表单里的内容

    要达到你的目的,就不能用类型为 submit 的按钮,要用 button,然后加onclick 方法来自定义预处理参数,然后再调用 submit 方法提交表单,比如 <script type=& ...

  7. Windows phone 8 学习笔记

    Windows phone 8 学习笔记(1) 触控输入  http://www.apkbus.com/android-138547-1-1.html Windows phone 8 学习笔记(2) ...

  8. HDU4549 M斐波那契数

    M斐波那契数列 题目分析: M斐波那契数列F[n]是一种整数数列,它的定义例如以下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 如今给 ...

  9. 【测试】这是用微软word发布的博客

    参考文章: http://blog.163.com/dsp163@126/blog/static/795585732011573383290/ 试试图片, 美女镇楼:    

  10. Selenium WebDriver java 简单实例

    开发环境 JDK 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html Eclipse: 下载地址:http ...