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"
        ]
    }
相关推荐
NQBJT2 小时前
[特殊字符] VS Code + Markdown 从入门到精通:写论文、技术文档的超实用指南
开发语言·vscode·c#·markdown
摇滚侠13 小时前
帮我整理一份 IDEA 开发中常用快捷键
java·ide·intellij-idea
dyxal16 小时前
VS Code 终端疑难杂症排查:为什么 PowerShell 无法启动?
vscode
【ql君】qlexcel16 小时前
Visual Studio Code开发STM32设置头文件宏定义uint32_t报错
vscode·stm32·vs code·头文件宏定义·uint32_t报错·uint8_t报错·uint16_t报错
琉璃榴16 小时前
Visual Studio Code连接远程服务器
服务器·vscode·github
HuDie34017 小时前
agent项目实操笔记
ide
jieyucx18 小时前
Golang 完整安装与 VSCode 开发环境搭建教程
开发语言·vscode·golang
梦魇星虹18 小时前
idea Cannot find declaration to go to
java·ide·intellij-idea
xifangge202519 小时前
【故障排查】IDEA 打开 Java 文件没有运行按钮(Run)?深度解析项目标识与环境配置的 3 大底层坑点
java·ide·intellij-idea
Codiggerworld21 小时前
Vim的语法:删除、复制、粘贴,像说话一样自然
编辑器·vim·excel