CMake shell find

CMake shell find

本文关键字:find shell CMake      更新时间:2023-10-16

我正在尝试从使用 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)                                                                                                                                                        

#However,该文件(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 中做到这一点?

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

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

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

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