我有一个C++代码的目录结构,如下所示:
|
|->include
|->src
Run Code Online (Sandbox Code Playgroud)
我正在为我的代码编写一个CMakeLists.txt文件.我想明白之间的差别include_directories,并target_include_directories在CMake.
它们的用法和为了添加我应该使用的包含文件路径有什么区别?
我正在写一个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}\"")
Run Code Online (Sandbox Code Playgroud)
cmake输出:
At last, the source_list is:"nothing"
Run Code Online (Sandbox Code Playgroud)
有人建议使用宏而不是函数,但我确实需要使用局部变量,所以我需要使用函数而不是宏.
如何在函数test()中正确设置全局变量source_list?cmake不能以简单和正常的方式做到吗?