Skip to content

Commit 12fe02a

Browse files
committed
[CMake] fix plutil runpath for ELF platforms
Remove the absolute path to the host toolchain's stdlib from plutil, and add it as a CMake BUILD_PATH, so that it's removed upon installation.
1 parent eec4b26 commit 12fe02a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Sources/Tools/plutil/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@ add_executable(plutil
22
main.swift)
33
target_link_libraries(plutil PRIVATE
44
Foundation)
5+
6+
# On ELF platforms, remove the absolute rpath to the host toolchain's stdlib,
7+
# then add it back temporarily as a BUILD_RPATH just for the tests.
8+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
9+
target_link_options(plutil PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
10+
11+
execute_process(
12+
COMMAND ${CMAKE_Swift_COMPILER} ${CMAKE_Swift_FLAGS} -print-target-info
13+
OUTPUT_VARIABLE output
14+
ERROR_VARIABLE error_output
15+
RESULT_VARIABLE result
16+
)
17+
if(NOT ${result} EQUAL 0)
18+
message(FATAL_ERROR "Error getting target info with\n"
19+
" `${CMAKE_Swift_COMPILER} ${CMAKE_Swift_FLAGS} -print-target-info`\n"
20+
"Error:\n"
21+
" ${error_output}")
22+
endif()
23+
24+
string(REGEX MATCH "\"runtimeLibraryPaths\": \\[\n\ +\"([^\"]+)\""
25+
path ${output})
26+
set_target_properties(plutil PROPERTIES BUILD_RPATH ${CMAKE_MATCH_1})
27+
endif()
28+
529
set_target_properties(plutil PROPERTIES
630
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
731

0 commit comments

Comments
 (0)