Skip to content

Commit 87a157f

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 87a157f

File tree

1 file changed

+109
-18
lines changed

1 file changed

+109
-18
lines changed

CMakeLists.txt

Lines changed: 109 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,119 @@ 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+
44+
set(BUILD_EXAMPLES NO)
45+
set(BUILD_TESTING NO)
46+
47+
find_package(ArgumentParser CONFIG)
48+
if(NOT ArgumentParser_FOUND)
49+
message("-- Vending swift-argument-parser")
50+
FetchContent_Declare(ArgumentParser
51+
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
52+
GIT_TAG 1.2.3)
53+
FetchContent_MakeAvailable(ArgumentParser)
54+
endif()
55+
56+
find_package(TSC CONFIG)
57+
if(NOT TSC_FOUND)
58+
message("-- Vending swift-tools-support-core")
59+
FetchContent_Declare(ToolsSupportCore
60+
GIT_REPOSITORY https://github.com/apple/swift-tools-support-core
61+
GIT_TAG main)
62+
FetchContent_MakeAvailable(ToolsSupportCore)
63+
endif()
3664

37-
find_package(LLBuild CONFIG)
38-
if(NOT LLBuild_FOUND)
65+
find_package(LLBuild CONFIG)
66+
if(NOT LLBuild_FOUND)
67+
if(APPLE)
3968
find_package(LLBuild REQUIRED)
69+
else()
70+
message("-- Vending swift-llbuild")
71+
set(LLBUILD_SUPPORT_BINDINGS Swift)
72+
FetchContent_Declare(LLBuild
73+
GIT_REPOSITORY https://github.com/apple/swift-llbuild
74+
GIT_TAG main)
75+
FetchContent_MakeAvailable(LLBuild)
4076
endif()
77+
endif()
4178

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)
79+
find_package(SwiftASN1 CONFIG)
80+
if(NOT SwiftASN1_FOUND)
81+
message("-- Vending swift-asn1")
82+
FetchContent_Declare(ASN1
83+
GIT_REPOSITORY https://github.com/apple/swift-asn1
84+
GIT_TAG 1.1.0)
85+
FetchContent_MakeAvailable(ASN1)
86+
endif()
87+
88+
find_package(SwiftCertificates CONFIG)
89+
if(NOT SwiftCertificates_FOUND)
90+
message("-- Vending swift-certificates")
91+
FetchContent_Declare(Certificates
92+
# GIT_REPOSITORY https://github.com/apple/swift-certificates
93+
# GIT_TAG 1.1.0)
94+
GIT_REPOSITORY https://github.com/compnerd/swift-certificates
95+
GIT_TAG vendor)
96+
FetchContent_MakeAvailable(Certificates)
97+
endif()
98+
99+
find_package(SwiftCollections CONFIG)
100+
if(NOT SwiftCollections_FOUND)
101+
message("-- Vending swift-collections")
102+
FetchContent_Declare(Collections
103+
GIT_REPOSITORY https://github.com/apple/swift-collections
104+
GIT_TAG release/1.0)
105+
FetchContent_MakeAvailable(Collections)
106+
107+
add_library(SwiftCollections::DequeModule ALIAS DequeModule)
108+
add_library(SwiftCollections::OrderedCollections ALIAS OrderedCollections)
109+
endif()
110+
111+
find_package(SwiftCrypto CONFIG)
112+
if(NOT SwiftCyrpto_FOUND)
113+
message("-- Vending swift-crypto")
114+
FetchContent_Declare(Crypto
115+
GIT_REPOSITORY https://github.com/apple/swift-crypto
116+
GIT_TAG 3.0.0)
117+
FetchContent_MakeAvailable(Crypto)
118+
endif()
119+
120+
find_package(SwiftDriver CONFIG)
121+
if(NOT SwiftDriver_FOUND)
122+
message("-- Vending swift-driver")
123+
FetchContent_Declare(Driver
124+
GIT_REPOSITORY https://github.com/apple/swift-driver
125+
GIT_TAG main)
126+
FetchContent_MakeAvailable(Driver)
127+
endif()
128+
129+
find_package(SwiftSystem CONFIG)
130+
if(NOT SwiftSystem_FOUND)
131+
message("-- Vending swift-system")
132+
FetchContent_Declare(System
133+
GIT_REPOSITORY https://github.com/apple/swift-system
134+
GIT_TAG 1.1.1)
135+
FetchContent_MakeAvailable(System)
136+
137+
add_library(SwiftSystem::SystemPackage ALIAS SystemPackage)
48138
endif()
49139

50-
find_package(dispatch QUIET)
51-
find_package(Foundation QUIET)
52140
find_package(SQLite3 REQUIRED)
53141

142+
set(BUILD_TESTING ${_SPM_SAVED_BUILD_TESTING})
143+
set(BUILD_EXAMPLES ${_SPM_SAVED_BUILD_EXAMPLES})
144+
54145
add_subdirectory(Sources)
55146
add_subdirectory(cmake/modules)

0 commit comments

Comments
 (0)