【问题标题】:Configure Visual Studio Code for CMake with some options使用一些选项为 CMake 配置 Visual Studio Code
【发布时间】:2021-09-14 13:28:57
【问题描述】:

我想使用CMake Tools extension 在 Visual Studio Code 中开发 CMake 项目。

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

PS project\build> cmake -G"Visual Studio 14 2015 Win64" -DBOOST_ROOT=some\path -DQT_ROOT=another\path\ project\path

如何在.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"
  ]
}

【问题讨论】:

    标签: cmake visual-studio-code


    【解决方案1】:

    .vscode\.cmaketools.json 文件只是 Visual Studio Code - CMake Tools Extension 的“工作区缓存”。见他们的code:

    /**
     * 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.
    */
    

    我认为您想要的是.vscode\settings.json,如here 所述,例如以下内容:

    {
        "cmake.generator": "Visual Studio 14 2015 Win64",
        "cmake.configureSettings": { "BOOST_ROOT": "some/path", "QT_ROOT": "another/path" }
    }
    

    【讨论】:

    • 您的链接似乎已损坏。
    • 我相信,链接的文档现在是here
    • 指定 QT_ROOT 对我不起作用,但以下方法对我有用:"cmake.configureArgs" : [ "-DCMAKE_PREFIX_PATH=C:\\projects\\qt" ]
    • @SebastianK 根据文档(vector-of-bool.github.io/docs/vscode-cmake-tools/settings.html):警告:总是更喜欢使用 cmake.configureSettings 或 CMake 变体。永远不要使用此设置传递 -D 参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 2021-06-16
    • 2023-01-17
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    相关资源
    最近更新 更多