Skip to content

Commit 9b51995

Browse files
committed
Introduce Cmake support for SwiftFoundation
1 parent da923d1 commit 9b51995

34 files changed

+1035
-6
lines changed

CMakeLists.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
cmake_minimum_required(VERSION 3.24)
16+
17+
if(POLICY CMP0156)
18+
# Deduplicate linked libraries where appropriate
19+
cmake_policy(SET CMP0156 NEW)
20+
endif()
21+
22+
if(POLICY CMP0157)
23+
# New Swift build model: improved incremental build performance and LSP support
24+
cmake_policy(SET CMP0157 NEW)
25+
endif()
26+
27+
project(SwiftFoundation
28+
LANGUAGES C Swift)
29+
30+
if(NOT SWIFT_SYSTEM_NAME)
31+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
32+
set(SWIFT_SYSTEM_NAME macosx)
33+
else()
34+
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
35+
endif()
36+
endif()
37+
38+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
39+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
40+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
41+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
42+
43+
set(BUILD_TESTING NO)
44+
45+
set(COLLECTIONS_SINGLE_MODULE YES)
46+
set(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE YES)
47+
48+
# Make sure our dependencies exists
49+
include(FetchContent)
50+
if (_SwiftFoundationICU_SourceDIR)
51+
FetchContent_Declare(SwiftFoundationICU
52+
SOURCE_DIR ${_SwiftFoundationICU_SourceDIR})
53+
else()
54+
FetchContent_Declare(SwiftFoundationICU
55+
GIT_REPOSITORY https://github.com/iCharlesHu/swift-foundation-icu.git
56+
GIT_TAG charles/cmake-support)
57+
endif()
58+
FetchContent_MakeAvailable(SwiftFoundationICU)
59+
60+
if (_SwiftCollections_SourceDIR)
61+
FetchContent_Declare(SwiftCollections
62+
SOURCE_DIR ${_SwiftCollections_SourceDIR})
63+
else()
64+
FetchContent_Declare(SwiftCollections
65+
GIT_REPOSITORY https://github.com/apple/swift-collections.git
66+
GIT_TAG release/1.1)
67+
endif()
68+
FetchContent_MakeAvailable(SwiftCollections)
69+
70+
# Availability Macros (only applies to FoundationEssentials and FoundationInternationalization)
71+
set(_SwiftFoundation_availability_macros)
72+
list(APPEND _SwiftFoundation_availability_macros
73+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPreview 0.1:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4\">"
74+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPreview 0.2:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4\">"
75+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPreview 0.3:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4\">"
76+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPreview 0.4:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4\">"
77+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.1:macOS 14, iOS 17, tvOS 17, watchOS 10\">"
78+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.2:macOS 14, iOS 17, tvOS 17, watchOS 10\">"
79+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.3:macOS 14, iOS 17, tvOS 17, watchOS 10\">"
80+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.4:macOS 14, iOS 17, tvOS 17, watchOS 10\">"
81+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.1:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">"
82+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.2:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">"
83+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.3:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">"
84+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.4:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">")
85+
86+
include(SwiftSupport)
87+
88+
add_subdirectory(Sources)
89+
add_subdirectory(cmake/modules)

