Skip to content

Commit 5e7281b

Browse files
authored
Allow disabling Dispatch and Networking in CMakeLists.txt (swiftlang#3029)
Dispatch and Networking aren't available for Wasm and WASI. We should make these parts configurable to make it possible to turn them off when building for that platform.
1 parent 7d93003 commit 5e7281b

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

CMakeLists.txt

+27-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3838
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
3939

4040
option(BUILD_SHARED_LIBS "build shared libraries" ON)
41+
option(HAS_LIBDISPATCH_API "has libdispatch API" ON)
42+
option(BUILD_NETWORKING "build FoundationNetworking module" ON)
43+
option(BUILD_TOOLS "build tools" ON)
4144
option(NS_CURL_ASSUME_FEATURES_MISSING "Assume that optional libcurl features are missing rather than test the library's version, for build debugging" NO)
4245

43-
find_package(dispatch CONFIG REQUIRED)
46+
if(HAS_LIBDISPATCH_API)
47+
find_package(dispatch CONFIG REQUIRED)
48+
endif()
4449

4550
include(SwiftSupport)
4651
include(GNUInstallDirs)
@@ -53,6 +58,12 @@ set(BUILD_SHARED_LIBS NO)
5358
add_subdirectory(CoreFoundation EXCLUDE_FROM_ALL)
5459
set(BUILD_SHARED_LIBS ${SAVED_BUILD_SHARED_LIBS})
5560

61+
# BlocksRuntime is already in libdispatch so it is only needed if libdispatch is
62+
# NOT being used
63+
if(NOT HAS_LIBDISPATCH_API)
64+
add_subdirectory(Sources/BlocksRuntime)
65+
endif()
66+
5667
# Setup include paths for uuid/uuid.h
5768
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h
5869
COMMAND
@@ -74,9 +85,22 @@ endif()
7485

7586
if(NOT BUILD_SHARED_LIBS)
7687
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
77-
CoreFoundation CFXMLInterface CFURLSessionInterface)
78-
install(TARGETS CoreFoundation CFXMLInterface CFURLSessionInterface
88+
CoreFoundation CFXMLInterface)
89+
90+
if(NOT HAS_LIBDISPATCH_API)
91+
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
92+
BlocksRuntime)
93+
endif()
94+
95+
install(TARGETS CoreFoundation CFXMLInterface
7996
DESTINATION lib/swift_static/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
97+
98+
if(BUILD_NETWORKING)
99+
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
100+
CFURLSessionInterface)
101+
install(TARGETS CFURLSessionInterface
102+
DESTINATION lib/swift_static/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
103+
endif()
80104
endif()
81105

82106
set(swift_lib_dir "lib/swift")

0 commit comments

Comments
 (0)