[CMake] Library deduplication and imported target dependencies

Stefano Bonicatti smjert at gmail.com
Mon May 30 08:15:47 EDT 2016


Hello there.
First of all is there any documentation about how CMake handles
deduplication of libraries when linking (so to avoid duplicate libraries to
be linked unnecessarily)?

Now to my issue: I have a library libA which has to link to libB, libC,
libD and libE.
libA is the only one internal to the CMake buildsystem, the other ones are
all external, and all are shared libs.
i obtain libB, libC and libD by path (find_package) and libE is an imported
target (added with add_library(libE SHARED IMPORTED)).

libE is actually compiled through custom commands and have dependencies
that i've set with set_target_properties(libE PROPERTIES
INTERFACE_LINK_LIBRARIES "${LIBRARY_DEPS}").

The deps are libC, libD, libF, libG and they're set with set(LIBRARY_DEPS
${LIBC} ${LIBD} ${LIBF} ${LIBG}).

Now if i look at the libA link command line, i see libC and libD duplicated.

The libs libA needs are linked with target_link_libraries and, except for
libE which is a target, they are all specified as absolute paths.

Now i've also tried removing the quotes around ${LIBRARY_DEPS}, when using
it, but this time while it deduplicates libC and libD, libF and libG aren't
linked anymore...

I've also tried creating imported targets for libC and libD, using them in
libA target_link_libraries (while still specifing the absolute path for
INTERFACE_LINK_LIBRARIES of libE), but it still doesn't deduplicate them.

Any clue?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160530/c66ba319/attachment.html>


More information about the CMake mailing list