【问题标题】:CMake shell find [duplicate]CMake shell找到[重复]
【发布时间】:2017-07-02 16:51:45
【问题描述】:

我正在尝试从使用 CMakeFiles 的现有项目中导入外部项目。为此,我正在尝试添加一个包含导入所需文件的静态库“.a”。

我的 CMakeFiles.txt:

cmake_minimum_required(VERSION 2.8.9)                                                                                                                                               
project(TEST)                                                                                                                                                                        
set(CMAKE_BUILD_TYPE Release)                                                                                                                                                       

#Bring the headers, such as Student.h into the project                                                                                                                              
include_directories(include)                                                                                                                                                        

#但是,文件(GLOB...)允许添加通配符:

file(GLOB SOURCES "src/examples/equality_prob/*.cpp" "src/examples/equality_prob/common/*.cpp")
#Generate the static library from the sources                                                                                                                                       
add_library(testEquality STATIC ${SOURCES})    

直到那里我认为我在正确的方式。但是在文件中(GLOB SOURCES,我想添加一个文件夹中的所有文件 *.cpp , *.h 等等,其中包含其他文件夹。

我可以在 Makefiles 中这样做:

$(shell find ${SRC}/examples -type f -name '*.o')  

但是我怎样才能在 CMakeFiles 中做到这一点?

【问题讨论】:

  • file(GLOB_RECURSE ...)?

标签: c++ makefile cmake glob


【解决方案1】:

使用GLOB_RECURSE 可能会给您想要的结果。

但是

这不是从GLOB documentation 收集源文件的推荐方法(也适用于GLOB_RECURSE):

我们不建议使用 GLOB 从源代码树中收集源文件列表。如果在添加或删除源时没有 CMakeLists.txt 文件发生更改,则生成的构建系统无法知道何时要求 CMake 重新生成。

因此,虽然有点不方便,但最好明确列出构成库的文件。

【讨论】:

  • 感谢您的明确答复!
猜你喜欢
  • 1970-01-01
  • 2020-11-10
  • 1970-01-01
  • 2019-12-13
  • 2017-05-17
  • 2017-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多