After reading the discussion in https://gitlab.kitware.com/cmake/cmake/-/issues/24504 I decided to post some follow up question here.
The mentioned discussion talks about cyclic dependencies but I actually have an issue with normal transitive dependencies. Let’s say we have static libraries A, U and an executable T.
A which “links” against U
T which links against U A
A of course only “links” by using target_link_libraries to get the include paths from U.
When I now specify to link against U with the WHOLE_ARCHIVE option (using the override in my case) the final linker command will link against U twice, both times with the whole-archive option. This results in a multiple definition error.
Is there a solution to this?
P.S. The background of using WHOLE_ARCHIVE at all is that T is a test executable for testing the library U. To generate coverage data (uncovered) also for unused object files I want to include the full library.