make and ninja inconsistency
Hello,
I have following construct to generate an info about current git revision in build time. I want to do it during build time because I need to know if my repo is dirty.
set(gitrev_src ${CMAKE_BINARY_DIR}/gitrev.c)
add_custom_command(
OUTPUT dummy_g ${gitrev_src}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gitrev.sh ${CMAKE_CURRENT_SOURCE_DIR} ${gitrev_src}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gitrev.sh
VERBATIM
)
target_sources(app PRIVATE ${gitrev_src})
dummy_g
is there to run the command every time. gitrev.sh
generates a new gitrev.c
only when the git revision was really changed, otherwise the file is not touched. There is just a line with variable assignment (const char * const gitrev = "xxx";
).
It is working as I expected using Ninja generator - app is linked only when gitrev.c was touched. However with make the app is relinked everytime. Moreover I noticed that make behavior even depends on the order of outputs OUTPUT dummy_g ${gitrev_src}
. If dummy_g
is listed as first, than gitrev.c
is deleted before build (Deleting primary custom command output "gitrev.c" because another output "dummy_g" does not exist.). Ninja does not take care.
I know that there are many similar issues reported but I'd like to know if there is a way how to handle this properly in current cmake versions. I have tried to play with BYPRODUCTS
but have not find a solution.
br Jan