Skip to content

Commit 42e6931

Browse files
compnerdrokhinip
authored andcommitted
build: use the exported target instead of reconstructing paths
Use the exported target from swift rather than recreate the paths locally. This almost works to replace the use of the paths. Unfortunately, swiftrt is not currently exported. Signed-off-by: Kim Topley <[email protected]>
1 parent 8cefcf3 commit 42e6931

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

CMakeLists.txt

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,32 @@ dispatch_common_warnings()
4444
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
4545
set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
4646

47+
# NOTE(abdulras) this is the CMake supported way to control whether we generate
48+
# shared or static libraries. This impacts the behaviour of `add_library` in
49+
# what type of library it generates.
50+
option(BUILD_SHARED_LIBS "build shared libraries" ON)
51+
4752
option(ENABLE_SWIFT "enable libdispatch swift overlay" OFF)
4853
if(ENABLE_SWIFT)
4954
if(NOT CMAKE_SWIFT_COMPILER)
5055
message(FATAL_ERROR "CMAKE_SWIFT_COMPILER must be defined to enable swift")
5156
endif()
5257

53-
get_filename_component(SWIFT_TOOLCHAIN ${CMAKE_SWIFT_COMPILER} DIRECTORY)
54-
get_filename_component(SWIFT_TOOLCHAIN ${SWIFT_TOOLCHAIN} DIRECTORY)
55-
56-
string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
57-
get_swift_host_arch(SWIFT_HOST_ARCH)
58+
find_package(Swift REQUIRED CONFIG)
5859

59-
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/${SWIFT_LIBDIR}/swift/${SWIFT_OS}/${SWIFT_HOST_ARCH})
60-
61-
add_library(swiftCore
62-
SHARED IMPORTED GLOBAL)
63-
set_target_properties(swiftCore
64-
PROPERTIES
65-
IMPORTED_LOCATION
66-
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
60+
string(TOLOWER ${CMAKE_SYSTEM_NAME} swift_os)
61+
get_swift_host_arch(swift_arch)
6762

68-
add_library(swiftSwiftOnoneSupport
69-
SHARED IMPORTED GLOBAL)
70-
set_target_properties(swiftSwiftOnoneSupport
71-
PROPERTIES
72-
IMPORTED_LOCATION
73-
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
63+
if(BUILD_SHARED_LIBS)
64+
set(swift_dir swift)
65+
else()
66+
set(swift_dir swift_static)
67+
endif()
7468

75-
set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/swift/${SWIFT_OS}" CACHE PATH "Path where the libraries will be installed")
76-
set(INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR}/swift/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
77-
set(INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR}/swift/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
78-
set(INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR}/swift/os" CACHE PATH "Path where the os/ headers will be installed")
69+
set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/${swift_dir}/${swift_os}" CACHE PATH "Path where the libraries will be installed")
70+
set(INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR}/${swift_dir}/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
71+
set(INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR}/${swift_dir}/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
72+
set(INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR}/${swift_dir}/os" CACHE PATH "Path where the os/ headers will be installed")
7973
endif()
8074

8175
if(NOT ENABLE_SWIFT)
@@ -87,11 +81,6 @@ endif()
8781

8882
option(ENABLE_DTRACE "enable dtrace support" "")
8983

90-
# NOTE(abdulras) this is the CMake supported way to control whether we generate
91-
# shared or static libraries. This impacts the behaviour of `add_library` in
92-
# what type of library it generates.
93-
option(BUILD_SHARED_LIBS "build shared libraries" ON)
94-
9584
option(ENABLE_TESTING "build libdispatch tests" ON)
9685

9786
option(USE_LLD_LINKER "use the lld linker" FALSE)

src/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,16 @@ if(ENABLE_SWIFT)
112112
${swift_optimization_flags}
113113
DEPENDS
114114
${PROJECT_SOURCE_DIR}/dispatch/module.modulemap)
115+
116+
get_filename_component(swift_toolchain ${CMAKE_SWIFT_COMPILER} DIRECTORY)
117+
get_filename_component(swift_toolchain ${swift_toolchain} DIRECTORY)
118+
set(swift_runtime_libdir ${swift_toolchain}/lib/${swift_dir}/${swift_os}/${swift_arch})
119+
115120
target_sources(dispatch
116121
PRIVATE
117122
swift/DispatchStubs.cc
118123
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
119-
${SWIFT_RUNTIME_LIBDIR}/swiftrt.o)
124+
${swift_runtime_libdir}/swiftrt.o)
120125
if(CMAKE_BUILD_TYPE MATCHES Debug)
121126
target_link_libraries(dispatch
122127
PRIVATE

0 commit comments

Comments
 (0)