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"
        ]
    }
相关推荐
送我上青云|23 分钟前
告别繁琐命令行:VS Code CMake Tools 环境配置极简指南
ide·visual studio code
还是大剑师兰特5 小时前
Vue3 前端专属配置(VSCode settings.json + .prettierrc)
前端·vscode·json
小路恢弘10 小时前
xcode替换LLVM插件
ide·macos·xcode
学嵌入式的小杨同学10 小时前
STM32 进阶封神之路(十五):DHT11 单总线实战 —— 温湿度检测从时序解析到代码落地(库函数 + 寄存器)
vscode·stm32·单片机·嵌入式硬件·mcu·智能硬件·pcb工艺
阿捏利11 小时前
vscode+ida-mcp-server配置及使用
vscode·ida·逆向·mcp
#空城12 小时前
LVGL9.5在VScode中安装模拟器
ide·vscode·编辑器
wayz1112 小时前
正则表达式:从入门到精通
java·python·正则表达式·编辑器
Liu.77414 小时前
vscode使用git和svn
git·vscode·svn
吧啦蹦吧15 小时前
idea---------------
java·ide·intellij-idea
golang学习记15 小时前
JetBrains Air 公测上线:当 26 年老牌 IDE 厂商开始“玩“智能体[特殊字符]
ide·intellij-idea·air