[CMake] Proposal: extra option PRIVATE for target_link_libraries

Alexander Neundorf a.neundorf-work at gmx.net
Wed Dec 23 08:36:56 EST 2009


On Wednesday 23 December 2009, Marcel Loose wrote:
> Hi all,
>
> I suggested this in the quite long thread "third party library
> dependencies", but it may have been overlooked. Hence, I started a new
> thread.
>
> Upon (re)reading the Mandriva page
> http://wiki.mandriva.com/en/Overlinking, I was thinking: maybe the issue
> of overlinking can be solved more or less the same way as pkg-config
> does: i.e. by defining private dependencies. This could be an extra
> option to target_link_libraries.
> Something like:
>
>   target_link_libraries(mylib public1 public2 PRIVATE private1 private2)

Assuming that public1 and public2 are libraries also built with cmake, that 
can be done already today:

add_library(public1 ...)
target_link_libraries(public1 private1)
target_link_libraries(public1 LINK_INTERFACE_LIBRARIES "")

add_library(public2 ...)
target_link_libraries(public2 private2)
target_link_libraries(public2 LINK_INTERFACE_LIBRARIES "")

install(TARGETS public1 public2 ... EXPORT MyPublicLibs)
install(EXPORT ...)


Then later on, when loading these exported targets, you will get what you 
want. If public1/2 are shared libs, their "link interface" will be empty. If 
they are static, you will link against everything they have been "linked" 
against, independent of the LINK_INTERFACE_LIBRARIES (which is used only for 
shared libs).

Alex


More information about the CMake mailing list