如何设置 CMake 以递归扫描给定目录并确定源文件列表?
我的项目是一个共享库。我有一个类似这样的文件夹结构:
/
src/ # Source files in an arbitrary tree
include/ # Headers, tree mirrors that of the src/ folder
examples/ # Executable code examples that link against the library
CMakeLists.txt
我希望 CMake 递归扫描 src
和 include
并确定我的项目中的源文件和头文件列表,而不管目录结构如何。我也想避免:
CMakeLists.txt
文件污染 src/
和 include/
目录不过,每个示例都有自己的构建脚本很好。
最佳答案
CMake 为递归文件通配提供了以下命令:
file(GLOB_RECURSE variable [RELATIVE path]
[FOLLOW_SYMLINKS] [globbing expressions]...)
命令文档:http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:file
https://stackoverflow.com/questions/9745627/