Skip to content

Commit 5306a4b

Browse files
committed
build: support building swift-driver outside of the toolchain
We can now vendor the dependencies allowing us to build a separate copy of the dependencies when building the package if it is not provided for. This enables building the package standalone for debugging in scenarios where SPM is unable to build the package (e.g. due to incorrect linking).
1 parent 01e8375 commit 5306a4b

File tree

1 file changed

+61
-14
lines changed

1 file changed

+61
-14
lines changed

CMakeLists.txt

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,90 @@
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.6)
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.6)
14-
15-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
16-
1719
project(SwiftDriver LANGUAGES C Swift)
1820

19-
set(CMAKE_Swift_LANGUAGE_VERSION 5)
20-
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
21-
set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
22-
2321
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2422
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2523
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2624

2725
set(CMAKE_MACOSX_RPATH YES)
2826
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
27+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
28+
29+
set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
30+
set(CMAKE_Swift_LANGUAGE_VERSION 5)
31+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2932

3033
# ensure Swift compiler can find _CSwiftScan
3134
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/CSwiftScan/include>)
3235

3336
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
3437

35-
find_package(TSC CONFIG REQUIRED)
38+
# Toolchain Vended Dependencies
39+
find_package(dispatch QUIET)
40+
find_package(Foundation QUIET)
41+
42+
include(FetchContent)
43+
44+
set(_SD_SAVED_BUILD_TESTING ${BUILD_TESTING})
45+
set(_SD_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES})
46+
47+
set(BUILD_TESTING NO)
48+
set(BUILD_EXAMPLES NO)
49+
50+
find_package(ArgumentParser CONFIG)
51+
if(NOT ArgumentParser_FOUND)
52+
message("-- Vending swift-argument-parser")
53+
FetchContent_Declare(ArgumentParser
54+
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
55+
GIT_TAG 1.2.3)
56+
FetchContent_MakeAvailable(ArgumentParser)
57+
endif()
3658

3759
find_package(LLBuild CONFIG)
3860
if(NOT LLBuild_FOUND)
39-
find_package(LLBuild REQUIRED)
61+
if(APPLE)
62+
find_package(LLBuild REQUIRED)
63+
else()
64+
message("-- Vending swift-llbuild")
65+
set(LLBUILD_SUPPORT_BINDINGS Swift)
66+
FetchContent_Declare(LLBuild
67+
GIT_REPOSITORY https://github.com/apple/swift-llbuild
68+
GIT_TAG main)
69+
FetchContent_MakeAvailable(LLBuild)
70+
endif()
4071
endif()
4172

42-
find_package(dispatch QUIET)
43-
find_package(Foundation QUIET)
44-
find_package(Yams CONFIG REQUIRED)
45-
find_package(ArgumentParser CONFIG REQUIRED)
73+
find_package(TSC CONFIG)
74+
if(NOT TSC_FOUND)
75+
message("-- Vending swift-tools-support-core")
76+
FetchContent_Declare(ToolsSupportCore
77+
GIT_REPOSITORY https://github.com/apple/swift-tools-support-core
78+
GIT_TAG main)
79+
FetchContent_MakeAvailable(ToolsSupportCore)
80+
endif()
81+
82+
find_package(Yams CONFIG)
83+
if(NOT Yams_FOUND)
84+
message("-- Vending yams")
85+
FetchContent_Declare(Yams
86+
GIT_REPOSITORY https://github.com/jpsim/yams
87+
GIT_TAG 5.0.6)
88+
FetchContent_MakeAvailable(Yams)
89+
endif()
90+
91+
set(BUILD_TESTING ${_SD_SAVED_BUILD_TESTING})
92+
set(BUILD_EXAMPLES ${_SD_SAVED_BUILD_EXAMPLES})
4693

4794
add_subdirectory(Sources)
4895
add_subdirectory(cmake/modules)

0 commit comments

Comments
 (0)