Skip to content

Commit c117856

Browse files
committed
build: enable vendoring dependencies
Setup the support for building SPM with vendored dependencies. This is preparatory work to enable the build of the LSP which is not possible to build with SPM on Windows and thus prevented from being able to be built and debugged outside of the toolchain build.
1 parent 64b7ca9 commit c117856

File tree

1 file changed

+120
-18
lines changed

1 file changed

+120
-18
lines changed

CMakeLists.txt

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
cmake_minimum_required(VERSION 3.19)
10+
11+
if(POLICY CMP0077)
12+
cmake_policy(SET CMP0077 NEW)
13+
endif()
14+
915
if(POLICY CMP0091)
1016
cmake_policy(SET CMP0091 NEW)
1117
endif()
1218

13-
cmake_minimum_required(VERSION 3.19)
14-
15-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
16-
1719
project(SwiftPM LANGUAGES C Swift)
1820

1921
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
20-
option(FIND_PM_DEPS "Search for all external Package Manager dependencies" YES)
2122

2223
set(CMAKE_Swift_LANGUAGE_VERSION 5)
2324
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
@@ -27,29 +28,130 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2728
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2829
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2930

31+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
3032
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
3133
set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
3234

33-
if(FIND_PM_DEPS)
34-
find_package(SwiftSystem CONFIG REQUIRED)
35-
find_package(TSC CONFIG REQUIRED)
35+
# Toolchain Vended dependencies
36+
find_package(dispatch QUIET)
37+
find_package(Foundation QUIET)
38+
39+
include(FetchContent)
40+
41+
set(_SPM_SAVED_BUILD_TESTING ${BUILD_TESTING})
42+
set(_SPM_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES})
43+
set(_SPM_VENDOR_DEPENDENCIES)
44+
45+
set(BUILD_EXAMPLES NO)
46+
set(BUILD_TESTING NO)
47+
48+
find_package(ArgumentParser CONFIG)
49+
if(NOT ArgumentParser_FOUND)
50+
message("-- Vending swift-argument-parser")
51+
FetchContent_Declare(ArgumentParser
52+
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
53+
GIT_TAG 1.2.3)
54+
list(APPEND _SPM_VENDOR_DEPENDENCIES ArgumentParser)
55+
endif()
56+
57+
find_package(TSC CONFIG)
58+
if(NOT TSC_FOUND)
59+
message("-- Vending swift-tools-support-core")
60+
FetchContent_Declare(ToolsSupportCore
61+
GIT_REPOSITORY https://github.com/apple/swift-tools-support-core
62+
GIT_TAG main)
63+
list(APPEND _SPM_VENDOR_DEPENDENCIES ToolsSupportCore)
64+
endif()
3665

37-
find_package(LLBuild CONFIG)
38-
if(NOT LLBuild_FOUND)
66+
find_package(LLBuild CONFIG)
67+
if(NOT LLBuild_FOUND)
68+
if(APPLE)
3969
find_package(LLBuild REQUIRED)
70+
else()
71+
message("-- Vending swift-llbuild")
72+
set(LLBUILD_SUPPORT_BINDINGS Swift)
73+
FetchContent_Declare(LLBuild
74+
GIT_REPOSITORY https://github.com/apple/swift-llbuild
75+
GIT_TAG main)
76+
list(APPEND _SPM_VENDOR_DEPENDENCIES LLBuild)
4077
endif()
78+
endif()
4179

42-
find_package(ArgumentParser CONFIG REQUIRED)
43-
find_package(SwiftDriver CONFIG REQUIRED)
44-
find_package(SwiftCollections CONFIG REQUIRED)
45-
find_package(SwiftASN1 CONFIG REQUIRED)
46-
find_package(SwiftCertificates CONFIG REQUIRED)
47-
find_package(SwiftCrypto CONFIG REQUIRED)
80+
find_package(SwiftASN1 CONFIG)
81+
if(NOT SwiftASN1_FOUND)
82+
message("-- Vending swift-asn1")
83+
FetchContent_Declare(ASN1
84+
GIT_REPOSITORY https://github.com/apple/swift-asn1
85+
GIT_TAG 1.1.0)
86+
list(APPEND _SPM_VENDOR_DEPENDENCIES ASN1)
87+
endif()
88+
89+
find_package(SwiftCertificates CONFIG)
90+
if(NOT SwiftCertificates_FOUND)
91+
message("-- Vending swift-certificates")
92+
FetchContent_Declare(Certificates
93+
# GIT_REPOSITORY https://github.com/apple/swift-certificates
94+
# GIT_TAG 1.1.0)
95+
GIT_REPOSITORY https://github.com/compnerd/swift-certificates
96+
GIT_TAG vendor)
97+
list(APPEND _SPM_VENDOR_DEPENDENCIES Certificates)
98+
endif()
99+
100+
find_package(SwiftCollections CONFIG)
101+
if(NOT SwiftCollections_FOUND)
102+
message("-- Vending swift-collections")
103+
FetchContent_Declare(Collections
104+
GIT_REPOSITORY https://github.com/apple/swift-collections
105+
GIT_TAG release/1.0)
106+
list(APPEND _SPM_VENDOR_DEPENDENCIES Collections)
107+
endif()
108+
109+
find_package(SwiftCrypto CONFIG)
110+
if(NOT SwiftCyrpto_FOUND)
111+
message("-- Vending swift-crypto")
112+
FetchContent_Declare(Crypto
113+
GIT_REPOSITORY https://github.com/apple/swift-crypto
114+
GIT_TAG 3.0.0)
115+
list(APPEND _SPM_VENDOR_DEPENDENCIES Crypto)
116+
endif()
117+
118+
find_package(SwiftDriver CONFIG)
119+
if(NOT SwiftDriver_FOUND)
120+
message("-- Vending swift-driver")
121+
FetchContent_Declare(Driver
122+
GIT_REPOSITORY https://github.com/apple/swift-driver
123+
GIT_TAG main)
124+
list(APPEND _SPM_VENDOR_DEPENDENCIES Driver)
125+
endif()
126+
127+
find_package(SwiftSystem CONFIG)
128+
if(NOT SwiftSystem_FOUND)
129+
message("-- Vending swift-system")
130+
FetchContent_Declare(System
131+
GIT_REPOSITORY https://github.com/apple/swift-system
132+
GIT_TAG 1.1.1)
133+
list(APPEND _SPM_VENDOR_DEPENDENCIES System)
134+
endif()
135+
136+
if(_SPM_VENDOR_DEPENDENCIES)
137+
FetchContent_MakeAvailable(${_SPM_VENDOR_DEPENDENCIES})
138+
139+
if(NOT TARGET SwiftCollections::DequeModule)
140+
add_library(SwiftCollections::DequeModule ALIAS DequeModule)
141+
endif()
142+
if(NOT TARGET SwiftCollections::OrderedCollections)
143+
add_library(SwiftCollections::OrderedCollections ALIAS OrderedCollections)
144+
endif()
145+
146+
if(NOT TARGET SwiftSystem::SystemPackage)
147+
add_library(SwiftSystem::SystemPackage ALIAS SystemPackage)
148+
endif()
48149
endif()
49150

50-
find_package(dispatch QUIET)
51-
find_package(Foundation QUIET)
52151
find_package(SQLite3 REQUIRED)
53152

153+
set(BUILD_TESTING ${_SPM_SAVED_BUILD_TESTING})
154+
set(BUILD_EXAMPLES ${_SPM_SAVED_BUILD_EXAMPLES})
155+
54156
add_subdirectory(Sources)
55157
add_subdirectory(cmake/modules)

0 commit comments

Comments
 (0)