target_link_libraries: Enable PRIVATE visibility for imported STATIC libraries
For a non-imported STATIC
library, the code
target_link_libraries(myStaticLib PRIVATE someDependency)
causes myStaticLib
's INTERFACE_LINK_LIBRARIES
to gain $<LINK_ONLY:someDependency>
to express the transitive private link dependency of the STATIC
library. Currently we reject this for an imported target:
IMPORTED library can only be used with the INTERFACE keyword of
target_link_libraries
Originally, usage requirements on imported targets always had to be specified by explicitly setting the INTERFACE_*
properties directly. Since #15689 (closed) and related issues were resolved, many usage requirements can be specified for imported targets using the INTERFACE
visibility with target_*
commands. The above case is another way to populate INTERFACE_LINK_LIBRARIES
of a STATIC
library, and so should be supported by target_link_libraries
. Otherwise, manually populating the private link dependencies of a static library requires knowledge of $<LINK_ONLY:...>
.
We also need to consider behavior for UNKNOWN
imported libraries, similar to #19434 (closed).
We could also consider behavior for INTERFACE
imported libraries that have IMPORTED_LIBNAME
set.