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. 百度地图api基本用法

    首先 ,如果想调用百度地图api,你需要获取一个百度地图api的密钥. 申请密钥很简单,在百度地图api的首页就有相关链接,填写相关信息百度就会给你一个密钥了. 接下来,就是引入百度地图的api 关键 ...

  2. C#对数字添加逗号,千分位

    /// <summary> /// 对数字添加”,“号,可以处理负数以及带有小数的情况 /// </summary> /// <param name="vers ...

  3. 刘德华夏日Fiesta演唱会上那个表演探戈舞的演员是谁啊?_百度知道

    刘德华夏日Fiesta演唱会上那个表演探戈舞的演员是谁啊?_百度知道     刘德华夏日Fiesta演唱会上那个表演探戈舞的演员是谁啊?    2008-05-28 00:04 topofhill | ...

  4. MSSQL - 存储过程事物

    效果: 创建带有事物的存储过程: use sales --指定数据库 create table bb --创建bb 这个表 ( ID int not null primary key ,--账号 Mo ...

  5. Spring MVC程序

    Spring MVC程序(IDEA开发环境)   回顾Java平台上Web开发历程来看,从Servlet出现开始,到JSP繁盛一时,然后是Servlet+JSP时代,最后演化为现在Web开发框架盛行的 ...

  6. 14.10.4 Defragmenting a Table 整理表

    14.10.4 Defragmenting a Table 整理表: 随机插入或者删除从一个secondary index 可以导致index变的fragmented Fragmentation意味着 ...

  7. 性能测试之LoardRunner 结果分析

    性能结果分析是性能测试中的重中之重,也是难点所在,以下总结了看图的一些顺序: 1.首先可以检查Analysis模块提供的Summary Report,整个测试过程中我们所关心的各业务 2.首先关注性能 ...

  8. Linux改动文件权限记录

    1.从文件类型上分可分为三种, 用ls-l查询,以"一"开头的是文件,以字母"d"开头的是文件夹(俗称文件夹),以字母"l"开头的是连接. ...

  9. [置顶] window.open()你真的会了吗?

    一.window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法: window.open(pageURL,name, ...

  10. 轻应用 lapp

    轻应用 LAPP (Light App) 即轻应用是一种无需下载.即搜即用的全功能 App,既有媲美甚至超越native app的用户体验,又具备webapp的可被检索与智能分发的特性,将有效解决优质 ...