Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Installing and Configuring CLion

martijnvandermarel edited this page Feb 20, 2019 · 42 revisions

Motivation

For working with this project, CLion is our recommended IDE and the one used by the developers. The free community edition has all the tools needed to contribute to this project.
You are welcome to use any IDE you want, but we won't be available for troubleshooting if you have any problems with it. If you are convinced another IDE is superior in any way, feel free to write an installation guide for that IDE.

Install CLion

  • Download CLion and install.
  • Install compiler, this option is only needed with Windows
    • Open CLion.
    • ctrl + alt + s (open settings).
    • Search for: toolchains.
    • Select "MinGW" as environment.
    • This is probably not installed, download and install this, restart CLion after the installation.
    • If the path is not correct set this path to MinGW (this probably looks like C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32 )

If there are no errors and the run is successful, everything is set-up correctly!

Fork the repository

Launch CLion, and create a new project by clicking on VCS--> Check out from Version Control, and select Git.
If you want to create a Pull Request, please fork the repository at https://github.com/project-march/march-iv and clone your own fork. Run in the march_ws directory of the project the following command in your terminal

catkin_make

However, sometimes catkin_make is building packages in the wrong order. A simple fix is to run catkin_make multiple times. Or use catkin_make --pkg {packge_name} to build a specific package, which is missing.

Source the source files

In case you haven't already, make sure that you source ROS correctly, with the following command

source /opt/ros/kinetic/setup.bash

In order for catkin to know where your files are located, you have to provide a source. You do this with source ~/path/to/the/repo/march-iv/march_ws/devel/setup.bash.
This needs to be done for every new terminal you start, so it is advised to add this command to your ~/.bashrc, which is ran every time a new terminal is started.

Unfortunately, this is also needed before you launch CLion. We provide a quick launchscript so you don't have to do it manually:

source ~/path/to/the/repo/march-iv/march_ws/devel/setup.bash
~/path/to/clion/clion-2018.2.4/bin/clion.sh

Put this in a CLion.bash file and make it executable with sudo chmod +x CLion.bash. After this you can make it double-clickable.

Install the Hatchery Plugin

It is advised to install the Hatchery Plugin as it has ROS support.
You can install Hatchery directly through the IDE, via File | Settings | Plugins | Search for "hatchery".

Setup auto-formatting in CLion

Setting up a shortcut for auto-formatting code will save time when developing the exoskeleton. The styleguide check is mandatory for passing the build process.

  • Install clang-format with sudo apt-get install -y clang-format-3.8.
  • Go to File->Settings->Preferences->Plugins and search for ClangFormatIJ. Install this plugin. It installs the context menu to invoke locally installed clang-format for a file or for a selection.
  • Go to Tools->clang-format and change the clang-format-binary to clang-format-3.8.
  • The path can stay empty.
  • Go to Keymap->Plugins->ClangFormatIJ->Reformat Code with clang-format and setup a keyboard shortcut.

Your code is now properly formatted when you trigger your shortcut!

Set copyright header and include guard

A copyright header in each file is mandatory to pass the build process.

  • Settings -> Editor -> File and Code Templates
  • Select Scheme: Project
  • Select C++ Class Header`` under the files` tab
  • Replace the content with the following code:
#parse("C File Header.h")
#[[#ifndef]]# ${INCLUDE_GUARD}
#[[#define]]# ${INCLUDE_GUARD}

${NAMESPACES_OPEN}

class ${NAME} {

};

${NAMESPACES_CLOSE}

#[[#endif]]#  // ${INCLUDE_GUARD}

  • Click Apply
  • Go to the Includes tab and select the C File Header
  • Replace content with the following code:
#if ($HEADER_COMMENTS)
// Copyright $YEAR Project March.
#end

  • Apply and click OK

CLion unresolved references in python.

  • Make sure the CMake is loaded (open the top level CMake and click the warning if it's there).
  • Mark the march_state_machine/src as Project Sources and Headers. The issue should be resolved now and CLion should find its imports correctly.

CLion can't find headers to include while catkin_make passes

change your cmake_build location to the build location used by ROS with the following steps:

  • Go to File --> Settings --> Build, Execution, Deployment --> CMake
  • Set the generation Path to ~/<link/to/the/repo>/march-iv/march_ws/devel and apply
  • Add the CMake option -DCATKIN_DEVEL_PREFIX:PATH=~/<link/to/the/repo>/march-iv/march_ws/devel
  • Finally you should right-click on your top level CMakeList.txt file in CLion and select "Reload CMake Project"

Source: https://answers.ros.org/question/284786/setup-clion-with-ros/

Clone this wiki locally