将文件夹下的所有文件添加到CMake Glob吗? [英] Add all files under a folder to a CMake glob?
本文介绍了将文件夹下的所有文件添加到CMake Glob吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚读过这篇文章:
答案提示文件是全局文件,例如:
With the answer suggesting a file glob, e.g.:
file(GLOB "*.h" "*.cpp")
现在,如果我希望我的目标依赖于某个文件夹下某个类型的所有文件-可能在多个子文件夹中,该怎么办?我尝试使用
now, what if I want my target to depend on all files of a certain type under a certain folder - which might be within multiple subfolders? I tried using
execute_process(COMMAND find src/baz/ -name "*.cpp" OUTPUT_VARIABLE BAR)
,然后
add_executable(foo ${BAR}
但这给了我错误:
找不到源文件:
src/baz/some/file/here
src/baz/some/other_file/here
src/baz/some/other_file/here2
(是,有这个间距。)
我在这里做什么错了?
推荐答案
将我的评论变成答案
如果要添加递归搜索文件使用 file(GLOB_RECURSE ...)
If you want to add recursive searching for files use file(GLOB_RECURSE ...)
file(GLOB_RECURSE source_list "*.cpp" "*.hpp")
您的第二个示例将转换为
Your second example would translate into
file(GLOB_RECURSE BAR "src/baz/*.cpp")
参考文献
file(...)
- Specify source files globally with GLOB?
这篇关于将文件夹下的所有文件添加到CMake Glob吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文