Ninja does not always rebuild resource files (*.rc) when they were changed
I have a project with a custom command that updates the current version number (based on git commit hash) on every build and updates two files (a header file and a resource file) via configure_file
.
The custom command is added with add_custom_command
and looks something like this:
add_custom_command(
OUTPUT
non-existing.txt # force to execute on every build
version.h
program.rc
COMMAND
${CMAKE_COMMAND} update_version.cmake)
The idea is that the current version is accessible from within the code but is also saved into the executable files version information.
A minimal sample project showing the issue is attached. test.zip
Problem
When I use cmake -G Ninja
to configure the project and subsequently run ninja
the RC object is only built every second run (i.e. the change to the .rc file occuring on every run is not detected by the build system immediately). This is highlighted by the following output:
$ ninja
[1/5] Generating non-existing.txt, version.h, hello.rc
[2/5] cmd.exe /c
[3/5] Building RC object CMakeFiles/hello.dir/hello.rc.obj
[4/5] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
[5/5] Linking CXX executable hello.exe
$ ninja
[1/3] Generating non-existing.txt, version.h, hello.rc
[2/3] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
[3/3] Linking CXX executable hello.exe
$ ninja
[1/4] Generating non-existing.txt, version.h, hello.rc
[2/4] Building RC object CMakeFiles/hello.dir/hello.rc.obj
[3/4] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
[4/4] Linking CXX executable hello.exe
$ ninja
[1/3] Generating non-existing.txt, version.h, hello.rc
[2/3] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
[3/3] Linking CXX executable hello.exe
$ ninja
[1/4] Generating non-existing.txt, version.h, hello.rc
[2/4] Building RC object CMakeFiles/hello.dir/hello.rc.obj
[3/4] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
[4/4] Linking CXX executable hello.exe
I also tested cmake -G "MinGW Makefiles
and mingw32-make
which rebuilds both the .rc file and the .cpp file in every run.
Environment information
cmake 3.8.2 and Ninja 1.7.2 on MSYS2 (specifically mingw-w64-x86_64-cmake 3.8.2-2 and mingw-w64-i686-ninja 1.7.2-1)
However standalone cmake 3.9.0-rc6 with standalone ninja version 1.7.2 is also affected.
Interestingly and older standalone version cmake 3.7.2 seems not to have had this problem.