Say we have make
files (not cmake/premake/ninja etc) for our project that do work for gcc and clang. We want to generate out from them JSON Compilation Database to feed it into clang-modernize
tool. How to do such thing? (is there any parser in clang infrastructure or some script with usage like make CC='cc_args.py gcc' CXX='cc_args.py g++'
or some other tool)?
The compile_commands. json file is a compilation database that consists of an array of “command objects” , where each command object specifies one way a translation unit is compiled in the project.
A compilation database is a JSON-formatted file named compile_commands. json that contains structured data about every compilation unit in your project. You can see an array of entries called command objects.
Right-click on the Visual Studio projectto open the Context Menu. Select the Clang Power Toolsoption. In the opened submenu, choose Export Compilation Database. File Explorer is automatically opened with the JSON Compilation Databaseselected. Watch our video tutorial to see the JSON Compilation Database in action. Conclusion
GitHub - nickdiego/compiledb: Tool for generating Clang's JSON Compilation Database files for make-based build systems. Failed to load latest commit information. Tool for generating Clang's JSON Compilation Database file for GNU make -based build systems. It's aimed mainly at non-cmake (cmake already generates compilation database) large codebases.
Note that the NMAKE generator creates an incorrect compilation database, which is a known issue. The -Mj option writes a compilation entry per input file. You can use it for each file in the project, and then merge the outputs into a JSON-formatted compilation database (see the procedure example ).
Inspired by projects like YCM-Generator and Bear , but faster (mainly with large projects), since in most cases it doesn't need a clean build (as the mentioned tools do) to generate the compilation database file, to achieve this it uses the make options such as -n / --dry-run and -k / --keep-going to extract the compile commands.
I have no personal experience with it but Bear seems to be targeted to your scenario. (It was linked from the clang-modernize site.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With