I am currently trying to improve the CMake user experience in Microsoft Visual Studio (MSVS) 2019 with our CMake-based convention-over-configuration build system.
Until MSVC 2019 we always used a "MSBuild"-generator (e.g. "Visual Studio 2017"
). But since Microsoft states that later updates of MSVS are able to open an existing CMakeCache.txt
, I wanted to give this MSVS feature a try.
What I would like to achieve: Make MSVS 2019 "understand" CMakeCache.txt
files using the build generator "Ninja Multi-Config"
.
Currently our build system generates a CMakeSettings.json
(in the same directory as the CMakeLists.txt
file) file during the configure step:
{
"configurations": [
{
"name": "x64-windows-msvc1927-static-md-Debug",
"cacheRoot": "C:/_bld",
"cmakeExecutable": "E:/dev/native/cmake/cmake-3.18.2-x64/bin/cmake.exe",
"configurationType": "Debug"
},
{
"name": "x64-windows-msvc1927-static-md-Release",
"cacheRoot": "C:/_bld",
"cmakeExecutable": "E:/dev/native/cmake/cmake-3.18.2-x64/bin/cmake.exe",
"configurationType": "Release"
},
{
"name": "x64-windows-msvc1927-static-md-RelWithDebInfo",
"cacheRoot": "C:/_bld",
"cmakeExecutable": "E:/dev/native/cmake/cmake-3.18.2-x64/bin/cmake.exe",
"configurationType": "RelWithDebInfo"
}
]
}
Why are we doing this? We have to explicitly set "cmakeExecutable"
, otherwise MSVS uses the CMake version shipped with MSVS. This fails because we are using v3.18 (and don't want to rely on two different CMake versions for building the software).
Everything looks fine, because all three build configs show up below the "build configuration" combo-box in the MSVS IDE.
But regardless of what is selected, the IDE always builds and runs the Debug
build config. Selecting another build config does not have any effect at all.
I'm afraid that it is not possible (yet) to achieve the goal stated above with MSVS because it simply does not understand the "Ninja Multi-Config"
generator.
The thing is: I can't change the generator to "Ninja"
because that would trigger a CMake warning for an existing cache.
- Do I have to use the
"Ninja"
generator (together with different build trees) in the first place? - Is there any real solution to my problem of using "Ninja" as a multi-config generator in MSVS 2019?
- If the answer to question 1 is "yes" or to question 2 is "no": Shouldn't using the generator
"Visual Studio 2019"
be simpler? I don't see any UX advantage at all not using this generator then.
The following environment is used:
- CMake v3.18.2
- Microsoft Visual Studio 2019 v16.7.5
- Ninja 1.10.1
CMake upstream and author of the Ninja Multi-Config generator here. A few things: