RPATH: Support CMAKE_SYSROOT value of /

Fixes: #27882
This commit is contained in:
Robert Maynard
2026-06-25 13:53:08 -04:00
parent cdcc758ff5
commit b6d3e9ba18
3 changed files with 24 additions and 2 deletions
+3 -2
View File
@@ -2266,7 +2266,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
// support or if using the link path as an rpath.
if (use_build_rpath) {
std::string d = ri;
if (!rootPath.empty() && cmHasPrefix(d, rootPath)) {
if (!rootPath.empty() && rootPath != "/" && cmHasPrefix(d, rootPath)) {
d.erase(0, rootPath.size());
} else if (cmNonempty(stagePath) && cmHasPrefix(d, *stagePath)) {
d.erase(0, (*stagePath).size());
@@ -2297,7 +2297,8 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
!cmSystemTools::IsSubDirectory(ri, topSourceDir) &&
!cmSystemTools::IsSubDirectory(ri, topBinaryDir)) {
std::string d = ri;
if (!rootPath.empty() && cmHasPrefix(d, rootPath)) {
if (!rootPath.empty() && rootPath != "/" &&
cmHasPrefix(d, rootPath)) {
d.erase(0, rootPath.size());
} else if (cmNonempty(stagePath) && cmHasPrefix(d, *stagePath)) {
d.erase(0, (*stagePath).size());
@@ -31,6 +31,8 @@ if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
run_RuntimePath(Genex)
run_cmake_command(GenexCheck
${CMAKE_COMMAND} -Ddir=${RunCMake_BINARY_DIR}/Genex-build -P ${RunCMake_SOURCE_DIR}/GenexCheck.cmake)
run_RuntimePath(SysrootSlash)
endif()
block()
@@ -0,0 +1,19 @@
enable_language(C)
# Setting CMAKE_SYSROOT to "/" must not strip the leading "/" from RPATH entries.
set(CMAKE_SYSROOT "/")
function(CheckRpath target rpath)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -Dfile=$<TARGET_FILE:${target}> -Drpath=${rpath}
-P "${CMAKE_CURRENT_SOURCE_DIR}/RelativeCheck.cmake"
VERBATIM
)
endfunction()
add_library(sysroot-slash-lib SHARED A.c)
add_executable(sysroot-slash-exe main.c)
target_link_libraries(sysroot-slash-exe sysroot-slash-lib)
CheckRpath(sysroot-slash-exe "${CMAKE_CURRENT_BINARY_DIR}${cfg_dir}")