vscode-cmake-tools
vscode-cmake-tools copied to clipboard
Add support for "args" in task provider
Brief Issue Summary
I would like to have default build command to do cmake --build --preset presetName
- to build currently selected user preset. How can I know its name? I cannot find command to do ${command:cmake.getPresetName}
or something similar.
CMake Tools Diagnostics
No response
Debug Log
No response
Additional Information
No response
So far I may be solve this with "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"],
in the build task. Do you confirm?
currently, the args
element is not being supported in the build task.
This is a bug, when there is a default build
preset defined, CMakeTools should pick the default build preset
settings. (In the current design for the configure
task, CMakeTools will pick the default configure preset
settings to configure the project. The same should be applied to build
tasks.
One option that can be added to the configure
or build
task can be the name of the preset (instead of always picking the default).
for example:
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"all"
],
**"preset": "presetName",**
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
My initial goal is to have 3
tasks - build, clean and rebuild, all operating at the currently selected preset. As I know, but may be wrong, you can run command for build with cmake --build --preset presetName
or cmake --build pathToBuildDir
.
For the time being I did it that way - and it seems to work well:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Build project",
"command": "cmake",
"args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Re-build project",
"command": "cmake",
"args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
},
{
"type": "shell",
"label": "Clean project",
"command": "cmake",
"args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
}
]
}
I can see you have used the "shell" task as a workaround to pass "args"
to the task.
I will use this issue to track adding this feature (i.e. supporting args) to "cmake" tasks in future releases.
I opened another feature request to track adding the "clean" and "clean-rebuild" tasks #2555
There is an upcoming fix for this issue in PR https://github.com/microsoft/vscode-cmake-tools/pull/2636. In this PR we added the suport for "env" variables as well as "preset".
after this fix goes in, you can have two ways of defining a build task:
- the first approach, using presets:
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"preset": "${command:cmake.activeBuildPresetName}",
"group": "build",
"options": {
"cwd": "${workspaceFolder}"
},
"detail": "CMake: build"
}
This task is equal to running cmake --build --preset <buildPresetName>
.
Note that when using presets, the args that are defined in settings.json will be ignored.
- the second approach:
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"all"
],
"options": {},
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
In this approach, any args that you define the settings including "cmake.buildDirectory"
, "cmake.buildArgs"
, and "cmake.buildToolArgs"
will be implicitly added to the build task.
currently, we don't support adding additional args to the task.