1:内置变量(不全)
CMAKE_C_COMPILER c编译器常量
CMAKE_CXX_COMPILER c++ 编译器常量
CMAKE_C_FLAGS c文件编译选项
EXECUTABLE_OUTPUT_PATH 可执行文件存放路径
LIBRARY_OUTPUT_PATH 库文件存放路径
...
2:常用修改函数
include_directories() 指定头文件的搜索路径与gcc -i 作用相同
link_diectiories() 指定动态链接库或动态链接库路径 gcc -L
add_subdirectory() 指定工程子目录,会自动寻找子文件夹下的cmakeLists.txt
add_definitions() 添加编译参数参数
add_executable() 添加可执行程序
target_link_libraries() 指定链接库 gcc -l
3:一些常用指令(支持汇编指令)
set:设置变量
set (Foo a b c) 设置常量Foo 等价与"a b c"
set(Foo a;b;c) 与上等价
foreach:遍历
set (VAR a,b,c)
foreach(f ${VAR})
command ...
endforeach(f)
macro:定义宏
macro(hello MA)
message(${MA})
endmacro(hello)
hello("hello world")
function(hello MESSAGE)
message(${MESSAGE})
endfunction(hello)
4:makefile添加额外编译选项:
//add_compile_options():修改所有编译器
例如:
if(CMAKE_COMPILER_IS_GNUCXX)
add_complie_options(-std=c++)
message(STATUS"optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)
//CMAKE_CXX_FLAGS/CMAKE_C_FLAGS:修改C/C++编译器
例如:
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_COMPLIER_FLAGS "-std=c++11${CMAKE_CXX_FLAGS}")
message(STATUS "optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)
5:其他