Skip to content

Commit fb57af4

Browse files
authored
Merge pull request swiftlang#29453 from compnerd/outsourcing
build: delegate rpath handling to CMake
2 parents 407b6c4 + 729ad36 commit fb57af4

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,12 +2583,6 @@ function(_add_swift_executable_single name)
25832583
LINK_LIBRARIES_VAR_NAME link_libraries
25842584
LIBRARY_SEARCH_DIRECTORIES_VAR_NAME library_search_directories)
25852585

2586-
if(${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
2587-
list(APPEND link_flags
2588-
"-Xlinker" "-rpath"
2589-
"-Xlinker" "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
2590-
endif()
2591-
25922586
_list_add_string_suffix(
25932587
"${SWIFTEXE_SINGLE_LINK_LIBRARIES}"
25942588
"-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE}"
@@ -2637,6 +2631,11 @@ function(_add_swift_executable_single name)
26372631
if (SWIFT_PARALLEL_LINK_JOBS)
26382632
set_property(TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool)
26392633
endif()
2634+
if(${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
2635+
set_target_properties(${name} PROPERTIES
2636+
BUILD_WITH_INSTALL_RPATH YES
2637+
INSTALL_RPATH "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
2638+
endif()
26402639
set_output_directory(${name}
26412640
BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
26422641
LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR})

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function(add_swift_unittest test_dirname)
4040
endif()
4141

4242
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
43-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
44-
LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx")
43+
set_target_properties(${test_dirname} PROPERTIES
44+
BUILD_RPATH ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx)
4545
elseif("${SWIFT_HOST_VARIANT}" STREQUAL "android")
4646
swift_android_lib_for_arch(${SWIFT_HOST_VARIANT_ARCH} android_system_libs)
4747
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_DIRECTORIES

tools/swift-syntax-parser-test/CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ target_link_libraries(swift-syntax-parser-test
1515
libSwiftSyntaxParser
1616
)
1717

18-
if(APPLE)
19-
# Prioritize finding the parser library from the build/lib directory.
20-
# Otherwise it may find it from the 'lib/swift/macosx' directory which could
21-
# be out-of-date.
22-
get_target_property(link_flags swift-syntax-parser-test LINK_FLAGS)
23-
set(link_flags "-Xlinker -rpath -Xlinker @executable_path/../lib ${link_flags}")
24-
set_property(TARGET swift-syntax-parser-test PROPERTY
25-
LINK_FLAGS "${link_flags}")
18+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
19+
set_target_properties(swift-syntax-parser-test PROPERTIES
20+
BUILD_WITH_INSTALL_RPATH YES
21+
INSTALL_RPATH @executable_path/../lib)
2622
endif()
2723

2824
set_property(TARGET swift-syntax-parser-test APPEND_STRING PROPERTY

unittests/SyntaxParser/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ target_link_libraries(SwiftSyntaxParserTests
1212
PRIVATE
1313
libSwiftSyntaxParser)
1414

15-
if(APPLE)
16-
# Prioritize finding the parser library from the build/lib directory.
17-
# Otherwise it may find it from the 'lib/swift/macosx' directory which could
18-
# be out-of-date.
19-
get_target_property(link_flags SwiftSyntaxParserTests LINK_FLAGS)
20-
set(link_flags "-Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR} ${link_flags}")
21-
set_property(TARGET SwiftSyntaxParserTests PROPERTY
22-
LINK_FLAGS "${link_flags}")
15+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
16+
set_target_properties(SwiftSyntaxParserTests PROPERTIES
17+
BUILD_RPATH ${SWIFT_LIBRARY_OUTPUT_INTDIR})
2318
endif()
2419

2520
set_property(TARGET SwiftSyntaxParserTests APPEND_STRING PROPERTY

0 commit comments

Comments
 (0)