“No Kit Selected”: Fixing VS Code CMake Kit Assignment

One important thing in using VS Code and CMake projects is that one needs to have a CMake kit assigned to the project. But after a restart of VS Code or if I re-load a project, VS Code has lost the previously assigned CMake kit:

VS Code has forgotten about the previously assigned CMake Kit?

This is very annoying, but luckily I have found a fix for this.

.vscode/cmake-kits.json

The trick is to add a file named cmake-kits.json to the .vscode folder, with the following content:

[
  {
    "name": "GCC 12.2.1 arm-none-eabi",
    "compilers": {
      "C": "${env:TOOLCHAIN_PATH}/arm-none-eabi-gcc",
      "CXX": "${env:TOOLCHAIN_PATH}/arm-none-eabi-g++"
    },
    "isTrusted": true,
    "keep": true
  }
]

This defines the CMake Toolkit with the compilers. With “isTrusted" and “keep" set to true, VS Code will keep that kit assigned.

Additionally I have set an environment variable for the tool chain which I easily can change. For example I have set it on Windows to:

TOOLCHAIN_PATH=C:\Raspy\arm-none-eabi-gcc-12.2.1-1.2\bin

.vscode/settings.json

Next, my .vscode/settings.json file:

{
    // These settings tweaks to the cmake plugin will ensure
    // that you debug using cortex-debug instead of trying to launch
    // a binary on the host
    "cmake.statusbar.advanced": {
        "debug": {
            "visibility": "hidden"
        },
        "launch": {
            "visibility": "hidden"
        },
        "build": {
            "visibility": "default"
        },
        "buildTarget": {
            "visibility": "hidden"
        }
    },
    "cmake.buildBeforeRun": true,
    "cmake.configureOnOpen": false,
}

The important setting here is "cmake.configureOnOpen" which avoids a race condition in VS Code, trying to load and configure the project while not having assigned a CMake kit yet.

Summary

With the above settings, I god rid of these annoying requests of VS Code to re-assign the CMake kit. You still have to activate the selected kit once, and if you still have troubles: VS Code stores the currently selected kit of the project folder not inside the project, but in its global settings see StackOverflow. So if you still see issues, you might need to clean the VS Code global settings, see VS Code: Uninstall completely.

Happy CMaking 🙂

Links

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.