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.
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.