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 Command 详见:CMake Settings
传递 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" ] }