博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cmake的四个命令:add_compile_options、add_definitions、target_compile_definitions、build_command...
阅读量:5926 次
发布时间:2019-06-19

本文共 6274 字,大约阅读时间需要 20 分钟。

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(

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(
[items1...] [
[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(
[CONFIGURATION
] [TARGET
] [PROJECT_NAME

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

--build . [--config
] [--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(
)

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.cppint main(int argc, char *argv[]){    int n = 5.5f;    auto func = [&](int n) {return n < 5;};    return 0;}

转载于:https://www.cnblogs.com/the-capricornus/p/4766331.html

你可能感兴趣的文章
取消word中所有超链接
查看>>
属性驱动的架构设计方法图解
查看>>
31.12. [Warning] Changed limits: max_open_files: 5000 (requested 20480)
查看>>
[LeetCode] Merge Two Sorted Lists 混合插入有序链表
查看>>
AWWWB 网站克隆器 更新到1.01 修正错误
查看>>
5.8. grep, egrep, fgrep, rgrep - print lines matching a pattern
查看>>
25.3. UUID()
查看>>
第 1 章 PostgreSQL 安装
查看>>
Deep Learning(深度学习)学习笔记整理系列之(八)
查看>>
Python学习之运算符
查看>>
Hadoop - Mac OSX下配置和启动hadoop以及常见错误解决
查看>>
华东师范大学2017年数学分析考研试题
查看>>
查看JVM统计信息【转】
查看>>
膝盖中了一箭之康复篇9-12周
查看>>
maven mvn Failed during checkstyle execution
查看>>
跨域请求获取Solr json检索结果并高亮显示
查看>>
项目2.0上线,回想过后杂谈总结基础回顾一番
查看>>
蓝牙BLE传输性能及延迟分析
查看>>
BT下载原理分析
查看>>
12月18日云栖精选夜读:阿里云机器学习平台PAI,助力降低机器学习的成本和技术门槛...
查看>>