Hi IMHO, I partially agree for the executable part but not for the library one.
First of all it does not depend on the shared/static status.
Let say a lib A depends on a lib B.
If the headers of A that may be included by an application that links A contains symbols from B then target_link_libraries(A PUBLIC B)
otherwise target_link_libraries(A PRIVATE B)
another situation may arise: B symbols are only present in A headers but are not used for A sources.
then target_link_libraries(A INTERFACE B)
for applications I agree that PUBLIC
or PRIVATE
should not make a difference, yet its cleaner then to use PRIVATE
.
I sum up it in the following way (for target_compile_definitions
and target_link_libraries
):
PRIVATE
: the target uses the definition/dependency only to be build, not its clients
PUBLIC
: the target uses the definition/dependency when it is built, its clients also use it
INTERFACE
: the target does not uses the definition/dependency when it is built, but its clients use it