Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate clang compilation database for a Visual Studio project

Visual Studio was added a lot of support for Clang.

I want to use clang-tidy.exe for a Visual-Studio project. In order to do that I need the JSON "compilation database".

Is there some way to export this database from a visual studio (2015) project?

like image 468
user972014 Avatar asked Sep 30 '16 18:09

user972014


People also ask

What is compilation database?

A compilation database is a JSON file, which consist of an array of “command objects”, where each command object specifies one way a translation unit is compiled in the project. Each command object contains the translation unit's main file, the working directory of the compile run and the actual compile command.

What's Compile_commands json?

A compilation database is a JSON-formatted file named compile_commands. json that contains structured data about every compilation unit in your project.


2 Answers

To export the JSON compilation Database you can use the Clang Power Tools VS extension.

All you need to do is to select your VS project from Solution Explorer, open the context menu by pressing right-click on it, and then search for Clang Power Tools. In the submenu search for the Export Compilation Database option. The JSON compilation database will be automatically generated for you.

More details about this feature can be found in this article.

The extension is compatible with Visual Studio 2015, 2017 and 2019.

like image 170
Ionut Enache Avatar answered Oct 04 '22 11:10

Ionut Enache


I've bumped into your question whilst searching for an answer to this very problem. This is what I have found so far:

  • SourceTrail provides a Visual Studio extension which is able to create a compilation database. See also this discussion. I have no experience with the extension, but it seems to tackle this problem.
  • compdb is a python script with all sorts of utilities for compilation databases. AFAIK it does not yet support visual studio, but it would be a great place to add support for this functionality.

HTH.

like image 42
Marco Craveiro Avatar answered Oct 04 '22 12:10

Marco Craveiro