set(var_name_1 var1) message("var_name is ${var_name_1}")
set(var_name_2 var2) set(${var_name_2} var) #same as set(var2 var) set(${${var_name_2}}_x foo) #same as set(var_x foo) message("var2 is ${var2}") message("var_name_2 is ${var_name_2}") message("var_x is ${var_x}") message("empty var is ${empty_var}")
执行结果如下:
1 2 3 4 5
var_name is var1 var2 is var var_name_2 is var2 var_x is foo empty var is
列表
在cmake 中,列表是使用 空格 `` 分隔的多个字符串 或 使用分号 ; 分隔的字符串。如下:
1 2 3 4 5 6
# Creates a list with members a, b, c, and d set(my_list a b c d) set(my_list "a;b;c;d")
# Creates a string "a b c d" set(my_string "a b c d")
嵌套列表
1 2 3 4 5 6 7 8 9 10
set(list_of_lists a b c) set(a 123) set(b 456) set(c 789)
foreach(list_name IN LISTS list_of_lists) foreach(value IN LISTS ${list_name}) message(${value}) endforeach() endforeach()