Unexpected behavior when regenerating a project with Ninja Multi-Config and MSVC

I have encountered an unusual behavior when regenerating a project using Ninja Multi-Config as the generator and Microsoft Visual C++ (MSVC) as the compiler.

Here is a minimal example project consisting of three files:

1. CMakeLists.txt

cmake_minimum_required(VERSION 3.15)

PROJECT(main)

find_package(Eigen3 CONFIG REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} Eigen3::Eigen)

2. CMakePresets.json

{
  "version": 10,
  "cmakeMinimumRequired": {
    "major": 4,
    "minor": 0
  },
  "configurePresets": [
    {
      "name": "default",
      "generator": "Ninja Multi-Config",
      "binaryDir": "${sourceDir}/build",
      "environment": {
        "VCPKG_HOST_TRIPLET": "x64-windows",
        "VCPKG_TARGET_TRIPLET": "x64-windows",
        "VCPKG_INSTALLED_DIR": "$env{VCPKG_ROOT}/installed"
      },
      "cacheVariables": {
        "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
        "CMAKE_C_COMPILER": "cl",
        "CMAKE_CXX_COMPILER": "cl"
      }
    }
  ]
}

3. main.cpp

#include <iostream>

int main()
{
  std::cout << "Hello\n";
  return 0;
}

When I run the following command for the first time:

cmake --preset=default

I get the expected output:

-- The C compiler identification is MSVC 19.43.34810.0
-- The CXX compiler identification is MSVC 19.43.34810.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.8s)
-- Generating done (0.0s)
-- Build files have been written to: F:/test_projects/test_cmake_ninja_multi/build

The project is successfully generated.

However, on the second invocation of the same command:

cmake --preset=default

I receive the following message:

-- Configuring done (0.1s)
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= cl
CMAKE_CXX_COMPILER= cl

-- The C compiler identification is MSVC 19.43.34810.0
-- The CXX compiler identification is MSVC 19.43.34810.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!

CMake now fails to find Eigen3, which was previously located without issue. Eigen is installed via vcpkg.

On the third invocation, the same error occurs again:

CMake Error at CMakeLists.txt:5 (find_package):
  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= cl
CMAKE_CXX_COMPILER= cl

-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_TOOLCHAIN_FILE


CMake Generate step failed.  Build files cannot be regenerated correctly.

However, on the fourth invocation, everything works as expected again — identical to the first run. The project is configured successfully.


Interestingly, this issue does not occur when using the clang-cl compiler instead of MSVC.


Has anyone else experienced this kind of behavior when using Ninja Multi-Config with MSVC and CMake presets? Is this a known issue, or am I misconfiguring something?

Any insights would be appreciated.