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.

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to