如何在Visual Studio 2019的CMake集成中使用较旧的编译器

时间:2019-09-05 16:45:07

标签: cmake grpc visual-studio-2019

我正在尝试将Windows上的gRPC编译为与必须使用Visual Studio 2015工具集进行编译的C ++应用程序兼容的DLL。

通过Visual Studio 2019安装程序,我将VS2019与Visual Studio 2015的旧C ++工具集(不是IDE)一起安装了。

当我在VS2019中打开新克隆的gRPC源文件夹时,其CMake集成会使用默认值创建以下CMakeSettings.json

{
  // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
  "configurations": [
    {
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x64_x64" ],
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": ""
    }
  ]
}

如何在CMakeSettings.json文件中指定在命令行或CMake GUI上使用CMake时可以指定的以下-A-T选项?

CMakeGUI

1 个答案:

答案 0 :(得分:1)

我在用户方舟的帮助下解决了这个问题:

  • -T参数进入cmakeCommandArgs
  • 不得指定-A参数,否则会因为指定了两次而出错。可以通过generatorinheritEnvironments设置(不确定哪个)。
  • generator必须设置为Visual Studio {installed IDE version},而不是Ninja
  • 由于generator的更改,必须将buildCommandArgs-v更改为/v:{desired verbosity level, see msbuild doc}

所有这些设置都可以通过UI进行更改。例: enter image description here enter image description here