CMake命令
2015-02-05
CMake命令
prject
usage:
project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
project(<PROJECT-NAME>
[VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
[LANGUAGES <language-name>...])
example: project(NE10 C CXX ASM)
note: 设置整个工程的名称,版本,以及支持的编程语言.一旦PROJECT-NAME被设置以后,以下变量会自动生成.
PROJECT_NAME
PROJECT_SOURCE_DIR, <PROJECT-NAME>_SOURCE_DIR
PROJECT_BINARY_DIR, <PROJECT-NAME>_BINARY_DIR
如果VERSION被设置,以下变量会自动生成.
PROJECT_VERSION, <PROJECT-NAME>_VERSION
PROJECT_VERSION_MAJOR, <PROJECT-NAME>_VERSION_MAJOR
PROJECT_VERSION_MINOR, <PROJECT-NAME>_VERSION_MINOR
PROJECT_VERSION_PATCH, <PROJECT-NAME>_VERSION_PATCH
PROJECT_VERSION_TWEAK, <PROJECT-NAME>_VERSION_TWEAK
option
usage:option(
example:OPTION(TEST_BUILD_SHARED “是否构建动态库” ON)
Note: 指定CMake的编译选项,注意这里的选项只是给CMake看的,只在CMakelists.txt里面有效,与程序无关。
add_subdirectory
usage: add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])
example: add_subdirectory(test)
note: 指定需要编译的子目录。子目录source_dir里面包含了CMakeLists.txt和相关的源代码。source_dir可以是相对当前目录的路径,也可以是绝对路径,一般用相对路径。
binary_dir指定子目录编译后的输出文件的存储目录。如果为空,则用source_dir代替。
如果指定了EXCLUDE_FROM_ALL,说明这个子目录编译出来的目标将不包括在主CMakeLists.txt的ALL目标里面。这个在某些情况下非常有用,比如这个子目录是一个与主工程不太相关的部分,像测试工程等。
当CMake执行到add_subdirectory指令时,立即跳转到子目录的CMakeLists.txt里面去执行,等执行完成返回后接着运行下面的指令。
message
usage: message([
example: MESSAGE(STATUS “${PROJECT_BINARY_DIR}”)
note:
(none) = 重要信息
STATUS = 突发信息
WARNING = 警告信息.跳过继续处理
AUTHOR_WARNING = 警告信息(dev).跳过继续处理
SEND_ERROR = 错误信息, 跳过继续处理,但是忽略生成
FATAL_ERROR = 错误信息, 停止处理
DEPRECATION = 反对点信息.如果指定了CMAKE_ERROR_DEPRECATED或者CMAKE_WARN_DEPRECATED,可以输出这种消息.如果没有,则不输出消息
string
usage: 对字符串进行操作
string(REGEX MATCH <regular_expression> <output variable> <input> [<input>...])
string(REGEX MATCHALL <regular_expression> <output variable> <input> [<input>...])
string(REGEX REPLACE <regular_expression> <replace_expression> <output variable> <input> [<input>...])
string(REPLACE <match_string> <replace_string> <output variable> <input> [<input>...])
string(CONCAT <output variable> [<input>...])
string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512> <output variable> <input>)
string(COMPARE EQUAL <string1> <string2> <output variable>)
string(COMPARE NOTEQUAL <string1> <string2> <output variable>)
string(COMPARE LESS <string1> <string2> <output variable>)
string(COMPARE GREATER <string1> <string2> <output variable>)
string(ASCII <number> [<number> ...] <output variable>)
string(CONFIGURE <string1> <output variable> [@ONLY] [ESCAPE_QUOTES])
string(TOUPPER <string1> <output variable>)
string(TOLOWER <string1> <output variable>)
string(LENGTH <string> <output variable>)
string(SUBSTRING <string> <begin> <length> <output variable>)
string(STRIP <string> <output variable>)
string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>] [RANDOM_SEED <seed>] <output variable>)
string(FIND <string> <substring> <output variable> [REVERSE])
string(TIMESTAMP <output variable> [<format string>] [UTC])
string(MAKE_C_IDENTIFIER <input string> <output variable>)
string(GENEX_STRIP <input string> <output variable>)
string(UUID <output variable> NAMESPACE <namespace> NAME <name> TYPE <MD5|SHA1> [UPPER])
example:
<替换操作> SET(START_STRING "hello,world,nice to meet you") MESSAGE(${START_STRING}) STRING(REPLACE "," " " SUB_STRING ${START_STRING}) MESSAGE(${SUB_STRING}) /************* output **************/ hello,world,nice to meet you hello world nice to meet you <正则表达式> SET(REG_STRING "hello,world,nice to meet you") STRING(REGEX REPLACE "\(.*\),\(.*\),\(.*\)" "match info is: \\1 | \\2 | \\3" REG_OUTPUT ${REG_STRING}) MESSAGE(${REG_OUTPUT}) /***********output***********/ match info is: hello | world | nice to meet you 所以,匹配的内容可以通过\1, \2, ...\n来获取。注意,要表示反斜杠,必须通过两个反斜杠来转义。 list ---- usage: 对列表进行操作 list(LENGTH