Skip to content

file(GET_RUNTIME_DEPENDENCIES) should search LC_RPATH till the root and not just it's immediate parent

Please see minimal example to reproduce the problem:

project(App)
add_library(Foo SHARED Foo.cpp Foo.h)
add_library(Bar SHARED Bar.cpp Bar.h)

# this removes LC_RPATH for Bar to simulate the problem
set_property(TARGET Bar PROPERTY BUILD_WITH_INSTALL_RPATH TRUE)

target_link_libraries(Bar PUBLIC Foo)

add_executable(App main.cpp)

target_link_libraries(App PUBLIC Bar)
install(TARGETS App RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(CODE [[file(GET_RUNTIME_DEPENDENCIES EXECUTABLES $<TARGET_FILE:App>
                    RESOLVED_DEPENDENCIES_VAR deps)]])

make install shows file Could not resolve runtime dependencies: @rpath/libFoo.dylib, but in fact it should be able to because libFoo.dylib exists in the LC_RPATH of App. It can be further confirmed that there's no problem executing App.

The real situation is Bar links to Foo.tbd instead of Foo.dylib, so Bar and Foo can be compiled in parallel, which is crucial for large scale projects, but as a result Bar does not have LC_RPATH to Foo, which breaks CMake's current file(GET_RUNTIME_DEPENDENCIES), but it should still work as long as the final App have LC_RPATH to both Bar and Foo.

This is a bit similar to #24172 (closed), but on macOS. cc @kyle.edwards @marc.chevrier

Edited by Jason Juang
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information