Skip to content

Instantly share code, notes, and snippets.

@srathi-monarch
Last active July 8, 2024 05:09
Show Gist options
  • Save srathi-monarch/f0eac2c732a87fc389b4291a651cea78 to your computer and use it in GitHub Desktop.
Save srathi-monarch/f0eac2c732a87fc389b4291a651cea78 to your computer and use it in GitHub Desktop.
Setup catkin with unified compile commands for all packages
#! /usr/bin/bash
# Run: `catkin config --append-args --cmake-args "-DCMAKE_EXPORT_COMPILE_COMMANDS=1"` to setup catkin correctly.
export ROS_WS_DIR=`catkin locate` || { echo "Not in a catkin workspace." ; exit 1; }
source /opt/ros/noetic/setup.bash
[[ -f ./devel/setup.bash ]] && source ./devel/setup.bash
echo -ne "[\n]" > $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json
unalias catkin_build
catkin_build() {
catkin build $@
( shopt -s nullglob && cat $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json $ROS_WS_DIR/build/*/compile_commands.json $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json | sed 's:\]\[:,:' > "${ROS_WS_DIR}/src/compile_commands.json" ; )
# zsh only
# cat $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json $ROS_WS_DIR/build/*/compile_commands.json(N) $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json | sed 's:\]\[:,:' > "${ROS_WS_DIR}/src/compile_commands.json"
}
# Now use catkin_build to build. Open ./src/compile_commands.json in Clion to view the entire workspace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment