Discussion:
[CMake] Make CMAKE_EXPORT_COMPILE_COMMANDS not default?
Martin Zenzes
2013-12-02 14:55:15 UTC
Permalink
Hi,

is there a reason why the cmake-option "CMAKE_EXPORT_COMPILE_COMMANDS"
is not enabled by default? It was exposed as an option in 2011 [1], a
few days after adding it initially. It can be enabled manually by adding
"set(CMAKE_EXPORT_COMPILE_COMMANDS ON)" into the CMakeLists.txt or
giving the option on the commandline as in "mkdir -p build && cd build
&& cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=on"

The option generates a file "compile_commands.json", containing the
exact calls for all translation units of the project in machine-readable
form. Benefits:

- easier debugging of build process. Not always necessary to search
manually in the output of `make -B VERBOSE=1|less`, instead go directly
to the compile_commands.json
- allows using this file for code-completion tools like clang_complete
[2] or YouCompleteMe [3]in projects out of the box

The file is only generated for UnixMakefiles and the Ninja buildsystem.

Greetings

[1]
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5674844de4b74d0b66cfc6b8237e631702c43637
[2] https://github.com/Rip-Rip/clang_complete
[3] https://github.com/Valloric/YouCompleteMe
Alexander Neundorf
2013-12-08 14:36:52 UTC
Permalink
Post by Martin Zenzes
Hi,
is there a reason why the cmake-option "CMAKE_EXPORT_COMPILE_COMMANDS"
is not enabled by default? It was exposed as an option in 2011 [1], a
few days after adding it initially. It can be enabled manually by adding
"set(CMAKE_EXPORT_COMPILE_COMMANDS ON)" into the CMakeLists.txt or
giving the option on the commandline as in "mkdir -p build && cd build
&& cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=on"
The option generates a file "compile_commands.json", containing the
exact calls for all translation units of the project in machine-readable
what is actually the purpose of this feature ?
It sounds to me a bit more like it should be an additional "extra" generator,
i.e. generate makefiles/ninja files and additionally this json file.

Alex
Stephen Kelly
2013-12-08 15:38:26 UTC
Permalink
Post by Alexander Neundorf
It sounds to me a bit more like it should be an additional "extra"
generator, i.e. generate makefiles/ninja files and additionally this json
file.
Hmm, the first thing I thought when I saw your kate project feature was that
it should be implemented more like CMAKE_EXPORT_COMPILE_COMMANDS.

Otherwise there's a combinatorial explosion of extra generators. There would
have to be a 'MinGW Makefiles - Kate Project - ExportCommands' generator
etc.

I don't think 'extra generator' axis is a good extension vector for
generation features.

Thanks,

Steve.
Alexander Neundorf
2013-12-08 20:55:19 UTC
Permalink
Post by Stephen Kelly
Post by Alexander Neundorf
It sounds to me a bit more like it should be an additional "extra"
generator, i.e. generate makefiles/ninja files and additionally this json
file.
Hmm, the first thing I thought when I saw your kate project feature was
that it should be implemented more like CMAKE_EXPORT_COMPILE_COMMANDS.
Otherwise there's a combinatorial explosion of extra generators. There
would have to be a 'MinGW Makefiles - Kate Project - ExportCommands'
generator etc.
this could easily be avoided by modifying it so that the user can choose them
freely, i.e. first choose the main generator, and then add the extra generator
if suitable, instead of having only the "complete" generators ("Makefile +
CodeBlocks") to choose from.

Alex

Loading...