summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2023-02-24 06:10:38 (GMT)
committerCraig Scott <craig.scott@crascit.com>2023-02-24 06:17:36 (GMT)
commitc15674a9cb0f8c6d432a52ac6fb724cc85f68034 (patch)
tree7a0dbed535916592d90111370edc175ee16e90ce
parent31ef93f19ff9c1529024ab5e9b82143b99ef1c70 (diff)
downloadCMake-c15674a9cb0f8c6d432a52ac6fb724cc85f68034.zip
CMake-c15674a9cb0f8c6d432a52ac6fb724cc85f68034.tar.gz
CMake-c15674a9cb0f8c6d432a52ac6fb724cc85f68034.tar.bz2
FetchContent: Reject CMAKE_TOOLCHAIN_FILE env var in sub-build
The sub-build should never try to use a toolchain file. The toolchain file may itself be getting downloaded by FetchContent. If the CMAKE_TOOLCHAIN_FILE environment variable is set, CMake uses it to initialize the CMake variable of the same name. We need to explicitly clear them before the first project call of the sub-build. Fixes: #24535
-rw-r--r--Modules/FetchContent/CMakeLists.cmake.in6
-rw-r--r--Tests/RunCMake/FetchContent/IgnoreToolchainFile.cmake2
-rw-r--r--Tests/RunCMake/FetchContent/RunCMakeTest.cmake1
3 files changed, 9 insertions, 0 deletions
diff --git a/Modules/FetchContent/CMakeLists.cmake.in b/Modules/FetchContent/CMakeLists.cmake.in
index aa2ad99..8adb533 100644
--- a/Modules/FetchContent/CMakeLists.cmake.in
+++ b/Modules/FetchContent/CMakeLists.cmake.in
@@ -3,6 +3,12 @@
cmake_minimum_required(VERSION @CMAKE_VERSION@)
+# Reject any attempt to use a toolchain file. We must not use one because
+# we could be downloading it here. If the CMAKE_TOOLCHAIN_FILE environment
+# variable is set, the cache variable will have been initialized from it.
+unset(CMAKE_TOOLCHAIN_FILE CACHE)
+unset(ENV{CMAKE_TOOLCHAIN_FILE})
+
# We name the project and the target for the ExternalProject_Add() call
# to something that will highlight to the user what we are working on if
# something goes wrong and an error message is produced.
diff --git a/Tests/RunCMake/FetchContent/IgnoreToolchainFile.cmake b/Tests/RunCMake/FetchContent/IgnoreToolchainFile.cmake
new file mode 100644
index 0000000..f8ee749
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/IgnoreToolchainFile.cmake
@@ -0,0 +1,2 @@
+set(ENV{CMAKE_TOOLCHAIN_FILE} path/to/somewhere/iDoNotExist.cmake)
+include(DownloadFile.cmake)
diff --git a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
index bb27491..3781089 100644
--- a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
@@ -7,6 +7,7 @@ run_cmake(DirectIgnoresDetails)
run_cmake(FirstDetailsWin)
run_cmake(DownloadTwice)
run_cmake(DownloadFile)
+run_cmake(IgnoreToolchainFile)
run_cmake(SameGenerator)
run_cmake(System)
run_cmake(VarDefinitions)