collect source lists

The documentation for file GLOB says
"

Note

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. The CONFIGURE_DEPENDS flag may not work reliably on all generators, or if a new generator is added in the future that cannot support it, projects using it will be stuck. Even if CONFIGURE_DEPENDS works reliably, there is still a cost to perform the check on every rebuild."

I am editing a CMake build that does exactly that. Is there a recommended alternative approach?

Thanks,

Jerome

The recommended approach is to list the source files explicitly instead of relying on globbing. That way, you have to modify the CMakeList file when adding a new source, which causes CMake to re-run on next build, guaranteeing that the file will be picked up correctly.

If the file list is too long and you do not want to clutter your CMakeList with it, you can move the source definition (e.g. a target_sources() call) into a separate *.cmake file and include() that.

1 Like

Thanks!