[cmake-developers] Add property to get all linked libraries including transitive ones

maikel van den Hurk maikelvandenhurk at hotmail.com
Tue Nov 1 16:30:06 EDT 2016


It would be nice to extend the current properties set of LINK_LIBRARIES and INTERFACE_LINK_LIBRARIES with a property to obtain actually all transitive linked libraries of a specific target. Currently you will have to traverse yourself over all targets to get in CMake a full overview of all linked libraries. This information should already be present internally to write out accordingly all the generator files accordingly. I do understand the fact that this information is only fully available during generation time. Would you be open for such extension point or is there are already one maybe?


For example:

add_library(Library1 library1.cpp)

target_link_libraries(Library1 PRIVATE Library2 PUBLIC Library3)


add_library(Library2 SHARED library2.cpp)

add_library(Library3 SHARED library3.cpp)


add_library(Library4 SHARED library4.cpp)

target_link_libraries(Library4 PRIVATE Library1 PUBLIC Library2)


get_target_property(ALL_DEPENDENCIES1 Library1 LINK_LIBRARIES)

get_target_property(ALL_DEPENDENCIES2 Library2 LINK_LIBRARIES)

get_target_property(ALL_DEPENDENCIES3 Library3 LINK_LIBRARIES)

get_target_property(ALL_DEPENDENCIES4 Library4 LINK_LIBRARIES)

get_target_property(INTERFACE_DEPENDENCIES1 Library1 INTERFACE_LINK_LIBRARIES)

get_target_property(INTERFACE_DEPENDENCIES2 Library2 INTERFACE_LINK_LIBRARIES)

get_target_property(INTERFACE_DEPENDENCIES3 Library3 INTERFACE_LINK_LIBRARIES)

get_target_property(INTERFACE_DEPENDENCIES4 Library4 INTERFACE_LINK_LIBRARIES)


message("All dependencies of Library1 are: ${ALL_DEPENDENCIES1}")

message("All dependencies of Library2 are: ${ALL_DEPENDENCIES2}")

message("All dependencies of Library3 are: ${ALL_DEPENDENCIES3}")

message("All dependencies of Library4 are: ${ALL_DEPENDENCIES4}")

message("Interface dependencies of Library1 are: ${INTERFACE_DEPENDENCIES1}")

message("Interface dependencies of Library2 are: ${INTERFACE_DEPENDENCIES2}")

message("Interface dependencies of Library3 are: ${INTERFACE_DEPENDENCIES3}")

message("Interface dependencies of Library4 are: ${INTERFACE_DEPENDENCIES4}")


That would result in:

All dependencies of Library1 are: Library2;Library3

All dependencies of Library2 are: ALL_DEPENDENCIES2-NOTFOUND

All dependencies of Library3 are: ALL_DEPENDENCIES3-NOTFOUND

All dependencies of Library4 are: Library1;Library2

Interface dependencies of Library1 are: $<LINK_ONLY:Library2>;Library3

Interface dependencies of Library2 are: INTERFACE_DEPENDENCIES2-NOTFOUND

Interface dependencies of Library3 are: INTERFACE_DEPENDENCIES3-NOTFOUND

Interface dependencies of Library4 are: Library2


It would be nice to request with a property for example from target Library4 all its linked libraries (i.e. the actual linker line), so in the example case you would get then Library1, Library2, Library3.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20161101/93f40ef7/attachment.html>


More information about the cmake-developers mailing list