-
Notifications
You must be signed in to change notification settings - Fork 188
Introduce Cmake support for SwiftFoundation #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
cmake_minimum_required(VERSION 3.24) | ||
|
||
if(POLICY CMP0156) | ||
# Deduplicate linked libraries where appropriate | ||
cmake_policy(SET CMP0156 NEW) | ||
endif() | ||
|
||
if(POLICY CMP0157) | ||
# New Swift build model: improved incremental build performance and LSP support | ||
cmake_policy(SET CMP0157 NEW) | ||
endif() | ||
|
||
project(SwiftFoundation | ||
LANGUAGES C Swift) | ||
|
||
if(NOT SWIFT_SYSTEM_NAME) | ||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
set(SWIFT_SYSTEM_NAME macosx) | ||
else() | ||
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>") | ||
endif() | ||
endif() | ||
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) | ||
|
||
set(BUILD_TESTING NO) | ||
|
||
set(COLLECTIONS_SINGLE_MODULE YES) | ||
set(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE YES) | ||
|
||
# Make sure our dependencies exists | ||
include(FetchContent) | ||
if (_SwiftFoundationICU_SourceDIR) | ||
FetchContent_Declare(SwiftFoundationICU | ||
SOURCE_DIR ${_SwiftFoundationICU_SourceDIR}) | ||
else() | ||
FetchContent_Declare(SwiftFoundationICU | ||
GIT_REPOSITORY https://github.com/apple/swift-foundation-icu.git | ||
GIT_TAG 0.0.8) | ||
endif() | ||
|
||
if (_SwiftCollections_SourceDIR) | ||
FetchContent_Declare(SwiftCollections | ||
SOURCE_DIR ${_SwiftCollections_SourceDIR}) | ||
else() | ||
FetchContent_Declare(SwiftCollections | ||
GIT_REPOSITORY https://github.com/apple/swift-collections.git | ||
GIT_TAG 1.1.1) | ||
endif() | ||
FetchContent_MakeAvailable(SwiftFoundationICU SwiftCollections) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${SwiftFoundation_SOURCE_DIR}/cmake/modules) | ||
|
||
# Availability Macros (only applies to FoundationEssentials and FoundationInternationalization) | ||
set(_SwiftFoundation_availability_macros) | ||
list(APPEND _SwiftFoundation_availability_macros | ||
"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\">" | ||
"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\">" | ||
"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\">" | ||
"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\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.1:macOS 14, iOS 17, tvOS 17, watchOS 10\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.2:macOS 14, iOS 17, tvOS 17, watchOS 10\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.3:macOS 14, iOS 17, tvOS 17, watchOS 10\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicate 0.4:macOS 14, iOS 17, tvOS 17, watchOS 10\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.1:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.2:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.3:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend \"AvailabilityMacro=FoundationPredicateRegex 0.4:macOS 10000, iOS 10000, tvOS 10000, watchOS 10000\">") | ||
|
||
include(SwiftFoundationSwiftSupport) | ||
|
||
add_subdirectory(Sources) | ||
add_subdirectory(cmake/modules) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
add_subdirectory(_CShims) | ||
add_subdirectory(FoundationMacros) | ||
add_subdirectory(FoundationEssentials) | ||
add_subdirectory(FoundationInternationalization) |
37 changes: 37 additions & 0 deletions
37
Sources/FoundationEssentials/AttributedString/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
target_sources(FoundationEssentials PRIVATE | ||
AttributeContainer.swift | ||
AttributeScope.swift | ||
AttributedString+AttributeTransformation.swift | ||
AttributedString+CharacterView.swift | ||
AttributedString+Guts.swift | ||
AttributedString+Runs+AttributeSlices.swift | ||
AttributedString+Runs+Run.swift | ||
AttributedString+Runs.swift | ||
AttributedString+UnicodeScalarView.swift | ||
AttributedString+_InternalRun.swift | ||
AttributedString+_InternalRuns.swift | ||
AttributedString+_InternalRunsSlice.swift | ||
AttributedString.swift | ||
AttributedStringAttribute.swift | ||
AttributedStringAttributeConstrainingBehavior.swift | ||
AttributedStringAttributeStorage.swift | ||
AttributedStringCodable.swift | ||
AttributedStringProtocol.swift | ||
AttributedSubstring.swift | ||
Collection\ Stdlib\ Defaults.swift | ||
Conversion.swift | ||
FoundationAttributes.swift | ||
String.Index+ABI.swift) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
add_library(FoundationEssentials | ||
_ThreadLocal.swift | ||
Bundle+Stub.swift | ||
Codable.swift | ||
CodableUtilities.swift | ||
CodableWithConfiguration.swift | ||
ComparisonResult.swift | ||
Date.swift | ||
DateInterval.swift | ||
FoundationEssentials.swift | ||
IndexPath.swift | ||
LockedState.swift | ||
Logging.swift | ||
OutputBuffer.swift | ||
Platform.swift | ||
SortComparator.swift | ||
UUID_Wrappers.swift | ||
UUID.swift | ||
WinSDK+Extensions.swift) | ||
|
||
add_subdirectory(AttributedString) | ||
add_subdirectory(Calendar) | ||
add_subdirectory(Data) | ||
add_subdirectory(Decimal) | ||
add_subdirectory(Error) | ||
add_subdirectory(FileManager) | ||
add_subdirectory(Formatting) | ||
add_subdirectory(JSON) | ||
add_subdirectory(Locale) | ||
add_subdirectory(Predicate) | ||
add_subdirectory(ProcessInfo) | ||
add_subdirectory(PropertyList) | ||
add_subdirectory(String) | ||
add_subdirectory(TimeZone) | ||
add_subdirectory(URL) | ||
|
||
# Depend on FoundationMacros | ||
add_dependencies(FoundationEssentials FoundationMacros) | ||
target_compile_options(FoundationEssentials PRIVATE -plugin-path ${CMAKE_BINARY_DIR}/lib) | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android) | ||
target_compile_options(FoundationEssentials PRIVATE | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -Xcc -Xfrontend -D_GNU_SOURCE>") | ||
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) | ||
endif() | ||
|
||
target_compile_options(FoundationEssentials PRIVATE | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend VariadicGenerics>" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>" | ||
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InferSendableFromCaptures>") | ||
target_compile_options(FoundationEssentials PRIVATE ${_SwiftFoundation_availability_macros}) | ||
target_compile_options(FoundationEssentials PRIVATE -package-name "SwiftFoundation") | ||
|
||
target_link_libraries(FoundationEssentials PUBLIC | ||
_CShims | ||
_FoundationCollections) | ||
|
||
set_target_properties(FoundationEssentials PROPERTIES | ||
INSTALL_RPATH "$ORIGIN") | ||
|
||
set_property(GLOBAL APPEND PROPERTY SWIFT_FOUNDATION_EXPORTS FoundationEssentials) | ||
_swift_foundation_install_target(FoundationEssentials) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
target_sources(FoundationEssentials PRIVATE | ||
Calendar.swift | ||
Calendar_Autoupdating.swift | ||
Calendar_Cache.swift | ||
Calendar_Enumerate.swift | ||
Calendar_Gregorian.swift | ||
Calendar_Protocol.swift | ||
Calendar_Recurrence.swift | ||
Date+FormatStyle.swift | ||
Date+Locale.swift | ||
DateComponents.swift | ||
RecurrenceRule.swift) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
target_sources(FoundationEssentials PRIVATE | ||
Collections+DataProtocol.swift | ||
ContiguousBytes.swift | ||
Data+Base64.swift | ||
Data+Error.swift | ||
Data+Reading.swift | ||
Data+Stub.swift | ||
Data+Writing.swift | ||
Data.swift | ||
DataProtocol.swift | ||
Pointers+DataProtocol.swift) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
target_sources(FoundationEssentials PRIVATE | ||
Decimal.swift | ||
Decimal+Conformances.swift) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
target_sources(FoundationEssentials PRIVATE | ||
CocoaError+FilePath.swift | ||
CocoaError.swift | ||
ErrorCodes+POSIX.swift | ||
ErrorCodes+Win32.swift | ||
ErrorCodes.swift) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay to leave them for now, but we should probably move these settings into a separate CMake cache file so that if folks need to cross-compile SwiftFoundation for use outside of the prebuilt SDK, they can do so in a way that is configurable.