Open leleliu008 opened 1 month ago
I don't think this is correct use for aux_source_directory
... Even the reference you linked mentions, that it causes trouble, when it's used to find files to compile:
It is tempting to use this command to avoid writing the list of source files for a library or executable target. While this seems to work, there is no way for CMake to generate a build system that knows when a new source file has been added.
when adding a new source file, you just need to rerun cmake -S . -B build.d
to reconfigure, you don't need to add it to source list in CMakeLists.txt
After some more digging I have found that file(GLOB ... CONFIGURE_DEPENDS)
should work even without the need to manually rerun cmake -B
when files are changed. It requires cmake 3.12, but I see no problem in upgrading the dependency. The docs say it is still not recommended to use this feature, but at it seems to work well, at least with common generators.
Docs: https://cmake.org/cmake/help/latest/command/file.html#glob
It is also simpler then using aux_source_directory
multiple times, as it can gather all the files at once:
file(
GLOB_RECURSE sources
CONFIGURE_DEPENDS
LIST_DIRECTORIES false
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
src/*.c src/*.cc ${CMAKE_CURRENT_BINARY_DIR}/version.cc
)
Reference: https://cmake.org/cmake/help/latest/command/aux_source_directory.html