Search code examples
visual-studio-codecmake

Is there a way to distinguish which CMake Tools Kit is chosen in the settings.json of VS Code?


Is there a way to distinguish, which cmake-kits are selected in the settings.json of VS Code?

For example I want to do something like that (this is not working).

.vscode/cmake-kits.json:

[
    {
      "name": "SDK",
      "toolchainFile": "${workspaceFolder}/toolchain/SDK.cmake"
    }
]

settings.json

{
    "[SDK]":{
        "cmake.cmakePath":"${workspaceFolder}/cmake.sh"
    }
    
}

To be precise I want to execute a script, when the SDK is selected and I do not want to execute it, when the local compiler is selected.


Solution

  • To get what you want with modifying a VS Code setting based on the selected CMake Kits in the way that you're leading the question, you'd want to look in the direction of variable substitution, where you'd find several variables provided by the CMake Tools extensions for build kits. Unfortunately, this is a dead end. There is currently no way to set a VS Code setting conditioned upon the value of a variable. I'm not aware of a way to get any further with CMake Tools Kits.

    What I would instead suggest that you do is use CMake Presets, which support a cmakeExecutable property in the configurePreset entry schema. The CMake Tools extension has pretty good support for CMake Presets, and you get the additional benefit that CMake Presets are not an IDE/IDE-extension-specific feature, but rather a CMake feature (unlike CMake Tools Kits, which are specific to CMake Tools).