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

add_compile_options()

Adds options to the compilation of source files.

增加源文件的编译选项。

add_compile_options(<option> ...)

Adds options to the compiler command line for targets in the current directory and below that are added after this command is invoked. See documentation of the directory and target COMPILE_OPTIONS properties.

为当前路径和下层路径的目标增加编译器命令行选项,选项在此命令被调用后添加。查看文档中关于路径和目标的 COMPILE_OPTIONS 属性。

This command can be used to add any options, but alternative commands exist to add preprocessor definitions (target_compile_definitions() and add_definitions()) or include directories (target_include_directories() and include_directories()).

这个命令可以被用来添加任何的选项,但是存在替代命令(target_compile_definitions() 和 add_definitions())增加预处理定义或(target_include_directories() 和 include_directories())包含路径。

Arguments to add_compile_options may use “generator expressions” with the syntax $<...>. See the cmake-generator-expressions(7) manual for available expressions. See the cmake-buildsystem(7) manual for more on defining buildsystem properties.

add_compile_options的参数可以使用带语法$<...>的“生成表达式”。关于有效的表达式可以查看cmake-generator-expressions(7)手册。关于更多的系统属性的定义可以查看cmake-buildsystem(7)助手。

add_definitions()

Adds -D define flags to the compilation of source files.

为源文件的编译添加由-D定义的标志。

add_definitions(-DFOO -DBAR ...)

Adds definitions to the compiler command line for targets in the current directory and below (whether added before or after this command is invoked). This command can be used to add any flags, but it is intended to add preprocessor definitions (see the add_compile_options() command to add other flags). Flags beginning in -D or /D that look like preprocessor definitions are automatically added to the COMPILE_DEFINITIONS directory property for the current directory. Definitions with non-trivial values may be left in the set of flags instead of being converted for reasons of backwards compatibility. See documentation of the directory, target, source file COMPILE_DEFINITIONS properties for details on adding preprocessor definitions to specific scopes and configurations.

为当前路径以及下层路径的目标加入编译器命令行定义(定义在命令调用之前或之后被添加,注:也就是不确定)。这个命令可以用来添加任何标志,但是它的原意是用来增加预处理器的定义(查看 add_compile_options() 命令增加其它的定义)。那些以 -D 或 /D 开头的标志,看起来像预处理器定义的flag,会被自动加到当前路径的 COMPILE_DEFINITIONS 属性中。为了后向兼容,非简单值(non-trival,指的是什么?——译注)的定义会被留在flags组(flags set)里,而不会被转换。关于在特定的域以及配置中增加预处理器的定义,参考路径、目标以及源文件的 COMPILE_DEFINITIONS 属性来获取更多的细节。

See the cmake-buildsystem(7) manual for more on defining buildsystem properties.

关于更多的系统属性的定义可以查看cmake-buildsystem(7)助手。

target_compile_definitions()

Add compile definitions to a target.

为目标增加编译定义。

target_compile_definitions(<target>
<INTERFACE|PUBLIC|PRIVATE> [items1...]
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]
)

Specify compile definitions to use when compiling a given <target>. The named <target> must have been created by a command such as add_executable() or add_library() and must not be an Imported Target.

编译给定的 <target> 时使用指定的编译定义。<target> 必须是 add_executable() 或者 add_library() 创建的,并且不是一个输入目标。

The INTERFACE, PUBLIC and PRIVATE keywords are required to specify the scope of the following arguments. PRIVATE and PUBLIC items will populate the COMPILE_DEFINITIONS property of <target>. PUBLIC and INTERFACE items will populate the INTERFACE_COMPILE_DEFINITIONS property of <target>. The following arguments specify compile definitions. Repeated calls for the same <target> append items in the order called.

关键字INTERFACE,PUBLIC和PRIVATE用来指定其后参数的作用域。PRIVATE 和 PUBLIC 项将产生 <target> 的 COMPILE_DEFINITIONS 属性。PUBLIC 和 INTERFACE 项将产生 <target> 的INTERFACE_COMPILE_DEFINITIONS 属性。其后的参数指定编译定义。重复调用相同的目标将按照调用顺序追加(定义)。

Arguments to target_compile_definitions may use “generator expressions” with the syntax $<...>. See the cmake-generator-expressions(7) manual for available expressions. See the cmake-buildsystem(7) manual for more on defining buildsystem properties.

target_compile_definitions的参数可以使用带语法$<...>的“生成表达式”。关于有效的表达式可以查看cmake-generator-expressions(7)手册。关于更多的系统属性的定义可以查看cmake-buildsystem(7)助手。

build_command()

Get a command line to build the current project. This is mainly intended for internal use by the CTest module.

获取构建该工程的命令行。通常是供CTest模块的内部使用。

注:笔者给出了一个简单的例子在文档结尾。

build_command(<variable>
[CONFIGURATION <config>]
[TARGET <target>]
[PROJECT_NAME <projname&gt] # legacy, causes warning
)

Sets the given <variable> to a command-line string of the form:

<cmake> --build . [--config <config>] [--target <target>] [-- -i]

where <cmake> is the location of the cmake(1) command-line tool, and <config> and <target> are the values provided to the CONFIGURATION and TARGET options, if any. The trailing -- -i option is added for Makefile Generators if policy CMP0061 is not set to NEW.

When invoked, this cmake --build command line will launch the underlying build system tool.

build_command(<cachevariable> <makecommand>)

This second signature is deprecated, but still available for backwards compatibility. Use the first signature instead.

It sets the given <cachevariable> to a command-line string as above but without the --target option. The <makecommand> is ignored but should be the full path to msdev, devenv, nmake, make or one of the end user build tools for legacy invocations.

