cmake教程二,变量以及flow control

本文主要内容如下:
  1. cmake中variable以及nested variable的使用

  2. 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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值