Vscode-cmake-tools: preLaunchTask to build using cmaketools in settings.json

Created on 16 Sep 2018  路  11Comments  路  Source: microsoft/vscode-cmake-tools

I've tried using a build task but I couldnt get it to work. Is there any way to do this currently?

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "RelWithDebug",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Program/Etterna-release-symbols.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "Release",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Program/Etterna.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        }
    ]
}

This is what i currently have for settings.

Feature Request build

Most helpful comment

+1 For this option!

All 11 comments

CMake Tools does not currently integrate with the VSCode tasks system. There is an impedance mismatch between how tasks work and what CMake Tools needs to work. I'm hoping to reconcile these in the future.

That's a shame. This extension is absolutely amazing! Thanks for the great work. It just worked. Having an easy way to setup the launch settings with automatic building would be a godsend.

+1 For this option!

+1 This would be great!

+1 I need it too

+1
I came here to see if there is already a suggestion to integrate cmake with the tasks system. And I found it. Unfortunately it looks like we're not getting this feature, at least anytime soon.
Is there any progress or is it still not possible due to technical reasons?

imho setting up tasks in vs code is not really intuitive and my tasks usually ignore everything I set in the cmake extension and just run cmake with default args. While this somehow works in my usual configuration, it fails to chose the right tools when I want to use a different kit.
I would greatly appreciate a "cmake" task type that just works, like the rest of the extension (great work btw).

All the upvotes need to be given to the first comment of this issue (and not later) so that they get detected by our system and be triaged to a proper milestone.

Is there a workaround for launching a debug session and a build with a single command?

Edit:
Here is my task that works pretty well for most edits but there are still some issues.

{
    "label": "build",
    "type": "shell",
    "command": "cmake",
    "args": [
        "--build",
        "./build"
    ],
    "group": "build",
    "presentation": {
        "reveal": "silent",
    },
    "problemMatcher": "$msCompile"
}

Edit 2:
馃槼 I embarrassingly did not know that the CMake Tools version of the run command also triggers a build, I no longer use the above task and have instead just bound the CMake Tools run command to F5.
Thanks @andreeis

If you are using the CMake Tools debug feature (via the status bar or the command), a build will be triggered by an out of date state.
If you use a launch.json then no.

Found a good solution for this. Please give some thumbs up over here and hope it will be implemented finally.

@RolfNoot I also posted over there and will copy here for convenience.

Without preLaunchTask

There is an example launch.json in our documentation that shows how to do this without a preLaunchTask. https://github.com/microsoft/vscode-cmake-tools/blob/develop/docs/debug-launch.md#debug-using-a-launchjson-file

The cmake.launchTargetPath and cmake.getLaunchTargetPath variable substitutions and their side effects (or lack thereof) are documented here: https://github.com/microsoft/vscode-cmake-tools/blob/develop/docs/cmake-settings.md#command-substitution.

With preLaunchTask

cmake.tasksBuildCommand should give you the cmake command required to build your binary, so if you want a preLaunchTask you could create a shell task that runs ${command:cmake.tasksBuildCommand} as the command.

Was this page helpful?
0 / 5 - 0 ratings