Skip to content

Commit ffcfbcc

Browse files
committed
build: honour and use RPATHs
RPATH handling in CMake 3.15 was unsupported on Swift targets. Adjust the configuration to support it on CMake <3.16 and use that to set the install RPATH to $ORIGIN rather than the workaround for the build RPATH.
1 parent accfc8f commit ffcfbcc

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
@@ -149,6 +149,7 @@ target_link_libraries(Foundation PRIVATE
149149
uuid)
150150
target_link_libraries(Foundation PUBLIC
151151
swiftDispatch)
152+
152153
# TODO(compnerd) properly propogate `BUILD_RPATH` to the target using CMake
153154
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
154155
target_link_options(Foundation PRIVATE
@@ -163,6 +164,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
163164
pathcch)
164165
endif()
165166
set_target_properties(Foundation PROPERTIES
167+
INSTALL_RPATH "$ORIGIN"
166168
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
167169
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
168170

@@ -212,6 +214,7 @@ target_link_libraries(FoundationNetworking PRIVATE
212214
Foundation
213215
CFURLSessionInterface)
214216
set_target_properties(FoundationNetworking PROPERTIES
217+
INSTALL_RPATH "$ORIGIN"
215218
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
216219
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
217220

@@ -236,9 +239,11 @@ target_link_libraries(FoundationXML PRIVATE
236239
Foundation
237240
CFXMLInterface)
238241
set_target_properties(FoundationXML PROPERTIES
242+
INSTALL_RPATH "$ORIGIN"
239243
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
240244
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
241245

246+
242247
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
243248
Foundation FoundationNetworking FoundationXML)
244249
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)