cmake: recursively collect all the linked shared libraries

Viewed 115

Is it possible to write a function in cmake, that will recursively collect all the linked libraries (that are of type SHARED)?

This is a function that goes only one level deep, and appends *-NOTFOUND entities to the list, that I would like to avoid.

get_target_property(libs App LINK_LIBRARIES)
set(list_libs ${libs})
foreach(lib ${libs})
    get_target_property(ls ${lib} LINK_LIBRARIES)
    list(APPEND list_libs ${ls})
endforeach()

message(STATUS "Linked libraries: ${list_libs}")

If it is possible, that would make deployment rather trivial. Because we would have a definitive list of dlls that needs to be copied to the folder of the executable or dependent library.

foreach(lib ${list_libs})
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${lib}> $<TARGET_FILE_DIR:App>
endforeach()
0 Answers
Related