I have some header-only library dependency Foo::foo which I do not want to end up in the exported targets of my library. To prevent that from happening, the library is linked as follows:
target_link_libraries(my_library
PRIVATE
$<BUILD_INTERFACE:Foo::foo>
)
This works, however Foo::foo itself depends on some libraries that I do want to be exported, since symbols of those libraries end up in the resulting library. Right now, I ensure those libraries are exported as follows:
get_property(_fooInterfaceLinkLibraries TARGET Foo::foo PROPERTY INTERFACE_LINK_LIBRARIES)
target_link_libraries(my_library
PRIVATE
$<BUILD_INTERFACE:Foo::foo>
$<INSTALL_INTERFACE:${_fooInterfaceLinkLibraries}>
)
Is this the ‘canonical’ approach, or is there a simpler approach? Note; using $<TARGET_PROPERTY:...> in the target_link_libraries call does not work since the generator expression itself ends up in the exported targets CMake file, still requiring the Foo::foo target to be known by any consumer.