Skip to content

Commit dd38a58

Browse files
committed
Introduce Cmake support for SwiftFoundation
1 parent 63be4bd commit dd38a58

File tree

36 files changed

+1036
-7
lines changed

36 files changed

+1036
-7
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/apple/swift-foundation-icu.git
56+
GIT_TAG 0.0.8)
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)

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let package = Package(
5656
from: "1.1.0"),
5757
.package(
5858
url: "https://github.com/apple/swift-foundation-icu",
59-
exact: "0.0.7"),
59+
exact: "0.0.8"),
6060
.package(
6161
url: "https://github.com/apple/swift-syntax.git",
6262
from: "510.0.0")

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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
target_sources(FoundationEssentials PRIVATE
15+
AttributeContainer.swift
16+
AttributeScope.swift
17+
AttributedString+AttributeTransformation.swift
18+
AttributedString+CharacterView.swift
19+
AttributedString+Guts.swift
20+
AttributedString+Runs+AttributeSlices.swift
21+
AttributedString+Runs+Run.swift
22+
AttributedString+Runs.swift
23+
AttributedString+UnicodeScalarView.swift
24+
AttributedString+_InternalRun.swift
25+
AttributedString+_InternalRuns.swift
26+
AttributedString+_InternalRunsSlice.swift
27+
AttributedString.swift
28+
AttributedStringAttribute.swift
29+
AttributedStringAttributeConstrainingBehavior.swift
30+
AttributedStringAttributeStorage.swift
31+
AttributedStringCodable.swift
32+
AttributedStringProtocol.swift
33+
AttributedSubstring.swift
34+
Collection\ Stdlib\ Defaults.swift
35+
Conversion.swift
36+
FoundationAttributes.swift
37+
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+
FoundationEssentials.swift
25+
IndexPath.swift
26+
LockedState.swift
27+
Logging.swift
28+
OutputBuffer.swift
29+
Platform.swift
30+
SortComparator.swift
31+
UUID_Wrappers.swift
32+
UUID.swift
33+
WinSDK+Extensions.swift)
34+
35+
add_subdirectory(AttributedString)
36+
add_subdirectory(Calendar)
37+
add_subdirectory(Data)
38+
add_subdirectory(Decimal)
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: 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_sources(FoundationEssentials PRIVATE
16+
Calendar.swift
17+
Calendar_Autoupdating.swift
18+
Calendar_Cache.swift
19+
Calendar_Enumerate.swift
20+
Calendar_Gregorian.swift
21+
Calendar_Protocol.swift
22+
Calendar_Recurrence.swift
23+
Date+FormatStyle.swift
24+
Date+Locale.swift
25+
DateComponents.swift
26+
RecurrenceRule.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_sources(FoundationEssentials PRIVATE
16+
Collections+DataProtocol.swift
17+
ContiguousBytes.swift
18+
Data+Base64.swift
19+
Data+Error.swift
20+
Data+Reading.swift
21+
Data+Stub.swift
22+
Data+Writing.swift
23+
Data.swift
24+
DataProtocol.swift
25+
Pointers+DataProtocol.swift)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
target_sources(FoundationEssentials PRIVATE
15+
Decimal.swift
16+
Decimal+Conformances.swift)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
target_sources(FoundationEssentials PRIVATE
15+
CocoaError+FilePath.swift
16+
CocoaError.swift
17+
ErrorCodes+POSIX.swift
18+
ErrorCodes+Win32.swift
19+
ErrorCodes.swift)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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_sources(FoundationEssentials PRIVATE
16+
SearchPaths/FileManager+DarwinSearchPaths.swift
17+
SearchPaths/FileManager+SearchPaths.swift
18+
SearchPaths/FileManager+WindowsSearchPaths.swift
19+
SearchPaths/FileManager+XDGSearchPaths.swift
20+
21+
FileManager+Basics.swift
22+
FileManager+Bridge.swift
23+
FileManager+Directories.swift
24+
FileManager+Files.swift
25+
FileManager+SymbolicLinks.swift
26+
FileManager+Utilities.swift
27+
FileOperations+Enumeration.swift
28+
FileOperations.swift
29+
SwiftFileManager.swift
30+
SwiftFileManagerDelegate.swift)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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_sources(FoundationEssentials PRIVATE
16+
BinaryInteger+NumericStringRepresentation.swift
17+
Date+ISO8601FormatStyle.swift
18+
DiscreteFormatStyle.swift
19+
FormatParsingUtilities.swift
20+
FormatStyle.swift
21+
FormatterCache.swift
22+
ParseStrategy.swift
23+
ParseableFormatStyle.swift)

0 commit comments

Comments
 (0)