Reputation: 131968
In the CMake documentation for target_link_libraries, it says:
target_link_libraries(<target> <PRIVATE|PUBLIC|INTERFACE> <item>... [<PRIVATE|PUBLIC|INTERFACE> <item>...]...)
The PUBLIC, PRIVATE and INTERFACE keywords can be used to specify both the link dependencies and the link interface in one command.
Libraries and targets following
PUBLIC
are linked to, and are made part of the link interface. Libraries and targets followingPRIVATE
are linked to, but are not made part of the link interface. Libraries followingINTERFACE
are appended to the link interface and are not used for linking .
I don't quite understand how this applies to library targets.
Suppose my language is C or C++; that targets lib1
and lib2
are libraries, and that target e1
is an executable. Now, if I write:
target_link_libraries(lib1 PRIVATE lib2)
target_link_libraries(e1 PRIVATE lib1)
Will e1
necessarily be linked against lib2
when I build e1
?
Note: If the answer differs depending on whether lib1
/lib2
are static or dynamic libraries, please say so.
Upvotes: 2
Views: 2074
Reputation: 141493
Will e1 necessarily be linked against lib2 when I build e1?
Yes.
But e1
will not have INCLUDE_DIRECTORIES
nor COMPILE_DEFINITIONS
that are PUBLIC
from lib2
.
Upvotes: 1