@@ -72,25 +72,41 @@ target_sources(dispatch
7272 PRIVATE
7373 block.cpp)
7474if (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.
7578 target_sources (dispatch
7679 PRIVATE
7780 data.m
78- object.m)
81+ object.m
82+ swift/DispatchStubs.cc)
7983endif ()
8084if (ENABLE_SWIFT)
8185 set (swift_optimization_flags)
8286 if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
8387 set (swift_optimization_flags -O)
8488 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+
85103 add_swift_library(swiftDispatch
86104 MODULE_NAME
87105 Dispatch
88106 MODULE_LINK_NAME
89107 dispatch
90108 MODULE_PATH
91109 ${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftmodule
92- OUTPUT
93- ${CMAKE_CURRENT_BINARY_DIR} /swiftDispatch.o
94110 SOURCES
95111 swift/Block.swift
96112 swift/Data.swift
@@ -110,23 +126,14 @@ if(ENABLE_SWIFT)
110126 -I ${PROJECT_SOURCE_DIR}
111127 -I/usr/include
112128 ${swift_optimization_flags}
129+ LINK_FLAGS
130+ $<TARGET_OBJECTS:DispatchStubs>
113131 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)
130137endif ()
131138if (ENABLE_DTRACE)
132139 dtrace_usdt_probe(${CMAKE_CURRENT_SOURCE_DIR} /provider.d
@@ -231,8 +238,6 @@ add_custom_command(TARGET dispatch POST_BUILD
231238 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:dispatch> .libs
232239 COMMENT "Copying libdispatch to .libs" )
233240
234- get_swift_host_arch(SWIFT_HOST_ARCH)
235-
236241install (TARGETS
237242 dispatch
238243 DESTINATION
@@ -242,6 +247,18 @@ if(ENABLE_SWIFT)
242247 ${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftmodule
243248 ${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftdoc
244249 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} )
246263endif ()
247264
0 commit comments