首先说明如何修改或创建一个环境变量,使用set(ENV{<variable>} <value>)指令用以声明,使用unset(ENV{<variable>})来清除某一个环境变量,其中ENV表示环境变量标志性前缀,variable指变量名称,value则为变量值,需要注意的是设定或读取环境变量时,都通过ENV前缀来访问环境变量,读取环境变量值时,要在ENV前加$符号;但if...
if (DEFINED var):如果变量被定义为真; if (var MATCHES regex):给定的变量或者字符串能够匹配正则表达式regex 时为真,此处 var 可以用 var 名,也可以用 ${var}; if (string MATCHES regex):给定的字符串能够匹配正则表达式regex时为真。 1.20.2 数字比较 if (variable LESS number):如果variable小于number时...
使用unset(ENV{<variable>})来清除某一个环境变量,其中ENV表示环境变量标志性前缀,variable指变量名称,value则为变量值,需要注意的是设定或读取环境变量时,都通过ENV前缀来访问环境变量,读取环境变量值时,要在ENV前加$符号;但if判断是否定义时,不用加$符号。
string(COMPARE LESS <string1> <string2> ) string(COMPARE GREATER <string1> <string2> ) string(COMPARE EQUAL <string1> <string2> ) string(COMPARE NOTEQUAL <string1> <string2> ) string(COMPARE LESS_EQUAL <string1> <string2> ) string(COMPARE GREATER_EQUAL <string1> <string2> ) 列表操...
IF(variable STREQUAL string) IF(string STREQUAL string) IF(DEFINED variable)#如果变量被定义,为真。 # 一个小例子,用来判断平台差异: IF(WIN32) MESSAGE(STATUS “This is windows.”) # 作一些 Windows 相关的操作 ELSE(WIN32) MESSAGE(STATUS “This is not windows”) ...
aux_source_directory( <variable>) 因此,可以修改 CMakeLists.txt 如下: 1# CMake 最低版本号要求23cmake_minimum_required (VERSION2.8)45# 项目信息67project (Demo2)89# 查找当前目录下的所有源文件1011# 并将名称保存到 DIR_SRCS 变量1213aux_source_directory(. DIR_SRCS)1415# 指定生成目标1617add_...
define_property()新增了INITIALIZE_FROM_VARIABLE选项。 CMAKE_<SYSTEM_>IGNORE_PREFIX_PATH可以控制find_*的查找路径。 新增<CMAKE_>LINK_LIBRARIES_ONLY_TARGETS强制只链接目标(非常适合查找错误!) IMPORTED_NO_SYSTEM可强制从目标中删除 SYSTEM 的新属性。
if(variable) # If variable is `ON`, `YES`, `TRUE`, `Y`, or non zero number else() # If variable is `0`, `OFF`, `NO`, `FALSE`, `N`, `IGNORE`, `NOTFOUND`, `""`, or ends in `-NOTFOUND` endif() # If variable does not expand to one of the above, CMake will expa...
, YES, TRUE, Y, or a non-zero number. False if the constant is 0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in the suffix -NOTFOUND. Named boolean constants are case-insensitive. If the argument is not one of these constants, it is treated as a variable....
option(debug "is debug mode?" OFF).可以通过-D选择不同的选项。 如cmake ../source -Ddebug=ON;cmake ../source -Ddebug=OFF option ( "help string describing option" [initial value]) option_variable可以通过${option_variable}进行访问,其值为ON或者OFF # 设置变量,取消变量...