Sources/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
add_subdirectory(_CShims)
16+
add_subdirectory(FoundationMacros)
17+
add_subdirectory(FoundationEssentials)
18+
add_subdirectory(FoundationInternationalization)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
AttributeContainer.swift
18+
AttributeScope.swift
19+
AttributedString+AttributeTransformation.swift
20+
AttributedString+CharacterView.swift
21+
AttributedString+Guts.swift
22+
AttributedString+Runs+AttributeSlices.swift
23+
AttributedString+Runs+Run.swift
24+
AttributedString+Runs.swift
25+
AttributedString+UnicodeScalarView.swift
26+
AttributedString+_InternalRun.swift
27+
AttributedString+_InternalRuns.swift
28+
AttributedString+_InternalRunsSlice.swift
29+
AttributedString.swift
30+
AttributedStringAttribute.swift
31+
AttributedStringAttributeConstrainingBehavior.swift
32+
AttributedStringAttributeStorage.swift
33+
AttributedStringCodable.swift
34+
AttributedStringProtocol.swift
35+
AttributedSubstring.swift
36+
Collection\ Stdlib\ Defaults.swift
37+
Conversion.swift
38+
FoundationAttributes.swift
39+
String.Index+ABI.swift)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
add_library(FoundationEssentials
16+
_ThreadLocal.swift
17+
Bundle+Stub.swift
18+
Codable.swift
19+
CodableUtilities.swift
20+
CodableWithConfiguration.swift
21+
ComparisonResult.swift
22+
Date.swift
23+
DateInterval.swift
24+
Decimal+Stub.swift
25+
FoundationEssentials.swift
26+
IndexPath.swift
27+
LockedState.swift
28+
Logging.swift
29+
OutputBuffer.swift
30+
Platform.swift
31+
SortComparator.swift
32+
UUID_Wrappers.swift
33+
UUID.swift
34+
WinSDK+Extensions.swift)
35+
36+
add_subdirectory(AttributedString)
37+
add_subdirectory(Calendar)
38+
add_subdirectory(Data)
39+
add_subdirectory(Error)
40+
add_subdirectory(FileManager)
41+
add_subdirectory(Formatting)
42+
add_subdirectory(JSON)
43+
add_subdirectory(Locale)
44+
add_subdirectory(Predicate)
45+
add_subdirectory(ProcessInfo)
46+
add_subdirectory(PropertyList)
47+
add_subdirectory(String)
48+
add_subdirectory(TimeZone)
49+
add_subdirectory(URL)
50+
51+
# Depend on FoundationMacros
52+
add_dependencies(FoundationEssentials FoundationMacros)
53+
target_compile_options(FoundationEssentials PRIVATE -plugin-path ${CMAKE_BINARY_DIR}/lib)
54+
55+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android)
56+
target_compile_options(FoundationEssentials PRIVATE
57+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -Xcc -Xfrontend -D_GNU_SOURCE>")
58+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
59+
endif()
60+
61+
target_compile_options(FoundationEssentials PRIVATE
62+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend VariadicGenerics>"
63+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>"
64+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
65+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InferSendableFromCaptures>")
66+
target_compile_options(FoundationEssentials PRIVATE ${_SwiftFoundation_availability_macros})
67+
target_compile_options(FoundationEssentials PRIVATE -package-name "SwiftFoundation")
68+
69+
target_link_libraries(FoundationEssentials PUBLIC
70+
_CShims
71+
_FoundationCollections)
72+
73+
set_target_properties(FoundationEssentials PROPERTIES
74+
INSTALL_RPATH "$ORIGIN")
75+
76+
set_property(GLOBAL APPEND PROPERTY SWIFT_FOUNDATION_EXPORTS FoundationEssentials)
77+
_install_target(FoundationEssentials)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
Calendar.swift
18+
Calendar_Autoupdating.swift
19+
Calendar_Cache.swift
20+
Calendar_Enumerate.swift
21+
Calendar_Gregorian.swift
22+
Calendar_Protocol.swift
23+
Calendar_Recurrence.swift
24+
Date+FormatStyle.swift
25+
Date+Locale.swift
26+
DateComponents.swift
27+
RecurrenceRule.swift)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
Collections+DataProtocol.swift
18+
ContiguousBytes.swift
19+
Data+Base64.swift
20+
Data+Error.swift
21+
Data+Reading.swift
22+
Data+Stub.swift
23+
Data+Writing.swift
24+
Data.swift
25+
DataProtocol.swift
26+
Pointers+DataProtocol.swift)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
CocoaError+FilePath.swift
18+
CocoaError.swift
19+
ErrorCodes+POSIX.swift
20+
ErrorCodes+Win32.swift
21+
ErrorCodes.swift)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
SearchPaths/FileManager+DarwinSearchPaths.swift
18+
SearchPaths/FileManager+SearchPaths.swift
19+
SearchPaths/FileManager+WindowsSearchPaths.swift
20+
SearchPaths/FileManager+XDGSearchPaths.swift
21+
22+
FileManager+Basics.swift
23+
FileManager+Bridge.swift
24+
FileManager+Directories.swift
25+
FileManager+Files.swift
26+
FileManager+SymbolicLinks.swift
27+
FileManager+Utilities.swift
28+
FileOperations+Enumeration.swift
29+
FileOperations.swift
30+
SwiftFileManager.swift
31+
SwiftFileManagerDelegate.swift)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
BinaryInteger+NumericStringRepresentation.swift
18+
Date+ISO8601FormatStyle.swift
19+
DiscreteFormatStyle.swift
20+
FormatParsingUtilities.swift
21+
FormatStyle.swift
22+
FormatterCache.swift
23+
ParseStrategy.swift
24+
ParseableFormatStyle.swift)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
target_include_directories(FoundationEssentials PRIVATE .)
16+
target_sources(FoundationEssentials PRIVATE
17+
BufferView.swift
18+
BufferViewCompatibility.swift
19+
BufferViewIndex.swift
20+
BufferViewIterator.swift
21+
JSON5Scanner.swift
22+
JSONDecoder.swift
23+
JSONEncoder.swift
24+
JSONScanner.swift
25+
JSONWriter.swift)

0 commit comments

Comments
 (0)