Skip to content

Commit e92d120

Browse files
committed
Switch to using FetchContent to automatically fetch dependencies
1 parent c658351 commit e92d120

File tree

10 files changed

+76
-79
lines changed

10 files changed

+76
-79
lines changed

CMakeLists.txt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##
1313
##===----------------------------------------------------------------------===##
1414

1515
cmake_minimum_required(VERSION 3.22)
1616

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+
1727
project(SwiftFoundation
1828
LANGUAGES C Swift)
1929

@@ -25,11 +35,28 @@ set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2535
set(BUILD_TESTING NO)
2636

2737
# Make sure our dependencies exists
28-
find_package(SwiftCollections CONFIG REQUIRED)
29-
find_package(SwiftFoundationICU CONFIG REQUIRED)
30-
# In the future we will fetch these dependencies if none found
38+
include(FetchContent)
39+
if (_SwiftFoundationICU_SourceDIR)
40+
FetchContent_Declare(SwiftFoundationICU
41+
SOURCE_DIR ${_SwiftFoundationICU_SourceDIR})
42+
else()
43+
FetchContent_Declare(SwiftFoundationICU
44+
GIT_REPOSITORY https://github.com/iCharlesHu/swift-foundation-icu.git
45+
GIT_TAG charles/cmake-support)
46+
endif()
47+
FetchContent_MakeAvailable(SwiftFoundationICU)
48+
49+
if (_SwiftCollections_SourceDIR)
50+
FetchContent_Declare(SwiftCollections
51+
SOURCE_DIR ${_SwiftCollections_SourceDIR})
52+
else()
53+
FetchContent_Declare(SwiftCollections
54+
GIT_REPOSITORY https://github.com/apple/swift-collections.git
55+
GIT_TAG release/1.1)
56+
endif()
57+
FetchContent_MakeAvailable(SwiftCollections)
3158

