Skip to content

Commit b445a05

Browse files
committed
Initial CMake Build
Adding an initial CMake build for the Swift-subprocess library. At this time, it will build its own swift-system library, although we should allow it to search for one if one is available. CMake does not automatically generate modulemaps like SwiftPM does. As a result, we need to add one for Swift to import the C shims. There is one library target emitted from this build, Subprocess.
1 parent 5e5dcc1 commit b445a05

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.29)
2+
project(Subprocess LANGUAGES C Swift)
3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
4+
5+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name ${PROJECT_NAME}>")
6+
7+
include(InstallExternalDependencies)
8+
9+
add_subdirectory(Sources)

Sources/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_library(Subprocess)
2+
3+
add_subdirectory(_SubprocessCShims)
4+
add_subdirectory(Subprocess)
5+
6+
target_compile_options(Subprocess PRIVATE
7+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StrictConcurrency>"
8+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTyeps>"
9+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
10+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Span>")
11+
12+
target_link_libraries(Subprocess PRIVATE SystemPackage)

Sources/Subprocess/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
target_sources(Subprocess PRIVATE
2+
Execution.swift
3+
Buffer.swift
4+
Error.swift
5+
Teardown.swift
6+
Result.swift
7+
IO/Output.swift
8+
IO/Input.swift
9+
Span+Subprocess.swift
10+
AsyncBufferSequence.swift
11+
API.swift
12+
SubprocessFoundation/Span+SubprocessFoundation.swift
13+
SubprocessFoundation/Output+Foundation.swift
14+
SubprocessFoundation/Input+Foundation.swift
15+
Configuration.swift)
16+
17+
if(WIN32)
18+
target_sources(Subprocess PRIVATE Platforms/Subprocess+Windows.swift)
19+
elseif(LINUX OR ANDROID)
20+
target_sources(Subprocess PRIVATE
21+
Platforms/Subprocess+Linux.swift
22+
Platforms/Subprocess+Unix.swift)
23+
elseif(APPLE)
24+
target_sources(Subprocess PRIVATE
25+
Platforms/Subprocess+Darwin.swift
26+
Platforms/Subprocess+Unix.swift)
27+
endif()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target_sources(Subprocess PRIVATE process_shims.c)
2+
3+
target_include_directories(Subprocess PRIVATE
4+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module _SubprocessCShims {
2+
header "process_shims.h"
3+
header "target_conditionals.h"
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include_guard()
2+
3+
# TODO: Use find_package to find a pre-built SwiftSystem
4+
5+
include(FetchContent)
6+
7+
FetchContent_Declare(SwiftSystem
8+
GIT_REPOSITORY https://github.com/apple/swift-system.git
9+
GIT_TAG a34201439c74b53f0fd71ef11741af7e7caf01e1 # 1.4.2
10+
GIT_SHALLOW YES)
11+
list(APPEND dependencies SwiftSystem)
12+
13+
14+
if(dependencies)
15+
FetchContent_MakeAvailable(${dependencies})
16+
endif()

0 commit comments

Comments
 (0)