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"
        ]
    }
相关推荐
sun03224 小时前
【VSCode基础】VSCode快捷键总结、工程导入配置等
ide·vscode·编辑器
AdleyTales9 小时前
vscode识别不了@提示找不到路径解决
前端·javascript·vscode
超级任性12 小时前
Visual Studio 2026 下载地址 V18.x.x各种版本官方下载网址
ide·visual studio
夜流冰13 小时前
VSCode - 插件: 高亮显示选中的目标
ide·vscode·c#
没学上了13 小时前
Pycharm修改环境
ide·python·pycharm
WF_YL16 小时前
IntelliJ IDEA 关闭保存时在文件末尾换行 -(取消保存自动末尾换行)
java·ide·intellij-idea
IT199516 小时前
IDEA+JDK11编译SpringCore5源码及替换项目中的Springcore
java·ide·intellij-idea
techzhi16 小时前
IntelliJ IDEA 启动卡顿问题排查与解决
java·ide·intellij-idea
a伊雪16 小时前
VSCode 安装通义灵码后左侧菜单栏不显示按钮的问题
ide·vscode·编辑器
超级任性17 小时前
Android Studio 各种版本及官方下载地址
android·ide·android studio·android-studio