Hi all!
Given the following CMakeLists.txt
cmake_minimum_required(VERSION 3.26)
project(MyProj LANGUAGES CXX)
add_executable(MyProj src.cpp)
and CMakePresets.json
{
"version": 6,
"configurePresets": [
{
"name": "Config",
"binaryDir": "build",
"generator": "Ninja Multi-Config",
"toolset":{
"value": "host=x64, version=14.37"
},
"cacheVariables": {
"CMAKE_CXX_COMPILER": "cl"
}
}
]
}
I can open the folder that contains these files in Visual Studio 2022 and it will configure without issue using the Visual Studio CMake integration. However if I execute the following command:
cmake --preset Config
I get the following error:
Preset CMake variables:
CMAKE_CXX_COMPILER="cl"
CMake Error at CMakeLists.txt:3 (project):
Generator
Ninja Multi-Config
does not support toolset specification, but toolset
host=x64, version=14.37
was specified.
-- Configuring incomplete, errors occurred!
After doing some research I found a few reasons why which is all quite nicely laid out in this post. My questions from this would be:
- Why is the Visual Studio CMake integration able to work with this preset and configure the project in the way I want? i.e. Ninja generator while using a specific version of the MSVC compiler.
- Is there a way for me to execute
cmake --preset Config
and achieve the same behaviour? Ideally without having to run vcvarsall.