版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1338347
主要的命令: cmake -p CMakeLists.txt, 其中-p主要是运行cmake不生成cmake中间文件。
简单的输出信息,以及变量的设置:
message("hello world")
# set a cmake variable, and echo it
set(ECHO_HELLO "world")
message("hello: ${ECHO_HELLO}")
输出如下:
hello world
hello: world
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
if(WIN32)
message("This is win32 platform")
else()
message("This is not win32 platform")
endif()
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/