[CMake] Transitive behavior of target_link_libraries between shared/static

Robert Dailey rcdailey.lists at gmail.com
Mon Jul 17 11:31:11 EDT 2017


Suppose I have the following:

```
add_library( A STATIC ${files} )

add_library( B SHARED ${more_files} )
target_link_libraries( B PUBLIC A )

add_library( C STATIC ${even_more_files} )
target_link_libraries( C PUBLIC B )


add_executable( D ${exe_files} )
target_link_libraries( D PRIVATE C )
```

Does the linker command for target `D` ever see target A's static link
library? I'm hoping the only thing the linker gets is `libB.so` and
`libC.a`, without `libA.a`.

It seems like A to everyone outside of B should just be a set of
public include directories and compile definitions, since the link
file aspect of it should be hidden across shared library boundaries.
Hoping someone can explain how this works. I want to make sure static
libs sitting behind shared libs in the dependency tree do not get
exposed.


More information about the CMake mailing list