让 CMake 递归扫描文件夹? [英] Have CMake recursively scan folders?
问题描述
如何设置 CMake 以递归方式扫描给定目录并确定源文件列表?
我的项目是一个共享库.我有一个类似于这样的文件夹结构:
<预><代码>/src/# 任意树中的源文件include/# 头,树镜像 src/文件夹的头examples/# 链接库的可执行代码示例CMakeLists.txt我希望 CMake 递归扫描 src
和 include
并确定我的项目中的源文件和头文件列表,而不管目录结构如何.我也想避免:
- 用无尽的
CMakeLists.txt
文件污染src/
和include/
目录 - 每次更改文件夹结构时都必须更改和调整脚本
不过,每个示例都可以拥有自己的构建脚本.
CMake 为递归文件全局化提供了以下命令:
file(GLOB_RECURSE 变量 [RELATIVE path][FOLLOW_SYMLINKS] [globbing 表达式]...)
命令文档:http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:file
How do I set up CMake to recursively scan a given directory and determine the list of source files?
My project is a shared library. I have a folder structure similar to this:
/
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
I want CMake to recursively scan src
and include
and determine the list of source and header files in my project, regardless of the directory structure. I also want to avoid:
- Polluting the
src/
andinclude/
directories with endlessCMakeLists.txt
files - Having to change and adapt the scripts every time I change my folder structure
It is fine for each example to have their own build script, however.
CMake provides the following command for recursive files globing:
file(GLOB_RECURSE variable [RELATIVE path]
[FOLLOW_SYMLINKS] [globbing expressions]...)
Command documentation: http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:file
这篇关于让 CMake 递归扫描文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!