我已将 Visual Studio 配置为使用 CMakePresets.json 进行 CMake 设置,而不是 CMakeSettings.json:
我的 CMakePresets.json 没有明确指定任何生成器:
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "base",
"binaryDir": "${sourceDir}/build"
},
{
"name": "vcpkg",
"inherits": "base",
"description": "Use VCPKG toolchain file from default location ../../vcpkg/",
"toolchainFile": "${sourceDir}/../../vcpkg/scripts/buildsystems/vcpkg.cmake"
},
{
"name": "clangcl",
"inherits": "base",
"description": "Use ClangCL toolchain",
"toolset": "ClangCL"
},
{
"name": "vcpkg-clangcl",
"description": "Useful for Windows builds: use ClangCL toolchain and VCPKG toolchain file from default location ../../vcpkg/",
"inherits": [
"clangcl",
"vcpkg"
]
}
]
}
当我从 Visual Studio IDE 配置缓存时,CMake 输出显示已使用 Ninja 生成器调用 CMake:
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "c:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_TOOLCHAIN_FILE:FILEPATH="C:/dev/project/app/../../vcpkg/scripts/buildsystems/vcpkg.cmake" -DCMAKE_MAKE_PROGRAM="c:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "C:\dev\project\app" 2>&1"
如何配置 Visual Studio(2022)以选择“Visual Studio 17 2022”作为默认生成器而不是 Ninja?
作为比较,当我从 VS 2022 开发人员命令提示符配置缓存时,默认生成器是 Visual Studio 17 2022:
> cmake --preset vcpkg-clangcl
Preset CMake variables:
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:/dev/project/app/../../vcpkg/scripts/buildsystems/vcpkg.cmake"
-- Building for: Visual Studio 17 2022
...