CMake/Tests/ObjectLibrary/Transitive/CMakeLists.txt
Brad King f3ad061858 Add usage requirements to update direct link dependencies
Link line construction starts with `LINK_LIBRARIES` and appends
dependencies from the transitive closure of `INTERFACE_LINK_LIBRARIES`.
Only the entries of `LINK_LIBRARIES` are considered direct link
dependencies.  In some advanced use cases, particularly involving static
libraries and static plugins, usage requirements need to update the list
of direct link dependencies.  This may mean adding new items, removing
existing items, or both.

Add target properties to encode these usage requirements:

* INTERFACE_LINK_LIBRARIES_DIRECT
* INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE

Fixes: #22496
2022-01-29 06:48:13 -05:00

26 lines
1.1 KiB
CMake

add_library(FooStatic STATIC FooStatic.c)
add_library(FooObject1 OBJECT FooObject.c)
target_link_libraries(FooObject1 PRIVATE FooStatic)
add_executable(Transitive1 Transitive.c)
target_link_libraries(Transitive1 PRIVATE FooObject1)
add_library(FooObject2 OBJECT FooObject.c)
target_link_libraries(FooObject2 INTERFACE FooStatic)
add_executable(Transitive2 Transitive.c)
target_link_libraries(Transitive2 PRIVATE FooObject2)
add_library(FooObjectDirect OBJECT FooObject.c)
add_library(FooStaticDirect STATIC FooStatic.c)
set_property(TARGET FooStaticDirect PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT FooObjectDirect)
add_executable(TransitiveDirect Transitive.c)
target_link_libraries(TransitiveDirect PRIVATE FooStaticDirect)
add_library(BarObject1 OBJECT BarObject1.c)
add_library(BarObject2 OBJECT BarObject2.c)
add_library(BarObject3 OBJECT BarObject3.c)
set_property(TARGET BarObject1 PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT BarObject2)
set_property(TARGET BarObject2 PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT BarObject3)
add_executable(BarMain BarMain.c)
target_link_libraries(BarMain PRIVATE BarObject1)