Add all files under a folder to a CMake glob?

好久不见. 提交于 2019-11-26 16:45:24

问题


I've just read this:

CMake - Automatically add all files in a folder to a target?

With the answer suggesting a file glob, e.g.:

file(GLOB "*.h" "*.cpp")

now, what if I want my target to depend on all files of a certain type under a certain folder - which might be within multiple subfolders? I tried using

execute_process(COMMAND find src/baz/ -name "*.cpp" OUTPUT_VARIABLE BAR)

and then

add_executable(foo ${BAR}

but this gives me the error:

Cannot find source file:

  src/baz/some/file/here

src/baz/some/other_file/here

src/baz/some/other_file/here2

(yes, with that spacing.)

What am I doing wrong here?


回答1:


Turning my comment into an answer

If you want to add recursive searching for files use file(GLOB_RECURSE ...)

file(GLOB_RECURSE source_list "*.cpp" "*.hpp")

Your second example would translate into

file(GLOB_RECURSE BAR "src/baz/*.cpp")

References

  • file(...)
  • Specify source files globally with GLOB?


来源:https://stackoverflow.com/questions/35411489/add-all-files-under-a-folder-to-a-cmake-glob

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