Skip to content

Commit 97a2f06

Browse files
authored
Merge pull request swiftlang#243 from compnerd/swiftDispatch
build: attempt to add swift support to cmake
2 parents 14d3d90 + 6add5cc commit 97a2f06

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

cmake/modules/SwiftSupport.cmake

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
include(CMakeParseArguments)
3+
4+
function(add_swift_library library)
5+
set(options)
6+
set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT)
7+
set(multiple_value_options SOURCES;SWIFT_FLAGS;CFLAGS)
8+
9+
cmake_parse_arguments(ASL "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN})
10+
11+
set(flags ${CMAKE_SWIFT_FLAGS})
12+
13+
list(APPEND flags -emit-library)
14+
15+
if(ASL_MODULE_NAME)
16+
list(APPEND flags -module-name;${ASL_MODULE_NAME})
17+
endif()
18+
if(ASL_MODULE_LINK_NAME)
19+
list(APPEND flags -module-link-name;${ASL_MODULE_LINK_NAME})
20+
endif()
21+
if(ASL_MODULE_PATH)
22+
list(APPEND flags -emit-module-path;${ASL_MODULE_PATH})
23+
endif()
24+
if(ASL_MODULE_CACHE_PATH)
25+
list(APPEND flags -module-cache-path;${ASL_MODULE_CACHE_PATH})
26+
endif()
27+
if(ASL_SWIFT_FLAGS)
28+
foreach(flag ${ASL_SWIFT_FLAGS})
29+
list(APPEND flags ${flag})
30+
endforeach()
31+
endif()
32+
if(ASL_CFLAGS)
33+
foreach(flag ${ASL_CFLAGS})
34+
list(APPEND flags -Xcc;${flag})
35+
endforeach()
36+
endif()
37+
38+
# FIXME: We shouldn't /have/ to build things in a single process.
39+
# <rdar://problem/15972329>
40+
list(APPEND flags -force-single-frontend-invocation)
41+
42+
set(sources)
43+
foreach(source ${ASL_SOURCES})
44+
get_filename_component(location ${source} PATH)
45+
if(IS_ABSOLUTE ${location})
46+
list(APPEND sources ${source})
47+
else()
48+
list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source})
49+
endif()
50+
endforeach()
51+
52+
get_filename_component(module_directory ${ASL_MODULE_PATH} DIRECTORY)
53+
54+
add_custom_command(OUTPUT
55+
${ASL_OUTPUT}
56+
${ASL_MODULE_PATH}
57+
${moodule_directory}/${ASL_MODULE_NAME}.swiftdoc
58+
DEPENDS
59+
${ASL_SOURCES}
60+
COMMAND
61+
${CMAKE_COMMAND} -E make_directory ${module_directory}
62+
COMMAND
63+
${CMAKE_SWIFT_COMPILER} ${flags} -c ${sources} -o ${ASL_OUTPUT})
64+
add_custom_target(${library}
65+
DEPENDS
66+
${ASL_OUTPUT}
67+
${ASL_MODULE_PATH}
68+
${moodule_directory}/${ASL_MODULE_NAME}.swiftdoc)
69+
endfunction()

src/CMakeLists.txt

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11

2+
include(SwiftSupport)
3+
24
set(dispatch_BLOCK_SOURCES block.cpp)
35
if(HAVE_OBJC)
46
list(APPEND dispatch_BLOCK_SOURCES data.m object.m)
57
endif()
8+
set(dispatch_SWIFT_SOURCES)
9+
if(CMAKE_SWIFT_COMPILER)
10+
set(swift_optimization_flags)
11+
if(CMAKE_BUILD_TYPE MATCHES Release)
12+
set(swift_optimization_flags -O)
13+
endif()
14+
add_swift_library(swiftDispatch
15+
MODULE_NAME
16+
Dispatch
17+
MODULE_LINK_NAME
18+
dispatch
19+
MODULE_PATH
20+
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
21+
OUTPUT
22+
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
23+
SOURCES
24+
swift/Block.swift
25+
swift/Data.swift
26+
swift/Dispatch.swift
27+
swift/IO.swift
28+
swift/Private.swift
29+
swift/Queue.swift
30+
swift/Source.swift
31+
swift/Time.swift
32+
swift/Wrapper.swift
33+
CFLAGS
34+
-fblocks
35+
-fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
36+
SWIFT_FLAGS
37+
-I ${CMAKE_SOURCE_DIR}
38+
${swift_optimization_flags})
39+
list(APPEND dispatch_SWIFT_SOURCES
40+
swift/DispatchStubs.cc;${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
41+
endif()
642
add_library(dispatch
743
allocator.c
844
apply.c
@@ -55,7 +91,8 @@ add_library(dispatch
5591
shims/time.h
5692
shims/tsd.h
5793
shims/yield.h
58-
${dispatch_BLOCK_SOURCES})
94+
${dispatch_BLOCK_SOURCES}
95+
${dispatch_SWIFT_SOURCES})
5996
target_include_directories(dispatch
6097
PRIVATE
6198
${CMAKE_BINARY_DIR}

0 commit comments

Comments
 (0)