Hey guys,
I have been using SonarLint in VS for quite some time now, and I really like the suggestions to improve code quality.
It all works well if you open a .sln file for a C/C++ project.
However in VS2022 Microsoft started supporting CMakePresets.
To use CMakePresets in VS you have to open the project as a folder. However when opening the project as a folder Sonar Lint does not seam to detect the language automatically
I’m getting
[CMake] Could not locate compilation database at 'C:\...\out\build\Windows Ninja Debug\compile_commands.json'. Make sure that your project is configured correctly.
See https://github.com/SonarSource/sonarlint-visualstudio/wiki for more information.
Unable to retrieve the configuration for file 'C:\...\app\Testclient.cpp'.
Check the file is part of a supported project type in the current solution.
How can I set the project type manually?
Operating system: Windows 10
IDE name and flavor/env: VS 2022
SonarLint plugin version: 5.5.0.43817 (newest at the time of writing)
Is connected mode used:
Connected to SonarCloud or SonarQube (and which version):
Unfortunately we do not support CMakePresets at the moment. It is a known limitation and we have a ticket at our backlog about it.
For setting the project up manually you can refer to our documentation.
Hope these are enough, please do not hesitate to follow up if you need further assistance.
Hey Ugras,
thank you for your quick feedback.
I added set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
and the compile_commands.json is properly generated within the build folder.
However in our porject we changed the build folder
Our build dir is located under
You’ll need to provide a buildroot property that either points to an environment variable, or uses macros which are supported. $(sourceParentDir) and ${presetName} are not supported.
You should’ve added this to CMakeSettings.json . But because you’re using CMakePresets you do not have this file.
A workaround would be adding the “CMakeSettings.json” for just SonarLint and maintaining it alongside with the “CMakePresets.json”.
According to Microsoft Docs if both CMakePresets.json will take precedence for configuring the build. The dummy CMakeSettings.json is just there to allow SonarLint to find the compilation database. (see table below)
Hey Ugras,
thank you for your quick support. Adding a CMakeSettings.json just for sonarlint worked nicely. Although It would make things easier when Sonarlint supports presets