[CMake] Executable depending on all source files
Alexander Neundorf
a.neundorf-work at gmx.net
Sat Aug 25 06:04:21 EDT 2012
On Saturday 25 August 2012, Russell Wallace wrote:
> I don't understand what you mean, but explicit listing violates DRY in
> a big way with the usual consequence, the two lists will inevitably
> get out of sync.
Yes, but here this is good IMO, since in general a file laying around in some
directory does not necessarily belong to the project.
> I'd rather use globbing (unless CMake has some other
> method that doesn't involve trying to keep things in sync by hand)?
There is not much "trying" involved. You notice immediately if a file is
missing in your CMakeLists.tx or if you list a file which does not exist.
> Even plain Make can use globbing reliably.
You can use file(GLOB ...), but it is not recommended.
When a new file is added to a target, cmake needs to rerun, to generate the
rules for building this file and to link the target.
In the makefiles generated by cmake there is the dependency to rerun cmake
when any of its input files have changed (e.g. when you added or removed a
source file), but there is no rule to rerun cmake if anything in a directory
has changed. So simply adding a file to a directory will not cause cmake to
rerun automatically.
By having to add that file explicitely to the CMakeLists.txt, cmake will rerun
and you will always have a consistent build system.
Alex
More information about the CMake
mailing list