简体   繁体   中英

CMake: add all files on current directory and subdirectories with target_sources()

In our C++ project, we have several CMakeLists.txt files (on different directories) listing every single cpp file desired with target_sources() .

For example:

target_sources(<Project> PUBLIC
    foo_1.cpp
    foo_2.cpp
    foo_3.cpp
)

This is fine in case we have few source files, but it's becoming harder for those directories where we have multiple cpp files to be added.

Is there a simple way to tell target_resources() to add all files on directory and subdirectories where CMakeList.txt file is?

For example, placing a CMakeLists.txt on a directory with multiple files and sub-directories (with more files) that just adds everything contained there.

This is solving my problem:

file(GLOB SRC_FILES    
    "*.cpp"
)

target_sources(<project> PUBLIC
    ${SRC_FILES}
)
´´´

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM