Compilation Database support for Visual Studio NMake

Operating system:
Windows 10
IDE name and flavor/env:
Visual Studio 2019
SonarLint plugin version:
6.1.0.45943
*** Is connected mode used:**
Yes, to SonarQube.

Support for compilation database was announced last year. I’ve been trying to setup sonar.cfamily.compile-commands=compile_commands.json based on the provided instructions.

Unfortunately, it seems like SonarLint is unable to support the project’s “configuration type”.

Connecting to '[....]'.
Current VS version:
    Visual Studio Professional 2019
    16.9.31129.286
    16.9.3
Loaded settings from "C:\Users\[....]\AppData\Roaming\SonarLint for Visual Studio\settings.json".
Connected to SonarQube '[....]'.
Checking for suppressions...
Number of suppressions found: 3
Initializing the telemetry package...
Finished initializing the telemetry package...
Initializing the notifications package...
Loading notifications settings...
Connected: checking for notifications
Finished initializing the notifications package
[Taint] Initializing taint issues synchronization package...
[Taint] Fetched 0 taint vulnerabilities.
[Taint] Finished initializing taint issues synchronization package.
Initializing the daemon package...
[Open in IDE] Creating request listener...
[Open in IDE] Checking availability of port [....]
[Open in IDE] Request listener created successfully. Listening on port [....].
Finished initializing the daemon package.
**Project's "Configuration type" is not supported.**
**Unable to retrieve the configuration for file '[....].cpp'.**
**    Check the file is part of a supported project type in the current solution.**
Checking for suppressions...
Number of suppressions found: 3

I looked into the SonarLint source code. Based on my research it seems that two configuration options are supported:

  1. MSBuild
  2. CMake

In our case we are using Visual Studio’s NMake to trigger build commands on the CLI. It seems that that results in the “Configuration type” of our project not being recognised by SonarLint, even though the sonar.cfamily.compile-commands is set.

Can anyone provide guidance on steps to take to get a Compilation Database to work in Visual Studio SonarLint when not using CMake?

That announcement relates to using the compilation database in batch analysis i.e. when using the CFamily build wrapper as part of a CI build.

Yes, SonarLint for Visual Studio supports vcxproj files and CMake (although not CMake presets). See the wiki for more information on CMake support.

Workaround: I know nothing about VS support for NMake. However, you could have a look at this post in which another user managed to make SonarLint for VS work with CMake presets by adding a dummy CMakeSettings.json file to point SonarLint to the compilation database.

I have tried that but since SonarLint doesn’t recognise the Project’s Configuration type as CMake, that doesn’t seem to trigger:

Project’s “Configuration type” is not supported.

For reference, this is the CMakeSettings.json I experimented with to make it work.

{
    "configurations": [
        {
            "name": "00_debug|x64",
            "buildRoot": "${workspaceRoot}"
        },
        {
            "name": "01_release|x64",
            "buildRoot": "${workspaceRoot}"
        },
        {
            "name": "02_final|x64",
            "buildRoot": "${workspaceRoot}"
        },
        {
            "name": "03_retail|x64",
            "buildRoot": "${workspaceRoot}"
        }
    ]
}

FYI, the Configuration type in the Visual studio project file looks as follows:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='00_debug|x64'" Label="Configuration">
    <ConfigurationType>Makefile</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PreferredToolArchitecture>x64</PreferredToolArchitecture>
    <CharacterSet>MultiByte</CharacterSet>
    <WholeProgramOptimization>false</WholeProgramOptimization>
    <PlatformToolset>v142</PlatformToolset>
  </PropertyGroup>