9.2 CDB creation
The shell
compile˙commands.json file can be generated in various ways. For example, the build system CMake has built-in support for generating a compilation database. Some tools can also generate this file from Makefiles or other build systems. There are even tools such as Bear and intercept-build that can generate a CDB by intercepting the actual compile commands as they are run.
So while the term is commonly associated with Clang and LLVM-based tools, the concept itself is more general and could theoretically be used by any tool that needs to understand the compilation settings for a set of source files. We will start with CDB generation using CMake, one of the most popular build systems.
Generating a CDB with CMake
Generating a CDB with CMake involves a few steps:
First, open a terminal or command prompt and navigate to your project’s root directory.
Then, run CMake with the
-DCMAKE
_EXPORT
_COMPILE
_COMMANDS=ON
option, which instructs CMake to create...