Support VSCode cmake-tools plugin

  • Operating system: Win10
  • IDE name and flavor/env: VSCode + cmake-tools plugin
  • SonarLint plugin version: 3.4.1
  • Is connected mode used: Irrelevant

People use CMake to build C++ projects for different architectures/oses/modes. This results in different paths for the compile_command.json file.
SonarLint should take this into account and switch the referenced file based on the used CMake Kit or Preset used by cmake-tools.

This can be done by evaluating the cmake-tools command: ${command:cmake.buildDirectory}. See: Get path to Build dir / compile_commands.json for configuring other extensions · Issue #2528 · microsoft/vscode-cmake-tools · GitHub, vscode-cmake-tools/ at main · microsoft/vscode-cmake-tools · GitHub

Sonarlint could also autodetect if this is a CMake project and when cmake-tools is installed, use this as the default search path.

Hi again @KUGA2,

I am not a user of cmake-tools so I want to understand your need first.

I gave a quick try and it appears to me that if you change the kit or variant, the compile_commands.json file is modified in place. In your use case do you have multiple compile_commands.json files in different directories ? Could you explain how you achieve that ?


You can (and you should to avoid rebuilds!) specify different outputs directories. I can provide you a basic example if you want. Do you prefer Linux or Windows?

Hint: See binaryDir
PS: I think you should always prefer presets over Kits/Variants, because presets is supported by the CMake developers and the other thing was a solution by the plugin, before presets were implemented.

@Damien_Urruty Do you want a demo project or not? Windows or Linux?