CMake shell 找到

CMake shell find

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

My 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)                                                                                                                                                        

#However, the file(GLOB...) allows for wildcard additions:

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 等等,其中包含其他文件夹的文件夹。

我可以在 Makefile 中用这样的东西来做到这一点:

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

但是我如何在 CMakeFiles 中制作它?

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

但是

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

We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.

所以,虽然有点不方便,但最好明确列出组成库的文件。