Note In CMake versions prior to 3.0 this command returned a command line that directly invokes the native build tool for the current generator. Their implementation of the PROJECT_NAME option had no useful effects, so CMake now warns on use of the option.

example

cmake_minimum_required(VERSION 2.8)
project(cmaketest)
#set(CMAKE_CXX_COMPILER "g++")
add_compile_options(-std=c++11 -w)
#add_definitions(-std=c++11) build_command(BUILD_COMMAND_LINE CONFIGURATION ${CMAKE_BUILD_TYPE}
PROJECT_NAME cmaketest TARGET all) message("build command:${BUILD_COMMAND_LINE}") message("using compiler ${CMAKE_CXX_COMPILER}") add_executable(test main.cpp)

build command:/usr/bin/make -i "all"

using compiler /usr/bin/c++

// main.cpp

int main(int argc, char *argv[])
{
int n = 5.5f;
auto func = [&](int n) {return n < 5;};
return 0;
}

cmake的四个命令:add_compile_options、add_definitions、target_compile_definitions、build_command的更多相关文章

  1. zookeeper命令行(zkCli.sh&zkServer.sh)使用及四字命令

    zookeeper提供了很多方便的功能,方便我们查看服务器的状态,增加,修改,删除数据(入口是zkServer.sh和zkCli.sh). 还提供了一系列四字命令,方便我们跟服务器进行各种交互,来确认 ...

  2. linux下监控进程需掌握的四个命令

    linux下监控进程需掌握的四个命令   在LInux系统下,最困难的工作之一就是跟踪正在系统中运行的程序,尤其是现在,图形桌面使用很多的程序,只是为了生成一个桌面环境,系统中运行了太多的进程,幸运的 ...

  3. cmake的两个命令: option 和 configure_file

    本节要讨论的是cmake的两个命令: option 和 configure_file option 选项,让你可以根据选项值进行条件编译. configure_file 配置文件,让你可以在代码文件中 ...

  4. zookeeper 四字命令的使用

    Linux中的命令NetCat有“瑞士军刀”的美誉.我们可以通过nc命令查看Zookeeper的一行属性数据.在Zookeeper中有很多四字命令,汇总如下: 序号 使用命令 输出说明  1 echo ...

  5. zookeeper之 zkServer.sh命令、zkCli.sh命令、四字命令

    一.zkServer.sh 1.查看 zkServer.sh 帮助信息[root@bigdata05 bin]# ./zkServer.sh helpZooKeeper JMX enabled by ...

  6. zookeeper 四字命令

    zookeeper四字命令   ZooKeeper3.4.6支持某些特定的四字命令字母与其的交互.它们大多是查询命令,用来获取 ZooKeeper 服务的当前状态及相关信息.用户在客户端可以通过 te ...

  7. Java 设计模式系列(十四)命令模式(Command)

    Java 设计模式系列(十四)命令模式(Command) 命令模式把一个请求或者操作封装到一个对象中.命令模式允许系统使用不同的请求把客户端参数化,对请求排队或者记录请求日志,可以提供命令的撤销和恢复 ...

  8. Zookeeper四字命令

    ZooKeeper 支持某些特定的四字命令(The Four Letter Words)与其进行交互.它们大多是查询命令,用来获取 ZooKeeper 服务的当前状态及相关信息.用户在客户端可以通过 ...

  9. Zookeeper运维常用四字命令

    Zookeeper运维常用四字命令 echo stat|nc 127.0.0.1 2181 查看哪个节点被选择作为follower或者leader 使用echo ruok|nc 127.0.0.1 2 ...

随机推荐

  1. SVN第二篇-----命令集合

    16.switch  代码库URL变更 svn switch (sw): 更新工作副本至不同的URL. 用法:  1.switch URL [PATH]         更新你的工作副本,映射到一个新 ...

  2. 设计模式笔记之四:MVP+Retrofit+RxJava组合使用

    本博客转自郭霖公众号:http://mp.weixin.qq.com/s?__biz=MzA5MzI3NjE2MA==&mid=2650236866&idx=1&sn=da66 ...

  3. Bash中的变量

    Bash中的变量1.用户定义的变量变量的定义  用户定义的变量有字母数字及下划线组成,并且变量名的第一个字符不能为数字.            与其它UNIX名字一样,变量名是大小写敏感的. 对于变量 ...

  4. 解决tomcat运行报错java.lang.UnsatisfiedLinkError: apache-tomcat-7.0.37\bin\tcnative-1.dll:Can load AMD 64

    http://www.apache.org/dist/tomcat/tomcat-connectors/native/ 到该地址下下载一个tomcat-native-1.2.2-win32-bin压缩 ...

  5. RFID射频卡超市购物结算系统问题记录--写入卡片时,后台php无法操作数据库

    后台管理人员要给每件商品贴上RF卡作为唯一标识,所以要先给对应的RFID卡中写入响应的信息,我这里为了便于模拟演示只写入商品编号,价格,名称这几个字段,然后要把已经写入的商品上传后台,由后台写入数据库 ...

  6. flask-sqlalchemy relationship

    http://www.ergo.io/blog/sqlalchemy-relationships-from-beginner-to-advanced class Cabinet(db.Model): ...

  7. github的SSH配置如下

    Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置. github的SSH配置如下: 一 . 设置Git的user name和email: $ git ...

  8. vuejs 子组件传递父组件的第一种方式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Oracle数据库常用技术

    一.视图(重点) 什么是视图? ·视图由一个或多个表(或视图)中提取数据而成 ·视图是一种虚拟表 ·视图一经创建,可以当作表来使用. 使用视图的好处? · 简化复杂数据查询 · 提高运行效率 · 屏蔽 ...

  10. C# 存储过程使用方法

                CREATE PROCEDURE [dbo].[GetNameById] @studentid varchar(8), @studentname nvarchar(50) OU ...