Cyclic Dependencies of Static Targets
I ran into the following issue. I have a set of external static libraries and I have written a single FindXXX.cmake file for then. For each library I have created an imported static library and have set the required properties. For example:
# FindXXX.cmake
add_library(External::A STATIC IMPORTED)
add_library(External::B STATIC IMPORTED)
set_target_properties(External::A PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${libA}/include
IMPORTED_LOCATION_RELEASE ${libA}/lib/liba-o.a
IMPORTED_LOCATION_RELWITHDEBINFO ${libA}/lib/liba-o.a
IMPORTED_LOCATION_DEBUG ${libA}/lib/liba-d.a)
set_target_properties(External::B PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${libB}/include
IMPORTED_LOCATION_RELEASE ${libB}/lib/libb-o.a
IMPORTED_LOCATION_RELWITHDEBINFO ${libB}/lib/libb-o.a
IMPORTED_LOCATION_DEBUG ${libB}/lib/libb-d.a)
list (APPEND External_Libs External::A)
list (APPEND External_Libs External::B)
Now the two libraries both have cyclic dependencies on each other, which is fine. The previous solution for this was to double the External_Libs list by append to itself. For example:
list (APPEND External_Libs ${External_Libs})
However this solution does not seem to work anymore. Now I have read the cyclic dependency notes in the documentation here and tried to each library to the other by means of LINK_LIBRARIES. For example:
set_target_properties(External::A PROPERTIES LINK_LIBRARIES External::B)
set_target_properties(External::B PROPERTIES LINK_LIBRARIES External::A)
However this did not work. What I would have expected is the same behavior as in the example in the documentation. Now my question is, did I miss something here. Is this working as intended? Or is this actually a bug?
Workaround
Also if you are running into the same problem. Our current workaround is to directly add the libraries to the linker by means of target_link_libraries. For example:
project(SomeProject)
find_package(XXX REQUIRED)
add_executable(${PROJECT_NAME} ${SOME_SOURCES})
target_link_libraries(${PROJECT_NAME} ${External_Libs})
target_link_libraries(${PROJECT_NAME} ${libA}/lib/liba-o.a)
target_link_libraries(${PROJECT_NAME} ${libB}/lib/libb-o.a)
The resulting link command will link the static libraries twice resolving all cyclic dependencies.