本节要讨论的是cmake的两个命令: option 和 configure_file
option 选项,让你可以根据选项值进行条件编译。
configure_file 配置文件,让你可以在代码文件中使用CMake中定义的的变量
*
option
Provides an option that the user can optionally select.
option 提供一个用户可以任选的选项。语法如下
option(<option_variable> "help string describing option"
[initial value])
Provide an option for the user to select as ON or OFF. If no initial value is provided, OFF is used.
option 提供选项让用户选择是 ON 或者 OFF ,如果没有提供初始化值,使用OFF。
也就是说默认的值是OFF。 但是请注意:这个option命令和你本地是否存在编译缓存的关系很大。
所以,如果你有关于 option 的改变,那么请你务必清理 CMakeCache.txt 和 CMakeFiles 文件夹。
还有,请使用标准的 [initial value] 值 ON 或者 OFF。 可以在命令行通过以下的方式设置选项
比如想打开 FOO_ENABLE 选项 -DFOO_ENABLE=ON
*
configure_file
configure_file 的作用是让普通文件也能使用CMake中的变量。
也就是说代码文件中可以使用CMake中的变量。
语法如下:
configure_file(<input> <output>
[COPYONLY] [ESCAPE_QUOTES] [@ONLY]
[NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
Copies an <input> file to an <output> file and substitutes variable values referenced as @VAR@ or ${VAR} in the input file content.
Each variable reference will be replaced with the current value of the variable, or the empty string if the variable is not defined.
Furthermore, input lines of the form: 拷贝一个 <input>(输入文件) 文件到 <output> (输出文件),并且替换输入文件中被 @VAR@ 或者 ${VAR} 引用的变量值。每一个变量将被替换成当前的变量值(注:CMake中的变量值)或者空串当变量未定义。 输入文件中的
#cmakedefine VAR ...
将被替换为
#define VAR ...
或者
/* #undef VAR */
下面看看各选项的意义
COPYONLY
Copy the file without replacing any variable references or other content. This option may not be used with NEWLINE_STYLE.
只拷贝文件,不进行任何的变量替换。这个选项在指定了 NEWLINE_STYLE 选项时不能使用(无效)。
ESCAPE_QUOTES
Escape any substituted quotes with backslashes (C-style).
躲过任何的反斜杠(C风格)转义。
注:躲避转义,比如你有个变量在CMake中是这样的
set(FOO_STRING "\"foo\"")
那么在没有 ESCAPE_QUOTES 选项的状态下,通过变量替换将变为 ""foo"",如果指定了 ESCAPE_QUOTES 选项,变量将不变。
@ONLY
Restrict variable replacement to references of the form @VAR@. This is useful for configuring scripts that use ${VAR} syntax.
限制变量替换,让其只替换被 @VAR@ 引用的变量(那么 ${VAR} 格式的变量将不会被替换)。这在配置 ${VAR} 语法的脚本时是非常有用的。 NEWLINE_STYLE <style>
Specify the newline style for the output file. Specify UNIX or LF for \n newlines, or specify DOS, WIN32, or CRLF for \r\n newlines. This option may not be used with COPYONLY.
指定输出文件中的新行格式。UNIX 和 LF 的新行是 \n ,DOS 和 WIN32 和 CRLF 的新行格式是 \r\n 。 这个选项在指定了 COPYONLY 选项时不能使用(无效)。 Example Consider a source tree containing a foo.h.in file:
#cmakedefine FOO_ENABLE
#cmakedefine FOO_STRING "@FOO_STRING@"
An adjacent CMakeLists.txt may use configure_file to configure the header:
option(FOO_ENABLE "Enable Foo" ON)
if(FOO_ENABLE)
set(FOO_STRING "foo")
endif()
configure_file(foo.h.in foo.h @ONLY)
This creates a foo.h in the build directory corresponding to this source directory. If the FOO_ENABLE option is on, the configured file will contain:
#define FOO_ENABLE
#define FOO_STRING "foo"
Otherwise it will contain:
/* #undef FOO_ENABLE */
/* #undef FOO_STRING */
One may then use the include_directories() command to specify the output directory as an include directory:
include_directories(${CMAKE_CURRENT_BINARY_DIR})
so that sources may include the header as #include <foo.h>.

cmake的两个命令: option 和 configure_file的更多相关文章

  1. cmake的四个命令:add_compile_options、add_definitions、target_compile_definitions、build_command

    cmake的四个命令:add_compile_options.add_definitions.target_compile_definitions.build_command add_compile_ ...

  2. Linux下df与du两个命令的差别?

    Linux下df与du两个命令的差别? 一.df显示文件系统的使用情况,与du比較,就是更全盘化. 最经常使用的就是 df -T,显示文件系统的使用情况并显示文件系统的类型. 举比例如以下: [roo ...

  3. linux中chmod与chown两个命令详解

    在linux系统中chmod,chown命令都可以来设置权限了,但它们也是有区别的,下文小编为各位介绍chmod与chown两个命令用法与区别介绍. 今天要分享的2个命令也是我们平时常用的,chmod ...

  4. Windows中将javac和java两个命令集成到UltraEdit工具栏

    1. 目的 将javac和java两个命令集成到UltraEdit工具栏,以方便在UltraEdit中编辑简单的java文件后,能够直接进行编译,运行. 2. 环境 UrtalEdit版本18.20: ...

  5. Linux下显示硬盘空间的两个命令

    1.df -h ,用于显示目前所有文件系统的可用空间及使用情况,示例如下: [root@msg45 ~]# df -hFilesystem                    Size  Used ...

  6. Django orm 中 python manage.py makemigrations 和 python manage.py migrate 这两条命令用途

    生成一个临时文件 python manage.py makemigrations 这时其实是在该app下建立 migrations目录,并记录下你所有的关于modes.py的改动,比如0001_ini ...

  7. linux查看网络ip得两个命令ifconfig和 ip addr

    在安装linux 得时候,我们要选择桥接网络,相当于本电脑和虚拟机得电话都是接通外网,linux查看网络ip得两个命令ifconfig和 ip addr 1,命令ifconfig 如果ifconfig ...

  8. 两个命令把 Vim 打造成 Python IDE

    运行下面两个命令,即可把 Vim(含插件)配置成 Python IDE.目前支持 MAC 和 Ubuntu. Shell   curl -O https://raw.githubusercontent ...

  9. CMake比较实用的命令小记

    最近将项目迁移到CMake进行管理,对CMake进行了一些研究,觉得有一些命令非常实用但很少有资料提到,在这里做一个总结,至于太普通常用的命令就不提了. OPTION(OPTION_VAR " ...

随机推荐

  1. Spring自学教程-AOP学习(五)

    Spring中的AOP 一.概述 (一)基本概念 1.什么是AOP?     面向方面编程.所谓方面即是指日志.权限.异常处理.事务处理等. 2.AOP的3个关键概念    (1)切入点(Pointc ...

  2. 2017 ZSTU寒假排位赛 #2

    题目链接:https://vjudge.net/contest/147632#overview. A题,状态压缩一下然后暴力即可. B题,水题,略过. C题,有负数,前缀和不是单调的,因此不能用尺取法 ...

  3. Codeforces #317 C.Lengthening Sticks(数学)

    C. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. MongoDB和MySQL的区别

    http://www.cnblogs.com/caihuafeng/p/5494336.html MongoDB(文档型数据库):提供可扩展的高性能数据存储 一. 1.基于分布式文件存储 2.高负载情 ...

  5. wdcp使用记录--持续更新

    1.扩展memcache 资源地址:http://download.csdn.net/detail/fangminglei/8390449 上传至root文件夹运行 注:官方提供的文件不能安装,需要改 ...

  6. MVC笔记2:mvc+jquery.validate.js 进行前端验证

    1.引用如下js和css 代码 <link href="@Url.Content("~/Content/Site.css")" rel="sty ...

  7. magento中文语言包的使用

    magento中文语言包的使用,我们在百度上随便就能找到一大堆. 由于本人今天是第一次使用magento,找到目录magento/app/locale  并且用语言包中的locale文件夹替换掉mag ...

  8. ceentos5.5 配置samba服务&用户&组

    准备 Change Root Password passwd root 在提示下建立新密码 静态IP vi /etc/sysconfig/network-scripts/ifcfg-eth0  #网络 ...

  9. 因子分析&主成分分析

    因子分析和主成分分析的异同点: 1.主成分分析仅仅是一种数据变换而不假设数据矩阵有什么样的结构形式 因子分析假定数据有特定的模型,而且齐总的因子满足特定的条件 2.因子分析和主成分分析都是从相关矩阵出 ...

  10. python py_innodb_page_info.py -v /usr/local/var/mysql/ibdata1

    mylib.py #encoding=utf-8 import os import include from include import * TABLESPACE_NAME='D:\\mysql_d ...