本文主要内容如下:
cmake中variable以及nested variable的使用
flow control (if foreach)的基本使用
1 cmake中variable以及nested variable的使用
主要的命令: cmake -p CMakeLists.txt, 其中-p主要是运行cmake不生成cmake中间文件。
1.1 cmake中variable
简单的输出信息,以及变量的设置:
message("hello world")
# set a cmake variable, and echo it
set(ECHO_HELLO "world")
message("hello: ${ECHO_HELLO}")
输出如下:
hello world
hello: world
1.2 cmake中 nested variable
set(XY_NAME "xiong yu")
set(XY_ADDRESS "china guangzhou")
set(PERSON "XY")
message("${${PERSON}_NAME} lives in ${${PERSON}_ADDRESS}")
输出如下:
xiong yu lives in china guangzhou
2. flow control (if foreach)的基本使用
2.1 if的使用
if(WIN32)
message("This is win32 platform")
else()
message("This is not win32 platform")
endif()
2.2 foreach的使用
set(FOR_LIST demo1.cpp demo2.cpp demo3.cpp)
foreach (f ${FOR_LIST})
message("now is file: " ${f})
endforeach ()
输出如下:
now is file: demo1.cpp
now is file: demo2.cpp
now is file: demo3.cpp
本文主要参考:
http://preshing.com/20170522/learn-cmakes-scripting-language-in-15-minutes/