Skip to content

Commit 78f2ce5

Browse files
Merge pull request #2999 from buttaface/plutil-rpath
[CMake] fix plutil runpath for ELF platforms
2 parents f8dc398 + caa1a83 commit 78f2ce5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Sources/Tools/plutil/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@ 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+
string(REPLACE " " ";" ARGS_LIST ${CMAKE_Swift_FLAGS})
12+
execute_process(
13+
COMMAND ${CMAKE_Swift_COMPILER} ${ARGS_LIST} -print-target-info
14+
OUTPUT_VARIABLE output
15+
ERROR_VARIABLE error_output
16+
RESULT_VARIABLE result
17+
)
18+
if(NOT ${result} EQUAL 0)
19+
message(FATAL_ERROR "Error getting target info with\n"
20+
" `${CMAKE_Swift_COMPILER} ${CMAKE_Swift_FLAGS} -print-target-info`\n"
21+
"Error:\n"
22+
" ${error_output}")
23+
endif()
24+
25+
string(REGEX MATCH "\"runtimeLibraryPaths\": \\[\n\ +\"([^\"]+)\""
26+
path ${output})
27+
set_target_properties(plutil PROPERTIES BUILD_RPATH ${CMAKE_MATCH_1})
28+
endif()
29+
530
set_target_properties(plutil PROPERTIES
631
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
732

0 commit comments

Comments
 (0)