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"
        ]
    }
相关推荐
tan180°7 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
万千思绪10 小时前
【PyCharm 2025.1.2配置debug】
ide·python·pycharm
我在看世界12 小时前
家里vscode连公司内网vscede
vscode·ssh
不想迷路的小男孩15 小时前
Android Studio 中Palette跟Component Tree面板消失怎么恢复正常
android·ide·android studio
AlickLbc15 小时前
在phpstudy环境下配置搭建XDEBUG配合PHPSTORM的调试环境
ide·phpstorm
悠悠小茉莉15 小时前
Win11 安装 Visual Studio(保姆教程 - 更新至2025.07)
c++·ide·vscode·python·visualstudio·visual studio
SZ17011023116 小时前
华为云 银河麒麟 vscode远程连接
ide·vscode·华为云
yanjiee17 小时前
需要scl来指定编译器的clangd+cmake在vscode/cursor开发环境下的配置
ide·vscode·编辑器
Waltt_Qiope20 小时前
关于使用cursor tunnel链接vscode(避免1006 issue的做法)
ide·vscode·issue
Charlene Fung21 小时前
vs code远程自动登录服务器,无需手动输入密码的终极方案(windows版)
运维·服务器·vscode·ssh