cmake-gui: empty generator or toolset fails on the reconfigure while set inside the toolchain file

Description

I need to load default valued inside the main CMakeLists.txt script.

If you keep generator & toolset values from CMake GUI empty, they really pass empty values.

The problem is a migration from this issue

Environment

CMake GUI 3.29.0
Windows 10 Pro
Visual Studio 17 2022 generator

Error text from GUI log

  • Nothing was specified in generator & toolset
CMake Error: Error: generator platform: 
Does not match the platform used previously: x64
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
  • generator was set as x64
CMake Error: Error: generator toolset: 
Does not match the toolset used previously: v143
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
  • both generator & toolset specified
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19045.
Configuring done (0.0s)

Steps to reproduce

  1. Create empty folder with CMakeLists.txt file:
cmake_minimum_required(VERSION 3.24)

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake")

project(Test)

And toolchain.cmake file with contents:

if(NOT CMAKE_GENERATOR_TOOLSET)
    set(CMAKE_GENERATOR_TOOLSET "v143" CACHE INTERNAL "Visual Studio toolset to use for CMake")
endif()
if(NOT CMAKE_GENERATOR_PLATFORM)
    set(CMAKE_GENERATOR_PLATFORM "x64" CACHE INTERNAL "Visual Studio platform to use for CMake")
endif()

if(NOT CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE)
    set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64" CACHE INTERNAL "Host architecture to use for CMake")
endif()
  1. Load project from CMake GUI

  2. Delete cache through FileDelete Cache

  3. Press Configure button

  4. Use this settings (or another from log):
    image

  5. Press Finish

  6. Wait for configure is finished

  7. Press Configure button again

  8. See the error

I’ve removed the CACHE INTERNAL "..." from all variables inside toolchain.cmake and all works as I want