Circular dependencies with Ninja, not with Unix Makefiles

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Circular dependencies with Ninja, not with Unix Makefiles

CMake mailing list
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
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Circular dependencies with Ninja, not with Unix Makefiles

Robert Maynard
Hi,

This is caused by doing an in source build and thereby causing the issue. The custom command is outputting a file called 'foo', which is also the chosen name of a target in the ninja file. All of this results in ninja conflating the two and causing a circular dependency.

Your options are to not to in source builds, or to choose a different name for your custom target.

On Thu, May 4, 2017 at 3:55 AM, Ignacio Fernández Galván via CMake <[hidden email]> wrote:
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
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Circular dependencies with Ninja, not with Unix Makefiles

CMake mailing list
Well, in my real case this happens even with out-of-source builds, which
also occurs in the test case if I change:

set (OUT ${CMAKE_BINARY_DIR}/ext)

in ext/CMakeLists.txt.

Sure, I can avoid it by renaming the file or target, but I thought this
is something that could be avoided by either (a) generating unique ninja
target names when possible, or (b) warning at the cmake stage that
target names are duplicated.

 From my point of view as a CMake user, I see no reason why the
combination of add_custom_command and add_custom_target should have a
conflict.

On 05/05/17 14:22, Robert Maynard wrote:

> Hi,
>
> This is caused by doing an in source build and thereby causing the
> issue. The custom command is outputting a file called 'foo', which is
> also the chosen name of a target in the ninja file. All of this results
> in ninja conflating the two and causing a circular dependency.
>
> Your options are to not to in source builds, or to choose a different
> name for your custom target.
>
> On Thu, May 4, 2017 at 3:55 AM, Ignacio Fernández Galván via CMake
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     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
>     <https://github.com/Kitware/ninja/releases>.
>
>     Ignacio
>     --
>
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Please keep messages on-topic and check the CMake FAQ at:
>     http://www.cmake.org/Wiki/CMake_FAQ
>     <http://www.cmake.org/Wiki/CMake_FAQ>
>
>     Kitware offers various services to support the CMake community. For
>     more information on each offering, please visit:
>
>     CMake Support: http://cmake.org/cmake/help/support.html
>     <http://cmake.org/cmake/help/support.html>
>     CMake Consulting: http://cmake.org/cmake/help/consulting.html
>     <http://cmake.org/cmake/help/consulting.html>
>     CMake Training Courses: http://cmake.org/cmake/help/training.html
>     <http://cmake.org/cmake/help/training.html>
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
>     <http://www.kitware.com/opensource/opensource.html>
>
>     Follow this link to subscribe/unsubscribe:
>     http://public.kitware.com/mailman/listinfo/cmake
>     <http://public.kitware.com/mailman/listinfo/cmake>
>
>

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake