colcon / colcon-cmake

Extension for colcon to support CMake packages
http://colcon.readthedocs.io
Apache License 2.0
16 stars 25 forks source link

Generate compile_commands.json #76

Closed bergercookie closed 4 years ago

bergercookie commented 4 years ago

Hi there,

Is there a way to generate a compile_commands.json file for the ROS workspace that colcon is used for? I've tried passing --cmake-args=-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON but that seems to only generate compile_commands for very few of the packages in my workspace as well as lots of warnings like the following:

Starting >>> gtest_vendor
--- stderr: gtest_vendor
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_EXPORT_COMPILE_COMMANDS

---

I've also tried generating the compile_commands.json using Bear but that resulted in an empty compile_commands file.

Any pointers?

dirk-thomas commented 4 years ago

Is there a way to generate a compile_commands.json file for the ROS workspace

Yes, the feature was implemented in #69 and that change is available as of colcon-cmake version 0.2.20 as referenced in that ticket. So you likely have an older version.

lots of warnings like the following:

You might want to try the CMake option --no-warn-unused-cli (see https://cmake.org/cmake/help/latest/manual/cmake.1.html).

Assuming that using the latest released version will resolve your question I am going to close this ticket.

bergercookie commented 4 years ago

I see. I would expect the --cmake-args=-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON to create a single compile_commands.json file at the root of the build directory. This way I would be able to feed tools like Sourcetrail with that one file instead of all the individual JSON files generated.

I mean, it's not too hard on my end to just aggregate them into a single file, it would just be nice for colcon to do it for me in the first place.

Do you think this is a feature worth having in colcon? I could take a look in implementing it.

bergercookie commented 4 years ago

I mean, it's not too hard on my end to just aggregate them into a single file, it would just be nice for colcon to do it for me in the first place.

Aplologies, I misunderstood your answer. The PR you linked is doing exactly that. I think I have an outdated version of colcon then!