VSCODE:从 launch.json 访问 cmake.buildDirectory

pem*_*pem 6 cmake visual-studio-code

我有一个 VSCode 的 cmake 项目,有几个构建变体。

也就是说,我将 cmake-variants.json 定义为:

{
    "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",
            },
            ....
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在 settings.json 中,我使用变体扩展定义 cmake 构建目录,如下所示:

"C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools",
"cmake.buildDirectory": "${workspaceFolder}/build/${variant:buildVariant}-${buildType}"
"cmake.generator": "Ninja",
...
Run Code Online (Sandbox Code Playgroud)

但现在为了远程调试,我需要在 launch.json 中提供可执行文件的路径(即构建工件的路径):

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

看来 launch.json 不知道“cmake.buildDirectory”:它只知道“${workspaceFolder}”。有什么方法可以告诉 launch json 构建工件应该位于哪里?

pem*_*pem 7

我自己找到的:

 "program": "${command:cmake.launchTargetDirectory}/program"
Run Code Online (Sandbox Code Playgroud)

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