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"
        ]
    }
相关推荐
FeelTouch Labs3 小时前
Node.js 中的 spawn 和 exec:子进程执行的不同方式对比
node.js·编辑器·vue·vim
余衫马5 小时前
2026最新版!Android Studio 极速安装与配置指南
android·ide·android studio
你的菊花 倾心恋仙6 小时前
最锋利的Visual Studio Web开发工具扩展:Web Essentials详解
前端·ide·visual studio
MoSTChillax7 小时前
数字人竞品分析(中):核心功能、产品使用与技术能力对比
ide·macos·xcode
林三的日常10 小时前
AI编程IDE卡成PPT?低配电脑的末日来了
ide·电脑·ai编程
2501_9151063210 小时前
SwiftUI项目创建详解:使用Xcode从零开始创建第一个App项目
ide·vscode·ios·swiftui·个人开发·xcode·敏捷流程
PC2005-cloud12 小时前
FinalShell 自定义背景图片教程
ide·python·pycharm
2501_9160074713 小时前
IDE 是什么?集成开发环境详解与 iOS 开发选型指南
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
2601_960906721 天前
AI研发加速中式及泛亚洲
人工智能·vscode·macos·sublime text·phpstorm
啦啦啦!1 天前
虚拟机如何接入Codex并配置中转站(vscode插件版)
linux·vscode·ubuntu·编辑器