[CMake] correct dependencies of update-if-different generated files?`
Matthew Woehlke
matthew.woehlke at kitware.com
Mon Jul 29 19:02:38 EDT 2013
Let's say¹ I have a code generation tool, 'gen', that I am naïvely using
to build a library, like so:
add_custom_command(
OUTPUT a.cpp b.cpp
COMMAND gen in.xml
DEPENDS in.xml
)
add_library(foo a.cpp b.cpp)
Now let's say that 'gen' is clever and does not overwrite the output
files with identical content (sort-of like configure_file).
Now, if in.xml is changed, the 'gen' command will run every time because
the mtime of in.xml is newer than that of a.cpp and b.cpp.
BUT... this "only" affects gmake (at least, it does not affect ninja²
and reportedly does not affect VS).
Has anyone run into this before, and/or is there a way to express the
build rules so that the build will completely converge (will not execute
any commands) *without* unnecessarily recompiling the generated source
files?
And, since I don't believe that there is, how would folks feel about
improving add_custom_command to specifically handle this case? I think
in pure make it is possible to solve the problem by having the custom
command also update a sentinel file on successful completion, and doing
like:
a.cpp b.cpp: sentinel
# No command here!
sentinel: in.xml
gen in.xml
touch sentinel
Such an enhancement would also be desirable as it would allow
'automatic' adjusting of the build rules for generators that have the
problem with only a minor change to the CMake rules, and without
penalizing generators that are more clever.
(¹ Original/actual code where I ran into this:
https://codereview.qt-project.org/61497)
(² Ninja is not affected because it records the last time it updated the
output files independent of their mtime.)
--
Matthew
More information about the CMake
mailing list