Skip to content

Commit 817bb47

Browse files
authored
Merge pull request #2559 from compnerd/rpath
build: honour and use RPATHs
2 parents bb11bb4 + ffcfbcc commit 817bb47

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ enable_testing()
1717
# Cache the variable to allow the user to alter the configuration.
1818
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE
1919
STRING "MSVC Runtime Library")
20+
if(CMAKE_VERSION VERSION_LESS 3.16.0)
21+
if(NOT (CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin))
22+
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ")
23+
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP ":")
24+
endif()
25+
endif()
2026

2127
option(BUILD_SHARED_LIBS "build shared libraries" ON)
2228

Foundation/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ target_link_libraries(Foundation PRIVATE
153153
uuid)
154154
target_link_libraries(Foundation PUBLIC
155155
swiftDispatch)
156+
156157
# TODO(compnerd) properly propogate `BUILD_RPATH` to the target using CMake
157158
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
158159
target_link_options(Foundation PRIVATE
@@ -167,6 +168,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
167168
pathcch)
168169
endif()
169170
set_target_properties(Foundation PROPERTIES
171+
INSTALL_RPATH "$ORIGIN"
170172
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
171173
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
172174

@@ -216,6 +218,7 @@ target_link_libraries(FoundationNetworking PRIVATE
216218
Foundation
217219
CFURLSessionInterface)
218220
set_target_properties(FoundationNetworking PROPERTIES
221+
INSTALL_RPATH "$ORIGIN"
219222
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
220223
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
221224

@@ -240,9 +243,11 @@ target_link_libraries(FoundationXML PRIVATE
240243
Foundation
241244
CFXMLInterface)
242245
set_target_properties(FoundationXML PROPERTIES
246+
INSTALL_RPATH "$ORIGIN"
243247
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
244248
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
245249

250+
246251
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
247252
Foundation FoundationNetworking FoundationXML)
248253
get_swift_host_arch(swift_arch)

Tools/plutil/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ add_executable(plutil
33
main.swift)
44
target_link_libraries(plutil PRIVATE
55
Foundation)
6-
# TODO(compnerd) properly propogate `BUILD_RPATH` to the target using CMake
7-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
8-
target_link_options(plutil PRIVATE
9-
"SHELL:-Xlinker -rpath -Xlinker $$$$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>:$<TARGET_FILE_DIR:Foundation>")
10-
endif()
6+
set_target_properties(plutil PROPERTIES
7+
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
118

129
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS plutil)
1310
install(TARGETS plutil

0 commit comments

Comments
 (0)