cmake 语法研究
注意点
详细内容
变量
set(WHH_VAR 0)
${0}
if 判断
set(WHH_VAR 0)
if(${WHH_VAR} EQUAL 0)
message(STATUS "WHH_VAR is ${WHH_VAR}")
elseif(${WHH_VAR} GREATER 0)
message(STATUS "WHH_VAR is greater than 0")
else()
message(STATUS "WHH_VAR is less 0")
endif()
// 判断变量是否定义
// 关键词 DEFINED
if(NOT DEFINED WHH_VAR)
message(STATUS "WHH_VAR is not defined yet")
else()
message(STATUS "WHH_VAR is ${WHH_VAR}")
endif()
/*
* if 的判断符如下
* EQUAL //等于
* LESS //小于
* LESS_EQUAL //小于等于
* GREATER //大于
* GREATER_EQUAL//大于等于
* STREQUAL //字符串相等
* STRLESS //字符串小于
* STRLESS_EQUAL//字符串小于等于
* STRGREATER //字符串大于
* STRGREATER_EQUAL //字符串大于等于
* VERSION_EQUAL //版本相等
* VERSION_LESS //版本小于
* VERSION_LESS_EQUAL //版本小于等于
* VERSION_GREATER //版本大于
* VERSION_GREATER_EQUAL//版本大于等于
* MATCHES //匹配通配符
* NOT //取反
* AND //与
* OR //或
*/
if(<constant>)
//True if the constant is 1, ON, 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 specific constants, it is treated as a variable or string and the following signature is used.
if(<variable|string>)
//True if given a variable that is defined to a value that is not a false constant. False otherwise. (Note macro arguments are not variables.)
if(NOT <condition>)
//True if the condition is not true.
if(<cond1> AND <cond2>)
//True if both conditions would be considered true individually.
if(<cond1> OR <cond2>)
//True if either condition would be considered true individually.
if(COMMAND command-name)
//True if the given name is a command, macro or function that can be invoked.
if(POLICY policy-id)
//True if the given name is an existing policy (of the form CMP<NNNN>).
if(TARGET target-name)
//True if the given name is an existing logical target name created by a call to the add_executable(), add_library(), or add_custom_target() command that has already been invoked (in any directory).
if(TEST test-name)
//True if the given name is an existing test name created by the add_test() command.
if(EXISTS path-to-file-or-directory)
//True if the named file or directory exists. Behavior is well-defined only for full paths. Resolves symbolic links, i.e. if the named file or directory is a symbolic link, returns true if the target of the symbolic link exists.
if(file1 IS_NEWER_THAN file2)
//True if file1 is newer than file2 or if one of the two files doesn’t exist. Behavior is well-defined only for full paths. If the file time stamps are exactly the same, an IS_NEWER_THAN comparison returns true, so that any dependent build operations will occur in the event of a tie. This includes the case of passing the same file name for both file1 and file2.
if(IS_DIRECTORY path-to-directory)
//True if the given name is a directory. Behavior is well-defined only for full paths.
if(IS_SYMLINK file-name)
//True if the given name is a symbolic link. Behavior is well-defined only for full paths.
if(IS_ABSOLUTE path)
//True if the given path is an absolute path.
if(<variable|string> MATCHES regex)
//True if the given string or variable’s value matches the given regular condition. See Regex Specification for regex format. () groups are captured in CMAKE_MATCH_<n> variables.
if(<variable|string> LESS <variable|string>)
//True if the given string or variable’s value is a valid number and less than that on the right.
if(<variable|string> GREATER <variable|string>)
//True if the given string or variable’s value is a valid number and greater than that on the right.
if(<variable|string> EQUAL <variable|string>)
//True if the given string or variable’s value is a valid number and equal to that on the right.
if(<variable|string> LESS_EQUAL <variable|string>)
//True if the given string or variable’s value is a valid number and less than or equal to that on the right.
if(<variable|string> GREATER_EQUAL <variable|string>)
//True if the given string or variable’s value is a valid number and greater than or equal to that on the right.
if(<variable|string> STRLESS <variable|string>)
//True if the given string or variable’s value is lexicographically less than the string or variable on the right.
if(<variable|string> STRGREATER <variable|string>)
//True if the given string or variable’s value is lexicographically greater than the string or variable on the right.
if(<variable|string> STREQUAL <variable|string>)
//True if the given string or variable’s value is lexicographically equal to the string or variable on the right.
if(<variable|string> STRLESS_EQUAL <variable|string>)
//True if the given string or variable’s value is lexicographically less than or equal to the string or variable on the right.
if(<variable|string> STRGREATER_EQUAL <variable|string>)
//True if the given string or variable’s value is lexicographically greater than or equal to the string or variable on the right.
if(<variable|string> VERSION_LESS <variable|string>)
//Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]], omitted components are treated as zero). Any non-integer version component or non-integer trailing part of a version component effectively truncates the string at that point.
if(<variable|string> VERSION_GREATER <variable|string>)
//Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]], omitted components are treated as zero). Any non-integer version component or non-integer trailing part of a version component effectively truncates the string at that point.
if(<variable|string> VERSION_EQUAL <variable|string>)
//Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]], omitted components are treated as zero). Any non-integer version component or non-integer trailing part of a version component effectively truncates the string at that point.
if(<variable|string> VERSION_LESS_EQUAL <variable|string>)
//Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]], omitted components are treated as zero). Any non-integer version component or non-integer trailing part of a version component effectively truncates the string at that point.
if(<variable|string> VERSION_GREATER_EQUAL <variable|string>)
//Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]], omitted components are treated as zero). Any non-integer version component or non-integer trailing part of a version component effectively truncates the string at that point.
if(<variable|string> IN_LIST <variable>)
//True if the given element is contained in the named list variable.
if(DEFINED <name>|CACHE{<name>}|ENV{<name>})
//True if a variable, cache variable or environment variable with given <name> is defined. The value of the variable does not matter. Note that macro arguments are not variables.
if((condition) AND (condition OR (condition)))
//The conditions inside the parenthesis are evaluated first and then the remaining condition is evaluated as in the previous examples. Where there are nested parenthesis the innermost are evaluated as part of evaluating the condition that contains them.
set
set用于设置普通、cache、环境变量
普通变量:set(<variable> <value>... [PARENT_SCOPE])
cache:set(<variable> <value>... CACHE <type> <docstring> [FORCE])
环境变量:set(ENV{<variable>} [<value>])
示例为:
set(WHH_VAR_NORMAL 0)
set(WHH_VAR_CACHE "whh_var_cache" CHCHE STRING "cache value")
set(ENV{WHH_VAR_ENV} ["whh_var_env"])
// cache变量的类型只能是:
// BOOL:ON OFF
// FILEPATH:硬盘上的文件路径
// PATH:文件夹路径
// STRING INTERNAL:一行文字