使用某些选项为CMake配置Visual Studio代码

Jep*_*sen 3 cmake visual-studio-code

我想使用CMake工具扩展在Visual Studio Code中开发CMake项目。

我使用以下命令在命令行中构建项目:

PS project\build> cmake -G"Visual Studio 14 2015 Win64" -DBOOST_ROOT=some\path -DQT_ROOT=another\path\ project\path
Run Code Online (Sandbox Code Playgroud)

如何在.cmaketools.json文件.vscode夹下的文件中使用相同的选项设置相同的命令?我想从编辑器内部运行它,如果可能的话,还指定输出文件夹,而不是build在我的项目中创建一个文件夹。

这是我的实际.cmaketools.json

{
  "variant": {
    "label": "Debug",
    "keywordSettings": {
      "buildType": "debug"
    },
    "description": "Emit debug information without performing optimizations"
  },
  "activeEnvironments": [
    "Visual C++ 14.0 - amd64"
  ]
}
Run Code Online (Sandbox Code Playgroud)

Flo*_*ian 6

.vscode\.cmaketools.json文件只是Visual Studio代码-CMake工具扩展的“工作区缓存”。查看他们的代码

/**
 * The workspace cache stores extension state that is convenient to remember
 * between executions. Things like the active variant or enabled environments
 * are stored here so that they may be recalled quickly upon extension
 * restart.
*/
Run Code Online (Sandbox Code Playgroud)

我想你想要的是一个.vscode\settings.json描述这里与例如以下内容:

/**
 * The workspace cache stores extension state that is convenient to remember
 * between executions. Things like the active variant or enabled environments
 * are stored here so that they may be recalled quickly upon extension
 * restart.
*/
Run Code Online (Sandbox Code Playgroud)

  • 指定 QT_ROOT 对我来说不起作用,但以下方法起作用了: ``"cmake.configureArgs" : [ "-DCMAKE_PREFIX_PATH=C:\\projects\\qt" ]`` (3认同)
  • @SebastianK 根据文档(https://vector-of-bool.github.io/docs/vscode-cmake-tools/settings.html):警告:始终更喜欢使用 cmake.configureSettings 或 CMake 变体。切勿使用此设置传递 -D 参数。 (3认同)
  • 您的链接似乎已断开。 (2认同)