#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 cor...
#cmakedefine01 VAR 会被替换成 #define VAR 0 或者 #define VAR 1 我们可以在命令行通过-D name=value 来控制CMake 变量的定义或者设置变量的值,-D会更新或者生成cache里面的一个数据项,因此可以通过命令行来控制编译选项,cache完以后同名的一般变量会被删除(文章一中的最后一条),所以如果采用这种方式,必须每...
# CMake 最低版本号要求cmake_minimum_required(VERSION2.8)# 项目信息project(Demo4)# 是否使用自己的 MathFunctions 库option(USE_MYMATH"Use provided math implementation"ON)# 加入一个配置头文件,用于处理 CMake 对源码的设置configure_file("${PROJECT_SOURCE_DIR}/config.h.in""${PROJECT_BINARY_DIR}/c...
option(MYDEBUG "enable debug compilation" OFF) set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) add_subdirectory(src) 这里使用了option命令,其第一个参数是这个option的名字,第二个参数是字符串,用来描述这个option是来干嘛的,第三个是option的值,ON或OFF,也可以不写,不写就是默认OFF。 然后编写sr...
option命令添加了一个USE_MYMATH选项,并且默认值为ON。 USE_MYMATH变量的值决定是否使用我们自己编写的 MathFunctions 库。 修改main.cc 文件 之后修改 main.cc 文件,让其根据USE_MYMATH的预定义值来决定是否调用标准库还是 MathFunctions 库: #include
#cmakedefine FOO_ENABLE #cmakedefine FOO_STRING "@FOO_STRING@" 1. 2. CMakeLists.txt中添加代码来设置一个开关,下边会执行if中的语句: option(FOO_ENABLE "Enable Foo" ON) if(FOO_ENABLE) set(FOO_STRING "foo") endif() configure_file(foo.h.in foo.h @ONLY) ...
Adds -D define flags to the compilation of source files. 为源文件的编译添加由-D定义的标志。 add_definitions(-DFOO -DBAR ...) 1. 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 com...
#cmakedefineUSE_MYMATH 三. 安装与测试 这一步骤中,我们将向我们的工程中添加安装规则和测试支持。 安装规则很简单直接。对于MathFunctions,我们可以在MathFuncitions的CMakeLists.txt中添加两行代码,即可安装库与头文件。 代码语言:javascript 复制 install(TARGETSMathFunctionsDESTINATIONbin)install(FILESMathFunctions...
#define _TEST_FUNC_H_ void func(int data); #endif 修改main.c,调用testFunc.h里声明的函数func(): main.c #include <stdio.h> #include "testFunc.h" int main(void) { func(100); return 0; } 修改CMakeLists.txt,在add_executable的参数里把testFunc.c加进来: ...
#define _TEST_FUNC_H_ void func(int data); #endif 修改main.c,调用testFunc.h里声明的函数func(): main.c #include #include "testFunc.h" int main(void) { func(100); return 0; } 修改CMakeLists.txt,在add_executable的参数里把testFunc.c加进来: ...