【发布时间】:2012-04-19 09:22:48
【问题描述】:
我正在编写一个 CMakeLists.txt 来生成文件并编译生成的文件。我创建了一个函数来将一些文件路径字符串添加到全局列表变量中。
我的 CMakeLists.txt:
set(source_list "nothing")
function(test file_path)
list(APPEND source_list ${file_path})
endfunction(test)
test(abc.txt)
test(def.txt)
message("At last, the source_list is:\"${source_list}\"")
cmake 输出:
At last, the source_list is:"nothing"
有人建议用宏代替函数,但我确实需要使用局部变量,所以我需要使用函数而不是宏。
如何在函数test()中正确设置全局变量source_list? cmake就不能用简单正常的方式来做吗?
【问题讨论】:
标签: cmake