Skip to content

Commit df97651

Browse files
compnerdktopley-apple
authored andcommitted
build: improve swift build/integration
Add explicit links against the swift runtime for the tests which may use the swift runtime. This prevents link failures for the swift tests. Install the swiftmodule and swiftdoc into the installed image. Correct the modulemap installation. Fix a typo in the header installation. Signed-off-by: Daniel A. Steffen <[email protected]>
1 parent 6165862 commit df97651

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,32 @@ dispatch_common_warnings()
3333
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
3434
set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
3535

36-
# TODO(compnerd) swift options
36+
option(ENABLE_SWIFT "enable libdispatch swift overlay" OFF)
37+
if(ENABLE_SWIFT)
38+
if(NOT CMAKE_SWIFT_COMPILER)
39+
message(FATAL_ERROR "CMAKE_SWIFT_COMPILER must be defined to enable swift")
40+
endif()
41+
42+
get_filename_component(SWIFT_TOOLCHAIN ${CMAKE_SWIFT_COMPILER} DIRECTORY)
43+
get_filename_component(SWIFT_TOOLCHAIN ${SWIFT_TOOLCHAIN} DIRECTORY)
44+
45+
string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
46+
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/lib/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR})
47+
48+
add_library(swiftCore
49+
SHARED IMPORTED GLOBAL)
50+
set_target_properties(swiftCore
51+
PROPERTIES
52+
IMPORTED_LOCATION
53+
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
54+
55+
add_library(swiftSwiftOnoneSupport
56+
SHARED IMPORTED GLOBAL)
57+
set_target_properties(swiftSwiftOnoneSupport
58+
PROPERTIES
59+
IMPORTED_LOCATION
60+
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
61+
endif()
3762

3863
option(BUILD_SHARED_LIBS "build shared libraries" ON)
3964

dispatch/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ install(FILES
1414
source.h
1515
time.h
1616
DESTINATION
17-
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch/)
17+
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
1818
if(ENABLE_SWIFT)
19+
get_filename_component(MODULE_MAP module.modulemap REALPATH)
1920
install(FILES
20-
module.modulemap
21+
${MODULE_MAP}
2122
DESTINATION
22-
${CMAKE_INSTALL_FULL_INCLUEDIR}/dispatch/)
23+
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
2324
endif()
2425

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if(HAVE_OBJC)
6969
data.m
7070
object.m)
7171
endif()
72-
if(CMAKE_SWIFT_COMPILER)
72+
if(ENABLE_SWIFT)
7373
set(swift_optimization_flags)
7474
if(CMAKE_BUILD_TYPE MATCHES Release)
7575
set(swift_optimization_flags -O)
@@ -203,4 +203,11 @@ install(TARGETS
203203
dispatch
204204
DESTINATION
205205
"${CMAKE_INSTALL_FULL_LIBDIR}")
206+
if(ENABLE_SWIFT)
207+
install(FILES
208+
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
209+
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
210+
DESTINATION
211+
"${CMAKE_INSTALL_FULL_LIBDIR}/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR}")
212+
endif()
206213

0 commit comments

Comments
 (0)