pavelliavonau/cmakeconverter

add_custom_command_if cyclic dependency

aleiby opened this issue · 2 comments

I'm getting a cyclic dependency from a PRE_BUILD step. The initial dependency is clear, I'm just not seeing where the reverse dependency is being added.

My setup:

  • I have two vcproj files in the same directory: core (STATIC LIBRARY) and core_test (EXECUTABLE).
  • These get combined into a single CMakeLists.txt.
  • Both projects have both PRE_BUILD and POST_BUILD steps.
  • CMake is complains about a cyclic dependency on the exe (core_test), and also notes that "Cyclic dependencies are allowed only among static libraries." (presumably why it didn't complain about the core project itself).

Full error:

1> [CMake] CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
1> [CMake]   "core_test" of type EXECUTABLE
1> [CMake]     depends on "core_test_PRE_BUILD" (strong)
1> [CMake]   "core_test_PRE_BUILD" of type UTILITY
1> [CMake]     depends on "core_test" (strong)
1> [CMake] At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.
1> [CMake] CMake Generate step failed.  Build files cannot be regenerated correctly.

I see in CMake/Utils.cmake, the call to:

add_dependencies(${TARGET} ${NAME})

This accounts for the expected "core_test" of type EXECUTABLE depends on "core_test_PRE_BUILD" (strong) part.
The only other add_dependencies I could find is the one for:

add_dependencies(${PROJECT_NAME} core)

For core_test.exe to link to core.lib.

Any idea where the second "core_test_PRE_BUILD" of type UTILITY depends on "core_test" (strong) is coming from?

Thanks!

May be related to https://gitlab.kitware.com/cmake/cmake/-/issues/22246.
If so - then redo your prebuild step and remove dependency on target properties.

Thanks! Yes, the PRE_BUILD step was using $<TARGET_FILE_NAME:${PROJECT_NAME}>. Setting cmake_minimum_required to 3.19.0 (was 3.15.0) resolved the issue.