# CLion

[CLion](https://www.jetbrains.com/clion/) is a JetBrains Integrated Development Environment (IDE) for C++. While normally a paid product, like with other JetBrains IDE, CLion can be registered with a university email. Please also check [the tutorial provided by JetBrains](https://www.jetbrains.com/help/clion/ros-setup-tutorial.html) for setting up CLion with ROS.

Because CLion can load `CMakeLists.txt` project directly, and because it is a JetBrains product and naturally loads Python packages and modules, it fits nicely with ROS packages. In order for package indexing to work, however, some configuration is necessary.

* First, you must add a directory as a new project. This can either be the entire catkin workspace or the `src` folder in that workspace.
* In order to load the correct ROS environments, it's necessary to launch clion from the terminal, with the appropriate `setup.bash` (or `setup.zsh`) loaded.

## C++ configuration

The generation path and the `catkin` build destination must be specified. In the `File --> Settings` dialog box, select the `Build, Execution, Deployment --> CMake` menu, and:

* add `-DCATKIN_DEVEL_PREFIX:PATH=/path/to/catkin/workspace/devel` to the `CMake options` field
* add `/path/to/catkin/workspace/build` to the `Generation path` field

![C++ project settings](https://3442986010-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Legv9tF01oE_ZuKIK_3%2F-LfQUlOjc6Ut6WpVTlo2%2F-LfQWgT4CGou9Gv_rCYg%2Fclion_project_settings.png?alt=media\&token=8757e6f0-d08e-4dc8-b79a-f6fa76b518a1)

## Python configuration

In order for CLion to index Python packages, you must point to the correct Python interpreter. Since ROS uses a Python 2 system interpreter, this needs to also be used for your project (in future ROS versions this will hopefully change). In the `Build, Execution, Deployment --> Python Interpreter` setting menu, if the correct interpreter is not automatically detected, click on the gear icon to add a new interpreter.

![Python project settings](https://3442986010-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Legv9tF01oE_ZuKIK_3%2F-LfQWtaU4qUw0CP2p6q8%2F-LfQX3ScMDuvPsoCb10g%2Fclion_project_settings_python.png?alt=media\&token=1fb0c625-0e55-430b-967c-8f5b0fdeafcd)

## Load `CMakeLists.txt`

After the above configurations, you're ready to load ROS `CMakeLists.txt` projects. Navigate to the package that you want to work on, right click on the `CMakeLists.txt` file, and click `Load CMake Project`.

![Load CMake project](https://3442986010-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Legv9tF01oE_ZuKIK_3%2F-LfQWtaU4qUw0CP2p6q8%2F-LfQXOo44ZhBv7CkhkFv%2Fclion_load_project.png?alt=media\&token=f59c85b5-cfe2-4ecd-a5de-257e2c242285)
