conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8k stars 953 forks source link

[question] Best practice to generate compile_commands.json across deps #12641

Open GrqPnegre opened 1 year ago

GrqPnegre commented 1 year ago

Newbie here... What are some suggested workflows for generating compile_commands.json (a la clangd) for conan projects? For make-based projects I typically build thus bear make ...., whereas for cmake-based projects thus cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .... I'd really like to do this for any deps I'm pulling in, while avoiding mucking-up recipes files.

jcar87 commented 1 year ago

Hi @GrqPnegre

For CMake projects, CMAKE_EXPORT_COMPILE_COMMANDS can also be defined as an environment variable (CMake docs). You could define it in a profile as a [buildenv] (docs here) and that should work when cmake is invoke when building recipes, without modifying the recipe files.

As for bear, this could be more challenging. Does bear make ... only output the compile_commands.json, or does it also transparently proceed with the build? If bear is only used with make, perhaps an option would be to have a script called make that calls bear and the "real" make, but this could be fragile depending on how make is installed.

GrqPnegre commented 1 year ago

Thx @jcar87.

Using [buildenv] is promising. I noticed that cmake writes compile_commands.json to CMAKE_BINARY_DIR. Unfortunately, I needed to make changes to CMakeLists.txt to install compile_commands.json to the root of the package dir.

For your bear comment, I'd need to play with that a bit and see what's lurking.