[CMake] Circular dependencies with Ninja, not with Unix Makefiles

Ignacio Fernández Galván jellby at yahoo.com
Thu May 4 03:55:26 EDT 2017


Hello,

I have a project where circular dependencies are generated when I use 
the Ninja generator, but not the default Unix Makefiles. I could create 
a minimal test like this:

$ cat CMakeLists.txt
add_subdirectory (ext ${PROJECT_BINARY_DIR}/ext)

$ cat ext/CMakeLists.txt
set (OUT ${CMAKE_CURRENT_LIST_DIR})

add_custom_command (OUTPUT ${OUT}/foo
     COMMAND touch ${OUT}/foo
     )

add_custom_target (foo ALL
     DEPENDS ${OUT}/foo
     )

add_custom_command (TARGET foo
     POST_BUILD
     COMMAND cp ${OUT}/foo ${CMAKE_BINARY_DIR}/foo
     )

$ touch ext/bar

$ cmake -G Ninja .
[...]

$ ninja
ninja: warning: multiple rules generate ext/foo. builds involving this 
target will not be correct; continuing anyway [-w dupbuild=warn]
ninja: error: dependency cycle: ext/foo -> ext/CMakeFiles/foo.util -> 
ext/CMakeFiles/foo -> ext/foo

I used a freshly compiled CMake 3.8 and the latest binary ninja from 
https://github.com/Kitware/ninja/releases.

Ignacio


More information about the CMake mailing list