@@ -72,25 +72,41 @@ target_sources(dispatch
72
72
PRIVATE
73
73
block .cpp )
74
74
if (HAVE_OBJC )
75
+ # TODO(compnerd) split DispatchStubs.cc into a separate component for the ObjC
76
+ # registration and a separate component for the swift compiler's emission of a
77
+ # call to the ObjC autorelease elision entry point.
75
78
target_sources (dispatch
76
79
PRIVATE
77
80
data.m
78
- object.m )
81
+ object.m
82
+ swift/DispatchStubs.cc )
79
83
endif ()
80
84
if (ENABLE_SWIFT )
81
85
set (swift_optimization_flags )
82
86
if (NOT CMAKE_BUILD_TYPE MATCHES Debug )
83
87
set (swift_optimization_flags -O )
84
88
endif ()
89
+
90
+ # TODO(compnerd) fix the swift compiler to directly call the swift entry point
91
+ # if ObjC Interop is disabled to avoid having the stub for the ObjC
92
+ # autorelease elision entry point
93
+ add_library (DispatchStubs
94
+ OBJECT
95
+ swift/DispatchStubs.cc )
96
+ target_include_directories (DispatchStubs
97
+ PRIVATE
98
+ ${PROJECT_SOURCE_DIR} )
99
+ set_target_properties (DispatchStubs
100
+ PROPERTIES
101
+ POSITION_INDEPENDENT_CODE YES )
102
+
85
103
add_swift_library (swiftDispatch
86
104
MODULE_NAME
87
105
Dispatch
88
106
MODULE_LINK_NAME
89
107
dispatch
90
108
MODULE_PATH
91
109
${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftmodule
92
- OUTPUT
93
- ${CMAKE_CURRENT_BINARY_DIR} /swiftDispatch.o
94
110
SOURCES
95
111
swift/Block.swift
96
112
swift/Data.swift
@@ -110,23 +126,14 @@ if(ENABLE_SWIFT)
110
126
-I ${PROJECT_SOURCE_DIR}
111
127
-I/usr/include
112
128
${swift_optimization_flags}
129
+ LINK_FLAGS
130
+ $< TARGET_OBJECTS:DispatchStubs>
113
131
DEPENDS
114
- ${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
-
120
- target_sources (dispatch
121
- PRIVATE
122
- swift/DispatchStubs.cc
123
- ${CMAKE_CURRENT_BINARY_DIR} /swiftDispatch.o
124
- ${swift_runtime_libdir} /swiftrt.o )
125
- if (CMAKE_BUILD_TYPE MATCHES Debug )
126
- target_link_libraries (dispatch
127
- PRIVATE
128
- swiftSwiftOnoneSupport )
129
- endif ()
132
+ ${PROJECT_SOURCE_DIR} /dispatch/module.modulemap
133
+ module-map-symlinks
134
+ DispatchStubs
135
+ TARGET_FILES
136
+ swiftDispatch_TARGET_FILES )
130
137
endif ()
131
138
if (ENABLE_DTRACE )
132
139
dtrace_usdt_probe (${CMAKE_CURRENT_SOURCE_DIR} /provider.d
@@ -231,8 +238,6 @@ add_custom_command(TARGET dispatch POST_BUILD
231
238
COMMAND ${CMAKE_COMMAND} -E copy $< TARGET_FILE:dispatch> .libs
232
239
COMMENT "Copying libdispatch to .libs" )
233
240
234
- get_swift_host_arch (SWIFT_HOST_ARCH )
235
-
236
241
install (TARGETS
237
242
dispatch
238
243
DESTINATION
@@ -242,6 +247,18 @@ if(ENABLE_SWIFT)
242
247
${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftmodule
243
248
${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftdoc
244
249
DESTINATION
245
- "${INSTALL_TARGET_DIR} /${SWIFT_HOST_ARCH} " )
250
+ ${INSTALL_TARGET_DIR} /${swift_arch} )
251
+
252
+ if (BUILD_SHARED_LIBS )
253
+ set (library_kind SHARED )
254
+ else ()
255
+ set (library_kind STATIC )
256
+ endif ()
257
+ set (swiftDispatch_OUTPUT_FILE
258
+ ${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_${library_kind}_LIBRARY_PREFIX}swiftDispatch${CMAKE_${library_kind}_LIBRARY_SUFFIX} )
259
+ install (FILES
260
+ ${swiftDispatch_OUTPUT_FILE}
261
+ DESTINATION
262
+ ${INSTALL_TARGET_DIR} )
246
263
endif ()
247
264
0 commit comments