colcon / colcon-cmake

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

Unable to generate compile_commands.json on Windows #115

Closed Scotty1701 closed 1 year ago

Scotty1701 commented 2 years ago

I'm attempting to generate a compile_commands.json file for use with clangd, however the file is not generated (neither on a package level nor the workspace level). Attempting to build the turtlesim package from ros_tutorials with

PS D:\Documents\dev_ws> colcon build --merge-install --event-handlers console_cohesion+ --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

gives the following warning:

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_EXPORT_COMPILE_COMMANDS

My platform is Windows 10 with Ros2 Foxy installed from the aka.ms/ros Chocolatey package.

I build colcon from source following the instructions in the docs, and colcon version-check gives:

colcon-cd 0.1.1: up-to-date
colcon-cmake 0.2.26: up-to-date
colcon-core 0.7.1: up-to-date
colcon-defaults 0.2.6: up-to-date
colcon-devtools 0.2.3: up-to-date
colcon-library-path 0.2.1: up-to-date
colcon-metadata 0.2.5: up-to-date
colcon-mixin 0.2.1: up-to-date
colcon-notification 0.2.13: up-to-date
colcon-output 0.2.12: up-to-date
colcon-package-information 0.3.3: up-to-date
colcon-package-selection 0.2.10: up-to-date
colcon-parallel-executor 0.2.4: up-to-date
colcon-pkg-config 0.1.0: up-to-date
colcon-powershell 0.3.7: up-to-date
colcon-python-setup-py 0.2.7: up-to-date
colcon-recursive-crawl 0.2.1: up-to-date
colcon-ros 0.3.22: up-to-date
colcon-test-result 0.3.8: up-to-date
colcon-zsh 0.4.0: up-to-date

Attempting the same in an Ubuntu 20.04 with identical colcon versions correctly generates compile_commands.json on a package and workspace level.

I also tested on windows with the change proposed in #114, however this did not result in any changed behavior. Additionally, I tested ommitting the --merge-install option, which produced no change for either platform.

Scotty1701 commented 1 year ago

This CMake flag is only implemented for Makefile Generators and Ninja (https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html). Ninja is supported on Windows, so I recommend using that instead of the default generator.