file(GET_RUNTIME_DEPENDENCIES): propagate parent rpath on macOS

Fixes: #24400
This commit is contained in:
Luis Caro Campos 2024-04-13 21:13:34 +01:00 committed by Brad King
parent 9ae75401d5
commit 3e865241f3
7 changed files with 78 additions and 4 deletions

View File

@ -126,10 +126,16 @@ bool cmBinUtilsMacOSMachOLinker::GetFileDependencies(
this->Archive->AddResolvedPath(filename, path, unique,
dep_file_info->rpaths);
if (unique &&
!this->ScanDependencies(path, dep_file_info->libs,
dep_file_info->rpaths, executablePath)) {
return false;
if (unique) {
std::vector<std::string> combinedParentRpaths =
dep_file_info->rpaths;
combinedParentRpaths.insert(combinedParentRpaths.end(),
rpaths.begin(), rpaths.end());
if (!this->ScanDependencies(path, dep_file_info->libs,
combinedParentRpaths,
executablePath)) {
return false;
}
}
}
} else {

View File

@ -42,6 +42,7 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
run_install_test(macos-unresolved)
run_install_test(macos-conflict)
run_install_test(macos-notfile)
run_install_test(macos-parent-rpath-propagation)
run_install_test(file-filter)
endif()
run_cmake(project)

View File

@ -0,0 +1,44 @@
enable_language(C)
# bin/exe (RPATH = "lib1:lib2:lib3")
# ^
# |
# lib1/libone.dylib (RPATH erased)
# ^
# |
# lib2/libtwo.dylib (RPATH erased)
# ^
# |
# lib3/libthree.dylib (RPATH erased)
# GET_RUNTIME_DEPENDENCIES(bin/exe) should resolve all three libraries
set(TEST_SOURCE_DIR "macos/parent-rpath-propagation")
add_library(three SHARED "${TEST_SOURCE_DIR}/three.c")
add_library(two SHARED "${TEST_SOURCE_DIR}/two.c")
target_link_libraries(two PRIVATE three)
add_library(one SHARED "${TEST_SOURCE_DIR}/one.c")
target_link_libraries(one PRIVATE two)
add_executable(exe "${TEST_SOURCE_DIR}/main.c")
target_link_libraries(exe PUBLIC one)
set_property(TARGET exe PROPERTY INSTALL_RPATH
@loader_path/../lib1
@loader_path/../lib2
@loader_path/../lib3
)
install(TARGETS exe DESTINATION bin)
install(TARGETS one DESTINATION lib1)
install(TARGETS two DESTINATION lib2)
install(TARGETS three DESTINATION lib3)
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES
"${CMAKE_INSTALL_PREFIX}/bin/$<TARGET_FILE_NAME:exe>"
)
]])

View File

@ -0,0 +1,8 @@
extern void one(void);
int main(void)
{
one();
return 0;
}

View File

@ -0,0 +1,6 @@
extern void two(void);
void one(void)
{
two();
}

View File

@ -0,0 +1,3 @@
void three(void)
{
}

View File

@ -0,0 +1,6 @@
extern void three(void);
void two(void)
{
three();
}