VSCode & CMake & vcpkg 整合

VSCode 整合 CMake

调试 CMake 工程

json 复制代码
// launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            // Resolved by CMake Tools:
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    // add the directory where our target was built to the PATHs
                    // it gets resolved by CMake Tools:
                    "name": "PATH",
                    "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
                }
            ],
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

传递 CMake Configure 参数

json 复制代码
// settings.json
{
    "cmake.configureArgs": [
        "-DHELLOCMAKE=ON"
    ]
}

设置 CMake 生成目录

json 复制代码
// settings.json
{
    "cmake.buildDirectory": "${workspaceFolder}/build_${buildKit}/${buildType}"
}

CMake 整合 vcpkg

  • VSCode 中配置 CMake 使用的工具链为 vcpkg :

    json 复制代码
    // settings.json
    {
        "cmake.configureSettings": {
            "CMAKE_TOOLCHAIN_FILE": "[vcpkg root]/scripts/buildsystems/vcpkg.cmake"
        }
    }
  • CMakeLists.txt 同目录下增加 vcpkg.json:

    json 复制代码
    // vcpkg.json
    {
        "dependencies": [
            "fmt"
        ]
    }
相关推荐
程序手艺人1 小时前
【日常开发】 VSCode Remote SSH 在 Ubuntu 18.04 (GLIBC 2.27) 上的解决方案
vscode·ubuntu·ssh
疏狂难除1 小时前
JetBrains IDE插件开发教程(二)——学习初始代码
ide·kotlin
培风图楠2 小时前
vscode初始配置环境后无法编译
ide·vscode·编辑器
雪靡3 小时前
Visual Studio 2026 优雅的给Cmake设置大代理
c++·ide·cmake·visual studio
周末也要写八哥3 小时前
Visual Studio 2022资源下载附保姆级安装教程
ide·visual studio
『昊纸』℃4 小时前
作为小白,C语言如何从零开始呢
c语言·ide·学习·编程·教材
yanghuashuiyue5 小时前
关于Eclipse和IDEA对比
java·ide·intellij-idea
插件开发5 小时前
在VS2019编辑器环境中使用c++打造window服务程序基础框架详细步骤
c++·编辑器·服务程序
bestlanzi5 小时前
使用vscode 搭建Java 开发环境
ide·vscode·编辑器
xiaobobo333020 小时前
vscode+clangd打开头文件发现某些标识符不识别为“白色”语言模型识别为C++
vscode·识别头文件错误·标识符为白色·语言模型识别错误