GET_RUNTIME_DEPENDENCIES has quirks and issues in cmake 3.17.2 so an answer to your question will depend on the build platform.
Short story:
On Linux it does not work as expected so I needed to implement something naiv. The following code is a excerpt from my code and maybe lacking variable declarations, functions definitions, … and elegance but the gist is hopefully clear.
# GET_RUNTIME_DEPENDENCIES does not work on Linux using cmake 3.17.2
# it does not honour the paths given by ldd and searches in system paths itself.
# in doing so it picks up 32 Bit system libs for 64 Bit builds
# this is a naive implementation that uses ldd
if (DEFINED ENV{LD_LIBRARY_PATH})
message (WARNING "LD_LIBRARY_PATH is defined. This may lead to the installation of library versions that were not used at link time.")
endif()
foreach (lib ${all_libs})
execute_process(COMMAND ldd ${lib} OUTPUT_VARIABLE ldd_out)
string (REPLACE "\n" ";" ldd_out_lines ${ldd_out})
foreach (line ${ldd_out_lines})
string (REGEX REPLACE "^.* => | \(.*\)" "" pruned ${line})
string (STRIP ${pruned} dep_filename)
if (IS_ABSOLUTE ${dep_filename})
is_system_lib (${dep_filename} sys_lib)
if (sys_lib EQUAL 0 OR INSTALL_SYSLIBS STREQUAL "true")
list (FIND dependencies ${dep_filename} found)
if (found LESS 0)
list (APPEND dependencies ${dep_filename})
endif()
endif()
endif()
endforeach()
endforeach()
On windows it works but has problems with API_SETS. Small code snippet
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
#[[
The following statements are a workaround of problems that cmake 3.17 has with Windows API sets.
Reference: https://ofekshilon.com/2016/03/27/on-api-ms-win-xxxxx-dll-and-other-dependency-walker-glitches/
#]]
LIST(APPEND pre_exclude_regexes "api-ms-.*") # windows API
LIST(APPEND pre_exclude_regexes "ext-ms-.*") # windows API
LIST(APPEND pre_exclude_regexes "ieshims.dll") # windows API
LIST(APPEND pre_exclude_regexes "emclient.dll") # windows API
LIST(APPEND pre_exclude_regexes "devicelockhelpers.dll") # windows API
LIST(APPEND post_exclude_regexes ".*WINDOWS[\\/]system32.*") # windows system dlls
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR dependencies
LIBRARIES ${all_libs}
DIRECTORIES ${TBT_PATH_EXTERNAL}
CONFLICTING_DEPENDENCIES_PREFIX conflicts
PRE_EXCLUDE_REGEXES ${pre_exclude_regexes}
POST_EXCLUDE_REGEXES ${post_exclude_regexes}
POST_INCLUDE_REGEXES ${post_include_regexes}
)
list (LENGTH conflicts_FILENAMES num_files_conflict)
if (${num_files_conflict} GREATER 0)
message(WARNING "dependencies of ${lib} found at multiple locations will not be installed.")
foreach (lib_conflict ${conflicts_FILENAMES})
message(STATUS "${lib_conflict} found at: ${conflicts_${lib_conflict}}")
endforeach()
endif()
endif()