32-
# Availability Macros
59+
# Availability Macros (only applies to FoundationEssentials and FoundationInternationalization)
3360
set(_SwiftFoundation_availability_macros)
3461
list(APPEND _SwiftFoundation_availability_macros
3562
"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\">"

Sources/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##
@@ -15,4 +15,3 @@
1515
add_subdirectory(_CShims)
1616
add_subdirectory(FoundationEssentials)
1717
add_subdirectory(FoundationInternationalization)
18-
add_subdirectory(Foundation)

Sources/Foundation/CMakeLists.txt

Lines changed: 0 additions & 28 deletions
This file was deleted.

Sources/FoundationEssentials/CMakeLists.txt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##
1313
##===----------------------------------------------------------------------===##
1414

1515
file(GLOB_RECURSE _FoundationEssentialsSources "*.swift")
16-
add_library(FoundationEssentials ${_FoundationEssentialsSources})
16+
add_library(FoundationEssentials SHARED ${_FoundationEssentialsSources})
1717

1818
# Configure FoundationMacros
1919
include(ExternalProject)
@@ -27,7 +27,6 @@ else()
2727
set(FoundationMacrosPath "${BINARY_DIR}/FoundationMacros#FoundationMacros")
2828
endif()
2929

30-
add_dependencies(FoundationEssentials _CShims)
3130
add_dependencies(FoundationEssentials FoundationMacros)
3231

3332
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
@@ -41,11 +40,9 @@ target_compile_options(FoundationEssentials PRIVATE ${_SwiftFoundation_availabil
4140
target_compile_options(FoundationEssentials PRIVATE -load-plugin-executable "${FoundationMacrosPath}")
4241
target_compile_options(FoundationEssentials PRIVATE -package-name "SwiftFoundation")
4342

44-
find_package(SwiftCollections CONFIG REQUIRED)
45-
4643
target_link_libraries(FoundationEssentials PUBLIC
4744
_CShims
48-
SwiftCollections::OrderedCollections
49-
SwiftCollections::_RopeModule)
45+
OrderedCollections
46+
_RopeModule)
5047

5148
set_property(GLOBAL APPEND PROPERTY SWIFT_FOUNDATION_EXPORTS FoundationEssentials)
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##
1313
##===----------------------------------------------------------------------===##
1414

1515
file(GLOB_RECURSE _FoundationInternationalizationSources "*.swift")
16-
add_library(FoundationInternationalization ${_FoundationInternationalizationSources})
16+
add_library(FoundationInternationalization SHARED ${_FoundationInternationalizationSources})
1717

1818
target_compile_options(FoundationInternationalization PRIVATE
1919
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>")
2020
target_compile_options(FoundationInternationalization PRIVATE ${_SwiftFoundation_availability_macros})
2121
target_compile_options(FoundationInternationalization PRIVATE -package-name "SwiftFoundation")
2222

23-
find_package(SwiftFoundationICU CONFIG REQUIRED)
24-
25-
# Dependencies
26-
add_dependencies(FoundationInternationalization _CShims)
27-
add_dependencies(FoundationInternationalization FoundationEssentials)
28-
2923
target_link_libraries(FoundationInternationalization PRIVATE
3024
_CShims
3125
FoundationEssentials
32-
SwiftFoundationICU::FoundationICU)
26+
FoundationICU)
3327

3428
set_property(GLOBAL APPEND PROPERTY SWIFT_FOUNDATION_EXPORTS FoundationInternationalization)

Sources/FoundationMacros/CMakeLists.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##
1313
##===----------------------------------------------------------------------===##
1414

1515
cmake_minimum_required(VERSION 3.22)
1616

17+
if(POLICY CMP0156)
18+
# Deduplicate linked libraries where appropriate
19+
cmake_policy(SET CMP0156 NEW)
20+
endif()
21+
1722
if(POLICY CMP0157)
23+
# New Swift build model: improved incremental build performance and LSP support
1824
cmake_policy(SET CMP0157 NEW)
1925
endif()
2026

2127
project(FoundationMacros
2228
LANGUAGES Swift)
2329

24-
find_package(SwiftSyntax CONFIG)
25-
if (NOT SwiftSyntax_FOUND)
26-
include(FetchContent)
30+
file(GLOB_RECURSE _FoundationMacrosSources "*.swift")
31+
add_executable(FoundationMacros ${_FoundationMacrosSources})
2732

33+
# Dependecies
34+
include(FetchContent)
35+
if (_SwiftSyntax_SourceDIR)
36+
FetchContent_Declare(SwiftSyntax
37+
SOURCE_DIR ${_SwiftSyntax_SourceDIR})
38+
else()
2839
FetchContent_Declare(SwiftSyntax
2940
GIT_REPOSITORY https://github.com/apple/swift-syntax.git
3041
GIT_TAG 84a4bedfd1294f6ee18e6dc9ad70df55fa6230f6)
31-
FetchContent_MakeAvailable(SwiftSyntax)
3242
endif()
33-
34-
file(GLOB_RECURSE _FoundationMacrosSources "*.swift")
35-
add_executable(FoundationMacros ${_FoundationMacrosSources})
43+
FetchContent_MakeAvailable(SwiftSyntax)
3644

3745
# Link against SwiftSyntax
3846
target_compile_options(FoundationMacros PRIVATE -parse-as-library)

Sources/_CShims/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##

Sources/_CShims/include/module.modulemap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ module _CShims {
1212
header "uuid.h"
1313

1414
export *
15-
}
15+
}

cmake/modules/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##

cmake/modules/SwiftFoundationConfig.cmake.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
##===----------------------------------------------------------------------===##
22
##
3-
## This source file is part of the SwiftFoundation open source project
3+
## This source file is part of the Swift open source project
44
##
5-
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation project authors
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
66
## Licensed under Apache License v2.0
77
##
88
## See LICENSE.txt for license information
9-
## See CONTRIBUTORS.md for the list of SwiftFoundation project authors
9+
## See CONTRIBUTORS.md for the list of Swift project authors
1010
##
1111
## SPDX-License-Identifier: Apache-2.0
1212
##

0 commit comments

Comments
 (0)