CMake's PRE_LINK forces ninja to build
I have annoying ninja issue with my slightly specific setup. I also have to say there are no issues if I use make but I prefer using ninja. My setup is:
- Ubuntu 19.04
- CMake-3.13.4
- ninja-1.9.0
- test.cpp is simple "hello world" program
- before linking I am modifying object file (in the example below I am touching the file - therefore modifying timestamp of the object file)
- compilation is successful
Next time when ninja runs and nothing has changed - ninja will recompile test.cpp (and modify object file and re-link). Make doesn't do that.
I have a workaround but that causes make to behave as ninja - it builds even if nothing has changed. In real life project, object file is not only touched, but also modified. But only touching the object file exposes the issue.
cmake_minimum_required(VERSION 3.12)
add_executable(ninja-test test.cpp)
add_custom_command(
TARGET ninja-test
PRE_LINK
COMMAND sleep 1 && touch ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ninja-test.dir/test.cpp.o # Modify object file
# COMMAND touch -r ${CMAKE_SOURCE_DIR}/test.cpp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ninja-test.dir/test.cpp.o # This line fixes ninja but breaks make
)
Is there any other way in CMake to 'embed' PRE_LINK step in ninja's build graph?
Cross-post in ninja-build mailing list: https://groups.google.com/forum/#!topic/ninja-build/yfBcw6J2qYA