build - 有 CMake 递归扫描文件夹吗?

如何设置 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 递归扫描 srcinclude 并确定我的项目中的源文件和头文件列表,而不管目录结构如何。我也想避免:

  • 用无穷无尽的 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/

相关文章:

xcode - 在需要时配置 Xcode 4 工作区以构建依赖项的正确方法是什么?

build - 如何将 build.gradle 目录传递给 gradlew?

git - Jenkins:一个项目的多个 Git 存储库

.net - 使用 Nant 构建 .NET 4 项目

java - 如何使用 pom.xml 将参数传递给 Maven 构建?

c++ - 在编译时使用 C++ 在目标代码中嵌入时间戳

linux - 并行make : set -j8 as the default option

java - 使用 SBT 构建纯 Java 项目

maven - Jenkins 构建会因覆盖率下降而失败吗?

visual-studio - 使用 Installshield LE 包含标记为 "Copy to