Skip to content

Commit aae4197

Browse files
committed
build: avoid rpath, library search path handling
Create an imported library target for the runtime libraries rather than add the explicit library search path handling. This avoids the need for the rpath in the tests, and allows cmake to properly model dependencies. It also makes the build system more amenable to cross-compiling/cross-linking by avoiding ELF linker specific options.
1 parent 23a3a84 commit aae4197

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

tests/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_SOURCE_DIR}/private" "${CMAKE_CURRENT_BINARY_DIR}/dispatch")
33
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/leaks-wrapper.sh" "${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper")
44

5+
# TODO(compnerd) hoist this out of the test directory
6+
if(SWIFT_RUNTIME_LIBDIR)
7+
add_library(swiftCore SHARED IMPORTED)
8+
set_target_properties(swiftCore
9+
PROPERTIES
10+
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
11+
12+
add_library(swiftSwiftOnoneSupport SHARED IMPORTED)
13+
set_target_properties(swiftSwiftOnoneSupport
14+
PROPERTIES
15+
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
16+
endif()
17+
518
add_library(bsdtests
619
STATIC
720
bsdtests.c
@@ -38,12 +51,11 @@ if(BSD_OVERLAY_FOUND)
3851
PRIVATE
3952
${BSD_OVERLAY_LDFLAGS})
4053
endif()
41-
42-
if(CMAKE_SWIFT_RUNTIME_LIBDIR)
54+
if(ENABLE_SWIFT)
4355
target_link_libraries(bsdtestharness
4456
PRIVATE
45-
-L${CMAKE_SWIFT_RUNTIME_LIBDIR} -lswiftCore -lswiftSwiftOnoneSupport
46-
-Wl,-rpath -Wl,${CMAKE_SWIFT_RUNTIME_LIBDIR})
57+
swiftCore
58+
swiftSwiftOnoneSupport)
4759
endif()
4860

4961
function(add_unit_test name)
@@ -84,11 +96,11 @@ function(add_unit_test name)
8496
PRIVATE
8597
${BSD_OVERLAY_LDFLAGS})
8698
endif()
87-
if(CMAKE_SWIFT_RUNTIME_LIBDIR)
99+
if(ENABLE_SWIFT)
88100
target_link_libraries(${name}
89101
PRIVATE
90-
-L${CMAKE_SWIFT_RUNTIME_LIBDIR} -lswiftCore -lswiftSwiftOnoneSupport
91-
-Wl,-rpath -Wl,${CMAKE_SWIFT_RUNTIME_LIBDIR})
102+
swiftCore
103+
swiftSwiftOnoneSupport)
92104
endif()
93105
target_link_libraries(${name} PRIVATE bsdtests)
94106
add_test(NAME ${name}

0 commit comments

Comments
 (0)