premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.22k stars 620 forks source link

What's the best way to add support for clang's json compilation database? #346

Closed tarruda closed 8 years ago

tarruda commented 8 years ago

Hi

I just started experimenting with premake and I'm loving it so far, thanks for this great project!

One thing I like about cmake is that it can emit clang's json compilation database, which is a simple json file that contains a list of compilation commands for individual files in the project. This database can be used by text-editors to provide code assist features(syntax/semantic highlight, semantic completion, ...). The format is described here: http://clang.llvm.org/docs/JSONCompilationDatabase.html

What's the best way to implement this feature in a way that is easily reusable in other premake projects? If you give me some pointers I can give it a shot. Specifically, this is what I'm looking for:

tvandijck commented 8 years ago

Well, the best way to do this would probably be by making a new "action" in a new module.

More about actions here: https://github.com/premake/premake-core/wiki/Adding-a-New-Action

and there is plenty of modules as examples here: https://github.com/premake/premake-core/wiki/Modules

Then to write json, I would suggest just writing text, just like most other actions do, importing a json library, while there is pure lua versions seems complicated for simply writing a json file. Parsing is another story obviously...

tarruda commented 8 years ago

Thanks for the pointers, I have a proof of concept implementation here: https://github.com/tarruda/premake-export-compile-commands

Would you mind reviewing it? There are a few things that still need to improve, in particular, how do I get flags for files with custom compilation options that differ that differ from the rest of the project?

tvandijck commented 8 years ago

Well, I don't know much about the json compilation database, but this module looks fine to me.

As for how to get flags for files individually, I don't know exactly, however the vs2010_vcxproj.lua script does something similar for the visual studio projects it outputs, so maybe you can use that as a reference to figure that out... I think the "m.emitFiles" method in that file would be a good start...