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

时间秒杀一切 提交于 2021-01-29 14:50:37

问题


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.


回答1:


This is solving my problem:

file(GLOB SRC_FILES    
    "*.cpp"
)

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


来源:https://stackoverflow.com/questions/60540624/cmake-add-all-files-on-current-directory-and-subdirectories-with-target-sources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!