CMakeLists.txt 语法
命令不区分大小写(参数区分大小写)
add_executable(demo main.cpp main.h main.rc)
用main.cpp源文件,main.h文件,main.rc文件构造可执行文件。至于如何使用这些文件, CMake比我们都清楚。
用 SET 设置变量
SET( MY_SOURCES main.cpp widget.cpp)
用 FOREACH 迭代
FOREACH(next_ITEM ${MY_SOURCES})
MESSAGE(STATUS "next item: ${next_ITEM}") ENDFOREACH(next_ITEM ${MY_SOURCES})
定义一个宏 hello
MACRO(hello MESSAGE)
MESSAGE(${MESSAGE})
ENDMACRO()
使用
hello("Hello World")
string 操作
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>)
Check if given C source compiles and links into an executable
CHECK_C_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>]) <code> - source code to try to compile, must define 'main' <var> - variable to store whether the source code compiled Will be created as an internal cache variable. <fail-regex> - fail if test output matches this regex
The following variables may be set before calling this macro to modify the way the check is run:
CMAKE_REQUIRED_FLAGS = string of compile command line flags CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) CMAKE_REQUIRED_INCLUDES = list of include directories CMAKE_REQUIRED_LIBRARIES = list of libraries to link CMAKE_REQUIRED_QUIET = execute quietly without messages