ROS2 + Clion

I am just posting this here for completeness (thx @dirk-thomas) and complement to Redirecting to Google Groups :

In ROS2 you can not have (yet?) your full workspace being imported in your IDE. However what you can have is individual packages and an environment for all dependencies. Say for e.g. rclcpp this what you do to get it imported into Clion:

You first need to compile ros_ws with ament: GitHub - ros2/ros2: The Robot Operating System, is a meta operating system for robots..

source ~/ros_ws/build/rclcpp/cmake__build.sh #this will setup your environment clion # go to File => Open => ~/ros2_ws/src/ros2/rclcpp => click OK

That’s it!

3 Likes

I have now also found a way to load a whole ROS2 workspace into Clion. At least code browsing is now made easy.

a) You first need to compile ros_ws with ament: https://github.com/ros2/ros2/wiki/Linux-Development-Setup.

b) Second you need to prepare you top level CMakeLists.txt file:

  • cd ros_ws
  • find src -name CMakeLists.txt -not -name setup.py -print0 | xargs -0 -n1 dirname | sort --unique
  • after I manually removed all fastRTPS subfolders and test subfolders
  • I also skipped all ament_* folders
  • I used emacs to replace ./ with add_subdirectory and to add ) at the end of every line (replace-string, C-q C-j)

c) Put this CMakeLists.txt into your ros_ws.

d) Comment out the following line in ament_cmake_core/ament_cmake_uninstall_target-extras.cmake:

=== ./src/ament/ament_cmake (git) ===
diff --git a/ament_cmake_core/ament_cmake_uninstall_target-extras.cmake b/ament_cmake_core/ament_cmake_uninstall_target-extras.cmake
index f6805e8..c89f289 100644
--- a/ament_cmake_core/ament_cmake_uninstall_target-extras.cmake
+++ b/ament_cmake_core/ament_cmake_uninstall_target-extras.cmake
@@ -32,6 +32,6 @@ if(AMENT_CMAKE_UNINSTALL_TARGET)
   )

   # register uninstall target to run generated CMake script
-  add_custom_target(uninstall
-    COMMAND ${CMAKE_COMMAND} -P "${AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT}")
+#  add_custom_target(uninstall
+#    COMMAND ${CMAKE_COMMAND} -P "${AMENT_CMAKE_UNINSTALL_TARGET_UNINSTALL_SCRIPT}")
 endif()

e)

$ source ~/ros_ws/build/rclcpp/cmake__build.sh #this will setup your environment
$ clion # go to File => Open => ~/ros2_ws/CMakeLists.txt => click OK

f)
Disable BUILD_TESTING:

In Clion File => Settings => Build, Execution, Deployment => CMake => Cmake options: -DBUILD_TESTING=OFF

g)
You can right click on the Clion project => Reload CMake Project. There will be some warnings about missing OpenSplice dependecies which you can safely ignore.

1 Like