Skip to content

Commit f4b3d89

Browse files
committed
build: tweak FetchContent usage to follow best practices
We should do a singular call to `FetchContent_MakeAvailable` as per the documentation. Heed this advice which also allows us to reduce the scope of the overridden variables. Once we migrate to a new enough CMake minimum (3.25), we should be able to replace that with a `block` scope to avoid the push/pop manual adjustment.
1 parent f4cd217 commit f4b3d89

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

CMakeLists.txt

+12-8
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,15 @@ find_package(Foundation QUIET)
4949

5050
include(FetchContent)
5151

52-
set(_SD_SAVED_BUILD_TESTING ${BUILD_TESTING})
53-
set(_SD_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES})
54-
55-
set(BUILD_TESTING NO)
56-
set(BUILD_EXAMPLES NO)
52+
set(VendoredDependencies)
5753

5854
find_package(ArgumentParser CONFIG)
5955
if(NOT ArgumentParser_FOUND)
6056
message("-- Vending swift-argument-parser")
6157
FetchContent_Declare(ArgumentParser
6258
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
6359
GIT_TAG 1.2.3)
64-
FetchContent_MakeAvailable(ArgumentParser)
60+
list(APPEND VendoredDependencies ArgumentParser)
6561
endif()
6662

6763
find_package(LLBuild CONFIG)
@@ -74,7 +70,7 @@ if(NOT LLBuild_FOUND)
7470
FetchContent_Declare(LLBuild
7571
GIT_REPOSITORY https://github.com/apple/swift-llbuild
7672
GIT_TAG main)
77-
FetchContent_MakeAvailable(LLBuild)
73+
list(APPEND VendoredDependencies LLBuild)
7874
endif()
7975
endif()
8076

@@ -84,9 +80,17 @@ if(NOT TSC_FOUND)
8480
FetchContent_Declare(ToolsSupportCore
8581
GIT_REPOSITORY https://github.com/apple/swift-tools-support-core
8682
GIT_TAG main)
87-
FetchContent_MakeAvailable(ToolsSupportCore)
83+
list(APPEND VendoredDependencies ToolsSupportCore)
8884
endif()
8985

86+
set(_SD_SAVED_BUILD_TESTING ${BUILD_TESTING})
87+
set(_SD_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES})
88+
89+
set(BUILD_TESTING NO)
90+
set(BUILD_EXAMPLES NO)
91+
92+
FetchContent_MakeAvailable(${VendoredDependencies})
93+
9094
set(BUILD_TESTING ${_SD_SAVED_BUILD_TESTING})
9195
set(BUILD_EXAMPLES ${_SD_SAVED_BUILD_EXAMPLES})
9296

0 commit comments

Comments
 (0)