Skip to content

Ninja: file(GENERATE) outputs always considered dirty

The code

file(GENERATE
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.c
  CONTENT [[int main() { return 0; }]]
  )
add_executable(foo ${CMAKE_CURRENT_BINARY_DIR}/foo.c)

causes ninja to do the following after the first build:

$ ninja -d explain
ninja explain: output cmake_object_order_depends_target_foo of phony edge with no inputs doesn't exist
ninja explain: cmake_object_order_depends_target_foo is dirty
ninja explain: foo.c is dirty
ninja explain: foo.c is dirty
ninja explain: CMakeFiles/foo.dir/foo.c.o is dirty
ninja explain: foo is dirty
[1/3] 
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information