Skip to content

Commit 16d6e06

Browse files
committed
build: use the same linker for the tests
We would previously not honor the linker settings for the tests. Adjust the build process to account for that.
1 parent 2706d53 commit 16d6e06

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include(CheckLibraryExists)
3030
include(CheckSymbolExists)
3131
include(GNUInstallDirs)
3232
include(SwiftSupport)
33+
include(DispatchUtilities)
3334

3435
set(SWIFT_LIBDIR "lib" CACHE PATH "Library folder name, defined by swift main buildscript")
3536
set(INSTALL_LIBDIR "${SWIFT_LIBDIR}" CACHE PATH "Path where the libraries should be installed")

cmake/modules/DispatchUtilties.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
function(dispatch_set_linker target)
3+
if(USE_GOLD_LINKER)
4+
set_property(TARGET ${target}
5+
APPEND_STRING
6+
PROPERTY LINK_FLAGS
7+
-fuse-ld=gold)
8+
endif()
9+
if(USE_LLD_LINKER)
10+
set_property(TARGET ${target}
11+
APPEND_STRING
12+
PROPERTY LINK_FLAGS
13+
-fuse-ld=lld)
14+
endif()
15+
endfunction()

src/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
212212
"-Xlinker -dead_strip"
213213
"-Xlinker -alias_list -Xlinker ${CMAKE_SOURCE_DIR}/xcodeconfig/libdispatch.aliases")
214214
endif()
215-
if(USE_GOLD_LINKER)
216-
set_property(TARGET dispatch
217-
APPEND_STRING
218-
PROPERTY LINK_FLAGS
219-
-fuse-ld=gold)
220-
endif()
221-
if(USE_LLD_LINKER)
222-
set_property(TARGET dispatch
223-
APPEND_STRING
224-
PROPERTY LINK_FLAGS
225-
-fuse-ld=lld)
226-
endif()
215+
dispatch_set_linker(dispatch)
227216

228217
# Temporary staging; the various swift projects that depend on libdispatch
229218
# all expect libdispatch.so to be in src/.libs/libdispatch.so

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ endif()
2323

2424
add_executable(bsdtestharness
2525
bsdtestharness.c)
26+
dispatch_set_linker(bsdtestharness)
2627
target_include_directories(bsdtestharness
2728
PRIVATE
2829
${CMAKE_CURRENT_BINARY_DIR}
@@ -84,6 +85,7 @@ function(add_unit_test name)
8485
target_compile_options(${name} PRIVATE -fblocks)
8586
# TODO(compnerd) make this portable
8687
target_compile_options(${name} PRIVATE -Wall -Wno-deprecated-declarations)
88+
dispatch_set_linker(${name})
8789
target_link_libraries(${name} PRIVATE dispatch Threads::Threads)
8890
if(WITH_BLOCKS_RUNTIME)
8991
target_link_libraries(${name} PRIVATE BlocksRuntime)

0 commit comments

Comments
 (0)