Skip to content

[CMake] fix plutil runpath for ELF platforms #2999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Sources/Tools/plutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ add_executable(plutil
main.swift)
target_link_libraries(plutil PRIVATE
Foundation)

# On ELF platforms, remove the absolute rpath to the host toolchain's stdlib,
# then add it back temporarily as a BUILD_RPATH just for the tests.
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
target_link_options(plutil PRIVATE "SHELL:-no-toolchain-stdlib-rpath")

string(REPLACE " " ";" ARGS_LIST ${CMAKE_Swift_FLAGS})
execute_process(
COMMAND ${CMAKE_Swift_COMPILER} ${ARGS_LIST} -print-target-info
OUTPUT_VARIABLE output
ERROR_VARIABLE error_output
RESULT_VARIABLE result
)
if(NOT ${result} EQUAL 0)
message(FATAL_ERROR "Error getting target info with\n"
" `${CMAKE_Swift_COMPILER} ${CMAKE_Swift_FLAGS} -print-target-info`\n"
"Error:\n"
" ${error_output}")
endif()

string(REGEX MATCH "\"runtimeLibraryPaths\": \\[\n\ +\"([^\"]+)\""
path ${output})
set_target_properties(plutil PROPERTIES BUILD_RPATH ${CMAKE_MATCH_1})
endif()

set_target_properties(plutil PROPERTIES
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

Expand Down