【发布时间】:2021-07-14 17:08:09
【问题描述】:
我使用 Visual Studio Code 和 CMake extension 来处理一个大项目。该项目由一些库和可执行文件组成,它们都可以作为单独的 cmake 构建目标使用。
我将 VSCode / tasks.json 配置为使用其默认 build.task 构建选定的目标:
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake build",
"type": "cmake",
"command": "build",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
现在,每当我点击<Ctrl-Shift-b> 时,都会构建选定的构建目标。
然后我通过创建 launch.json 文件来创建启动配置:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": ["--serialPort","/dev/ttyS0"],
"stopAtEntry": false,
"cwd": "${command:cmake.launchTargetDirectory}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
现在,每当我点击F5 时,gdb 调试器都会使用选定的启动目标启动。
这很好用,除了只有 一个 的启动目标需要我提供的 "args": ["--serialPort","/dev/ttyS0"]。其他一些人拒绝从给定的这个参数开始。
那么,有没有办法在 VSCode 中使用 cmake 为单独的目标设置单独的参数?
【问题讨论】:
标签: c++ visual-studio-code cmake