代码
cmake_minimum_required(VERSION 2.8)
set(mylist a)
list(APPEND mylist b c)
MESSAGE("${mylist}")
MESSAGE(${mylist})
foreach(component ${mylist})
MESSAGE(${component})
endforeach(component)
结果
a;b;c
abc
a
b
c
结论
list是用;隔开的字符串组,也可以以空格隔开,显示整个list时加上“”号会显示分隔符,否则不会显示,连在一起。list可以使用foreach遍历。
补充
- MESSAGE(${component })就会出错,
syntax error, unexpected $end, expecting }
${component}中的花括号要紧贴着变量。
- cmake脚本中缩进不是必须的。