diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake index db90f9930d..777deadfbc 100644 --- a/Modules/CMakeDetermineSystem.cmake +++ b/Modules/CMakeDetermineSystem.cmake @@ -225,12 +225,16 @@ if(CMAKE_BINARY_DIR) # if a toolchain file is used, it needs to be included in the configured file, # so settings done there are also available if they don't go in the cache and in try_compile() set(INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED) - if(CMAKE_TOOLCHAIN_FILE) + if(DEFINED CMAKE_TOOLCHAIN_FILE) string(CONCAT INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED "set(_CMAKE_INPUT_TOOLCHAIN_FILE [==[${_CMAKE_INPUT_TOOLCHAIN_FILE}]==])\n" - "set(_CMAKE_SYSTEM_TOOLCHAIN_FILE \"${CMAKE_TOOLCHAIN_FILE}\")\n" - "include(\"\${_CMAKE_SYSTEM_TOOLCHAIN_FILE}\")" ) + if(_INCLUDED_TOOLCHAIN_FILE) + string(APPEND INCLUDE_CMAKE_TOOLCHAIN_FILE_IF_REQUIRED + "set(_CMAKE_SYSTEM_TOOLCHAIN_FILE \"${CMAKE_TOOLCHAIN_FILE}\")\n" + "include(\"\${_CMAKE_SYSTEM_TOOLCHAIN_FILE}\")" + ) + endif() endif() # configure variables set in this file for fast reload, the template file is defined at the top of this file diff --git a/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake b/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake index a29a66005b..0f8f733195 100644 --- a/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompilerChange/RunCMakeTest.cmake @@ -45,6 +45,17 @@ if(UNIX AND "${RunCMake_GENERATOR}" MATCHES "Unix Makefiles|Ninja|FASTBuild") endblock() endif() +# Running with empty toolchain argument does not trigger reconfigure +block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ToolchainEmpty-build) + set(RunCMake-stdout-file + ${RunCMake_SOURCE_DIR}/ToolchainEmpty-stdout.txt + ) + run_cmake_with_options(ToolchainEmpty-step1 "-DCMAKE_TOOLCHAIN_FILE=") + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake(ToolchainEmpty-step2) +endblock() + # Set up "toolchain" files file(WRITE "${RunCMake_BINARY_DIR}/foo.cmake" "set(toolchain_var foo)\n") file(WRITE "${RunCMake_BINARY_DIR}/bar.cmake" "set(toolchain_var bar)\n") diff --git a/Tests/RunCMake/CompilerChange/ToolchainEmpty-stdout.txt b/Tests/RunCMake/CompilerChange/ToolchainEmpty-stdout.txt new file mode 100644 index 0000000000..5db9bd57dd --- /dev/null +++ b/Tests/RunCMake/CompilerChange/ToolchainEmpty-stdout.txt @@ -0,0 +1,2 @@ +-- Toolchain file: $ +-- Using toolchain: $ diff --git a/Tests/RunCMake/CompilerChange/ToolchainEmpty-step1.cmake b/Tests/RunCMake/CompilerChange/ToolchainEmpty-step1.cmake new file mode 100644 index 0000000000..68a8f6a7d7 --- /dev/null +++ b/Tests/RunCMake/CompilerChange/ToolchainEmpty-step1.cmake @@ -0,0 +1,2 @@ +message(STATUS "Toolchain file: ${CMAKE_TOOLCHAIN_FILE}") +message(STATUS "Using toolchain: ${toolchain_var}") diff --git a/Tests/RunCMake/CompilerChange/ToolchainEmpty-step2.cmake b/Tests/RunCMake/CompilerChange/ToolchainEmpty-step2.cmake new file mode 100644 index 0000000000..68a8f6a7d7 --- /dev/null +++ b/Tests/RunCMake/CompilerChange/ToolchainEmpty-step2.cmake @@ -0,0 +1,2 @@ +message(STATUS "Toolchain file: ${CMAKE_TOOLCHAIN_FILE}") +message(STATUS "Using toolchain: ${toolchain_var}")