Unfortunately, a compilation database is the only way.
Fortunately, generating a compilation database is easy.
If you exhausted the first and the second option in our doc, you are stuck with the third option:
Generating Compilation Database Using a Custom Script.
Compilation databases are really simple, you only have to provide the
command to build your file, the
directory from which this command is executed, and the path to the
file you are compiling.
You can take 3 approaches to do this.
Incremental and lightweight local approach
If your project mostly compiles the same way, you can start with a compilation database with one entry that you add manually and start from there. We have an algorithm behind the scene to deduce the compile command for files that don’t have entries in the compilation database based on available entries.
You just have to make sure that the provided entry is valid by executing the
directory and making sure that the output is a successful compilation to
After that, you can enable
S2260 to detect the quality of the analysis as indicated by the doc and add more entries to your compilation database incrementally.
I would recommend this approach if you are looking for a local and quick solution.
build system based script
It is easy to generate a compilation database for one build system, but it is hard to generate it consistently across build systems. You can simply modify your build system to add an entry to the compilation database every time it calls the compiler.
This is recommended if your build system is customizable and extendable.
build-wrapper based script
if you already have build-wrapper.json for your project, you can write a quick script to transform it into a compilation database.
build-wrapper.json is a superset of compile_commands.json. It should be easy to write a script by looking at your specific `build-wrapper.json and mapping it.
command = concatenated
file can be extracted from
command with one entry for each compiled file.
Let me know if you have further questions,