Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.
Jason Wang edited this page Jul 31, 2018 · 6 revisions

Getting started with JetBrains CLion in catkin

Why use CLion?

In the end it's a matter of choice, but if you need justification:

  • Some people (me, for example) like it more than Eclipse
  • Seems to have much faster indexing / overall experience than Eclipse
  • Crashes less often, handles a lot of opened files faster
  • Works very good with Python, too (PyCharm is integrated)
  • Very good out-of-the box git integration

Initial set-up

  1. Download and install the latest CLion from jetbrains
  2. You need to launch CLion with your workspace environment sourced;
source ~/catkin_ws/devel/setup.bash
sh <YOUR_JETBRAINS_INSTALL_DIR>/bin/clion.sh
  1. Alternative solution would be to add source ~/catkin_ws/devel/setup.bash to the end of ~/.bashrc. Then you can edit CLion desktop file so that it doesn't have to be launched from terminal every time. The following example changes it for one user, if you have installed the desktop file for all, you have to edit /usr/share/applications/jetbrains-clion.desktop. If neither File exists, open up Clion and hit Tools > Create Desktop Entry first.
$ vi ~/.local/share/applications/jetbrains-clion.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=CLion
Icon=/opt/clion-2017.3/bin/clion.svg
Exec=bash -i -c "/opt/clion-2017.3/bin/clion.sh" %f
Comment=The Drive to Develop
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-clion

Opening catkin packages (remember to source devel/setup.bash)

File > Open Select the CMakeLists.txt and open as Project (or open the folder containing CMakeLists.txt)

Headers not shown at first

QT-Creator users have come up with a fix, which is copy pasted below:

Since the files shown in project view are only CMake dependencies, the headers will not show up at first. Add them by adding the following to the CMakeLists, then right-click the project and Run CMake again:

#############
# QTCREATOR #
#############
FILE(GLOB_RECURSE LibFiles "include/*")
add_custom_target(headers SOURCES ${LibFiles})

Tips & Tricks

Solarized colorscheme

Arguably one of the best color schemes:

TODO

Google Code-Style

If you want to use consistent C++ formatting use Google Code-Style:

TODO

One big project instead of many small projects

Since you can only open one project per window every time, which is annoying, you can use a meta CMakeLists.txt that will recursively build all packages, which in turns make CLion opens your whole catkin workspace as one project.

TODO: Link to meta CMakeLists.txt

Note that if you add more packages, you have to manually reload the project.

Caveat: Your workspace has to contain only catkin packages. Solution: If you have non-catkin packages, create a separate catkin workspace, say catkin_ws_base, put the non catkin packages there, and then extend from that (catkin config --extend catkin_ws_base). Now everything should be working.