Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCODE: accessing cmake.buildDirectory from launch.json

I have a cmake project for VSCode with several build variants.

That is, I have cmake-variants.json defined as:

{
    "buildType": {
        "default": "Debug",
        "description": "The build type",
        "choices": {
            "Debug": {
                "short": "Debug",
                "long": "Debug: with debug info",
                "buildType": "Debug"
            },
            "Release": {
                "short": "Release",
                "long": "Release: no debug info",
                "buildType": "Release"
            },
            ...
        }
    },
    "buildVariant": {
        "default": "gcc-a64",
        "description": "Build variant (host or cross-compiling with GCC or Clang)",
        "choices": {
            "gcc-a64": {
                "short": "gcc-a64",
                "long": "GCCg cross-compile for A64",
            },
            ....
        }
    }
}

And then in settings.json, I define cmake build directory using variant expansion as follows:

"C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools",
"cmake.buildDirectory": "${workspaceFolder}/build/${variant:buildVariant}-${buildType}"
"cmake.generator": "Ninja",
...

But now for remote debugging, I need the path to executable to be available in launch.json (i.e. path to the build artifacts):

  "configurations": [
    {
        "name": "(cross-gdb) Launch program",
        "type": "cppdbg",
        "request": "launch",
        "program": "/path/to/cmake/build/directory/program",
        ...
    }

It seems that launch.json does not know about "cmake.buildDirectory": it only knows "${workspaceFolder}". Is there any way to tell launch json where the build artifacts should lie?

like image 273
pem Avatar asked Jun 23 '26 12:06

pem


1 Answers

Found it myself:

 "program": "${command:cmake.launchTargetDirectory}/program"

https://vector-of-bool.github.io/docs/vscode-cmake-tools/debugging.html

like image 164
pem Avatar answered Jun 25 '26 19:06

pem