Clion Open Source

broken image


The benefit is that you control each and every little detail, and use the official and stable platform API, which is also open-source. Of course, the downside is that it's a huge amount of work with little to no relation to the real task - making a new native debugger work in CLion. (CLion, Eclipse e.t.c) is straightforward. Using lazy algorithms there is virtually zero overhead in benchmarks and minimum overhead in execution time. Libinstrument tries to be as non-intrusive as possible, while trying to help the developer offering basic reflection. There are Unit Tests for each class and method, testing is driven with CTest. Open Source 2D-CAD LibreCAD is a free Open Source CAD application for Windows, Apple and Linux. Support and documentation are free from our large, dedicated community of users, contributors and developers. You, too, can also get involved! CLion is also available as a snap package. If you're on Ubuntu 16.04 or later, you can install CLion from the command line. Sudo snap install clion -classic.

CLion is a great IDE. Lately, I've been using it to develop some games with Unreal Engine 4. I've created a step by step guide on how to do this. You can get and install CLion from https://www.jetbrains.com/clion/.

If using MS Windows

CLion doesn't come with a compiler. If you are going to be doing any other C or C++ work with it you need one. At the time of writing, you can use the MSVC compiler changing some registry settings, but I recommend installing a better toolchain.

The easiest way I've found to setup the compiler is to download and install MSYS2 from http://www.msys2.org/. Once that is done just open 'MSYS2 MinGW 64-bit' from the Start Menu and run:

Open CLion and go to Configure > Settings… > Build, Execution, Deployment > Toolchains and add a new Toolchain. Use this settings:

  • Name: MinGW
  • Environment: MinGW
  • Path: C:msys64mingw64

Wait a few seconds for it to detect the compiler and set these values:

  • C Compiler: C:/msys64/mingw64/bin/clang.exe
  • C++ Compiler: C:/msys64/mingw64/bin/clang++.exe

Then set it as default (move it to the top of the list) and just click OK.

If using Linux / MacOS

You are ready to continue.

UE4 Plugin for CLion (for UE4 >= 4.19)

Just continue to 'Generating the CMake project file' down below.

UE4 Plugin for CLion (for UE4 >= 4.16, < 4.19)

Next you need to install the CLionSourceCodeAccess plugin. If using a git repo just go to your project folder and run:

Lear more about git submodules here. If you are not using git, or don't want to use submodules, download the plugin from https://github.com/dotBunny/CLionSourceCodeAccess/archive/master.zip and extract it to the Plugins folder (create that folder if it doesn't exist). In any case you should end up with Plugins/CLionSourceCodeAccess/CLionSourceCodeAccess.uplugin and other related files.

After that just open the your UE4 project and let it compile the plugin. You need to set a couple more settings. Go to Edit > Project Settings… > Plugins > CLion and enter the following:

  • C Compiler: C:/msys64/mingw64/bin/clang.exe
  • C++ Compiler: C:/msys64/mingw64/bin/clang++.exe
  • CLion executable: Select your clion.exe
  • Mono path: You need this for Linux/MacOS

There's more information about this plugin on https://github.com/dotBunny/CLionSourceCodeAccess. You can also get it from the UE4 marketplace at https://www.unrealengine.com/marketplace/clion-integration, but I haven't tested that one.

UE4 Plugin for CLion (for UE4 4.15)

For UE4 4.15 follow the previous procedure but replace the following items:

Clion open source license
  • Git repo: https://github.com/cesarizu/CLionSourceCodeAccess.git
  • Download link: https://github.com/cesarizu/CLionSourceCodeAccess/archive/master.zip

Before opening CLion you need to change one file: Intermediates/ProjectFiles/Definitions.cmake. From that file, delete the line that reads:

You need to do this every time you run File > Generate CMakeLists.

Generating the CMake project file

The next step is generating the CMakeLists.txt file that CLion can open. For that just click on File > Generate CMakeLists. You need to do this every time you add or remove classes from your project.

You can now click on File > Open CLion and the project will open. Finally to open CLion automatically when you double click on any class in the UE4 editor, navigate to Edit > Editor Preferences… > General > Source Code and change the Source Code Editor there.

Installing the Unreal Engine 4 SDK Support for CLion

There's a plugin to get some extra functionality on CLion when working on UE4 projects. This will get rid of errors on UPROPERTY, UCLASS, USTRUCT and similar macros. On CLion go to File > Settings… > Plugins then click on Browse Repositories… and install Unreal Engine 4 SDK Support.

And voila! you can now benefit from the multiple features that CLion offers over other IDEs.

If there's anything on this guide that doesn't work or is incorrect, please let me know.

References

EVERY SETUP STEP IN THIS DOCUMENT IS CRITICAL TO GET CLION WORKING PROPERLY.Read carefully, and do not skip anything.

The Bazel plugin for CLion does not support macOS, perhttps://github.com/bazelbuild/intellij/issues/109

This guide describes how to set up Drake in the JetBrains CLion IDE on Ubuntu.

First, you must install Bazel and build Drake with Bazel, followingthe Drake Bazel instructions.

To use Drake with CLion, your Drake checkout must be named drake.

Installing CLion

  1. Go to https://www.jetbrains.com/clion/download/. Look for 'Other versions'and download the appropriate version of CLion (see below).
  2. Install CLion. Exact steps depend on your platform, but it'sstraightforward. Just using defaults for everything is fine. You now have a30-day trial version of CLion. Either try it out as is, or get a freeacademic license here.

The most recent versions that we have tested for compatibility are:

  • Ubuntu 18.04
  • Bazel 3.0.0 (6 April 2020)
  • CLion 2019.3.6 (5 May 2020) with:
    • Bazel plugin 2020.06.01.1.0 (15 June 2020).

Many versions of the above (Bazel / CLion / Bazel plugin) are not compatiblewith each other. We strongly suggest using only the versions shown above, whenworking with Drake.

Upgrading CLion

Users upgrading from a previous version of CLion should do the following:

Source
  1. To have your Unity launcher CLion icon point to the correct version,run locate jetbrains-clion.desktop and edit the located file. If morethan one file is located, you may want to consolidate to a single launch filein your user directory, typically ~/.local/share/applications.
  2. Uninstall the previous version of the Bazel plugin and update to the latestversion. See Installing the Bazel Plugin.

Note: It is not necessary to import your project into a new CLion project.Overwriting the old project is appropriate.

Girl sketch full body

Installing the Bazel Plugin

To use Bazel in CLion, you must install a plugin supplied by Google. Toinstall the plugin, open Settings (either Welcome > Configure >Settings or File > Settings), select Plugins, and press the Browserepositories button. Locate and install the Bazel plugin. You will beprompted to restart CLion.

To use Drake in CLion you must use Drake's bazel wrapper.Open Settings > Bazel Settings. For Bazel binary location select thepath to drake/tools/clion/bazel_wrapper from any recent Drake source tree(it doesn't have to match the current project open in CLion).

Setting up Drake in CLion

CLion will invoke Bazel to build Drake, including the external dependenciesspecified in the WORKSPACE file.

  1. File > Import Bazel Project
  2. Select Workspace: Use an existing Bazel workspace, and provide the path toyour drake directory.
  3. Select Project View: choose 'Import project view file', andselect the file drake/.bazelproject
  4. Project View: Pick a project data directory of your choice for theCLion project files. It must not be a subdirectory of drake.
  5. (Advanced) Project View: If you only wish to develop a subset of Drake,you can specify only those files and targets in the project view file.Most users should leave it as-is.
  6. Click 'Finish'. CLion will begin ingesting the Drake source, buildingsymbols, and compiling Drake. This will take several minutes.

Building and Running Targets

To build all of Drake with default Bazel options, selectBazel > Build > Compile Project.

To build or run a specific target go to Run > Edit Configurations. Click+ to create a new Bazel command. Specify the configuration name and Bazeloptions. The Target expression specifies the actual code (library, binary,and/or test) that you want to run. To learn more about target expressions, seethe Bazel manual.Once you've created a configuration, you can launch it from the Run menu.

To run a specific target in the debugger, create a configuration as above,using the bazel run command. Then launch it from Run > Debug.

Keeping CLion Up-to-Date with the Bazel Build

Clion open source free

Changes to BUILD files can add or remove source files from the Bazel build.To propagate those changes into the CLion project structure, selectBazel > Sync Project With BUILD Files.

Git Integration

CLion provides a user interface for Git, which you can enable in the VCSmenu. It automatically detects all Git roots within the workspace. This willinclude bazel-drake, which is a Bazel-internal detail. Bazel editsthe contents of that directory for its own purposes, and those changes willspuriously appear in the CLion UI as changes that need to be committed. To makeCLion ignore bazel-drake, enable Git integration under the VCStab, then go to File > Settings. Select the Version Control menu itemdirectly (not one of the subtopics displayed when that item is expanded). Youwill see a list of all the Git root directories. Look for bazel-drakeon that list and select it. On the right hand side are + and - buttons;click - to remove the spurious root directory. After that you should beable to go to VCS > Commit Changes and there should be no changes seen.

CLion provides a mechanism for invoking external binaries/scripts/etc. withparameters derived from the CLion GUI. Below, we outline a number of commontools to aid with compliance with the Drake style guide. The work to createa new external tool is the same in all cases; only the specific tool settingsdiffer from tool to tool. We'll outline the general work here and provideper-tool details below. The GUI description applies to version 2018.1.6 andmay be slightly different in previous versions.

  1. Open the Settings dialog (File > Settings) or Alt+Ctrl+S.
  2. Navigate to Tools > External Tools.
  3. Click the + sign to add a newtool.
  4. Set the appropriate fields in the Edit Tool. See the following tools fordetails.
  5. Click Ok.

There are several ways to use an External Tool. One is to right-click on afile and select External Tools > Tool Name. Another is to selectTools > External Tools > Tool Name. For tools that operate on aselected file, make sure that file is 'active' by clicking on it. TheTool Name will be the value set in the Name field outlined below.

Formatting files

You can use clang format to modify the formatting of your file in the GUI. We'llintroduce three variants:

  • Apply clang-format to a whole file.
  • Apply clang-format to selected lines.
  • Apply clang-format to correct #include ordering.

These tools modify the selected file. There is a synchronization issue withCLion such that the modification may not be immediately apparent. When in doubt,select away from the target file and back; this will cause the file to refreshand you can confirm that the file has been modified as expected.

First, make sure you have installed clang-format-9(see Tools for Code Style Compliance).

Clang format selected file

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Clang Format Full File
  • Description:Apply clang-format to the active file
  • Program:clang-format-9
  • Arguments:-i $FileName$
  • Working directory:$FileDir$
  • Advanced Options: Uncheck Open console for tool output

Drupal frontend editing. Leave the checkbox options in their default state.

Clang format selected lines

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Clang Format Selected Lines
  • Description:Apply clang-format to the selected lines
  • Program:clang-format-9
  • Arguments:-lines $SelectionStartLine$:$SelectionEndLine$ -i $FileName$
  • Working directory:$FileDir$
  • Advanced Options: Uncheck Open console for tool output

Leave the checkbox options in their default state.

Correct #include ordering

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Clang Format Include Ordering
  • Description:Runs the clang format for correcting includes on the current file
  • Program:bazel
  • Arguments:run //tools/lint:clang-format-includes -- $FilePath$
  • Working directory:$Projectpath$
  • Advanced Options: Uncheck Open console for tool output

Leave the checkbox options in their default state.

'Linting' files

Open

'Linting' refers to using tools to find aspects of code which don't conformto specified coding practices. You can apply Drake's linting tools in CLion tofind such issues. We'll define two tools:

  • General linting (via cpplint) which captures most of the Drake style guide.
  • Drake extended linting which captures aspects of the Drake style guide notcaptured by the general linting tool. This includes detecting out-of-order#include directives.
Clion Open Source
  • Git repo: https://github.com/cesarizu/CLionSourceCodeAccess.git
  • Download link: https://github.com/cesarizu/CLionSourceCodeAccess/archive/master.zip

Before opening CLion you need to change one file: Intermediates/ProjectFiles/Definitions.cmake. From that file, delete the line that reads:

You need to do this every time you run File > Generate CMakeLists.

Generating the CMake project file

The next step is generating the CMakeLists.txt file that CLion can open. For that just click on File > Generate CMakeLists. You need to do this every time you add or remove classes from your project.

You can now click on File > Open CLion and the project will open. Finally to open CLion automatically when you double click on any class in the UE4 editor, navigate to Edit > Editor Preferences… > General > Source Code and change the Source Code Editor there.

Installing the Unreal Engine 4 SDK Support for CLion

There's a plugin to get some extra functionality on CLion when working on UE4 projects. This will get rid of errors on UPROPERTY, UCLASS, USTRUCT and similar macros. On CLion go to File > Settings… > Plugins then click on Browse Repositories… and install Unreal Engine 4 SDK Support.

And voila! you can now benefit from the multiple features that CLion offers over other IDEs.

If there's anything on this guide that doesn't work or is incorrect, please let me know.

References

EVERY SETUP STEP IN THIS DOCUMENT IS CRITICAL TO GET CLION WORKING PROPERLY.Read carefully, and do not skip anything.

The Bazel plugin for CLion does not support macOS, perhttps://github.com/bazelbuild/intellij/issues/109

This guide describes how to set up Drake in the JetBrains CLion IDE on Ubuntu.

First, you must install Bazel and build Drake with Bazel, followingthe Drake Bazel instructions.

To use Drake with CLion, your Drake checkout must be named drake.

Installing CLion

  1. Go to https://www.jetbrains.com/clion/download/. Look for 'Other versions'and download the appropriate version of CLion (see below).
  2. Install CLion. Exact steps depend on your platform, but it'sstraightforward. Just using defaults for everything is fine. You now have a30-day trial version of CLion. Either try it out as is, or get a freeacademic license here.

The most recent versions that we have tested for compatibility are:

  • Ubuntu 18.04
  • Bazel 3.0.0 (6 April 2020)
  • CLion 2019.3.6 (5 May 2020) with:
    • Bazel plugin 2020.06.01.1.0 (15 June 2020).

Many versions of the above (Bazel / CLion / Bazel plugin) are not compatiblewith each other. We strongly suggest using only the versions shown above, whenworking with Drake.

Upgrading CLion

Users upgrading from a previous version of CLion should do the following:

  1. To have your Unity launcher CLion icon point to the correct version,run locate jetbrains-clion.desktop and edit the located file. If morethan one file is located, you may want to consolidate to a single launch filein your user directory, typically ~/.local/share/applications.
  2. Uninstall the previous version of the Bazel plugin and update to the latestversion. See Installing the Bazel Plugin.

Note: It is not necessary to import your project into a new CLion project.Overwriting the old project is appropriate.

Installing the Bazel Plugin

To use Bazel in CLion, you must install a plugin supplied by Google. Toinstall the plugin, open Settings (either Welcome > Configure >Settings or File > Settings), select Plugins, and press the Browserepositories button. Locate and install the Bazel plugin. You will beprompted to restart CLion.

To use Drake in CLion you must use Drake's bazel wrapper.Open Settings > Bazel Settings. For Bazel binary location select thepath to drake/tools/clion/bazel_wrapper from any recent Drake source tree(it doesn't have to match the current project open in CLion).

Setting up Drake in CLion

CLion will invoke Bazel to build Drake, including the external dependenciesspecified in the WORKSPACE file.

  1. File > Import Bazel Project
  2. Select Workspace: Use an existing Bazel workspace, and provide the path toyour drake directory.
  3. Select Project View: choose 'Import project view file', andselect the file drake/.bazelproject
  4. Project View: Pick a project data directory of your choice for theCLion project files. It must not be a subdirectory of drake.
  5. (Advanced) Project View: If you only wish to develop a subset of Drake,you can specify only those files and targets in the project view file.Most users should leave it as-is.
  6. Click 'Finish'. CLion will begin ingesting the Drake source, buildingsymbols, and compiling Drake. This will take several minutes.

Building and Running Targets

To build all of Drake with default Bazel options, selectBazel > Build > Compile Project.

To build or run a specific target go to Run > Edit Configurations. Click+ to create a new Bazel command. Specify the configuration name and Bazeloptions. The Target expression specifies the actual code (library, binary,and/or test) that you want to run. To learn more about target expressions, seethe Bazel manual.Once you've created a configuration, you can launch it from the Run menu.

To run a specific target in the debugger, create a configuration as above,using the bazel run command. Then launch it from Run > Debug.

Keeping CLion Up-to-Date with the Bazel Build

Changes to BUILD files can add or remove source files from the Bazel build.To propagate those changes into the CLion project structure, selectBazel > Sync Project With BUILD Files.

Git Integration

CLion provides a user interface for Git, which you can enable in the VCSmenu. It automatically detects all Git roots within the workspace. This willinclude bazel-drake, which is a Bazel-internal detail. Bazel editsthe contents of that directory for its own purposes, and those changes willspuriously appear in the CLion UI as changes that need to be committed. To makeCLion ignore bazel-drake, enable Git integration under the VCStab, then go to File > Settings. Select the Version Control menu itemdirectly (not one of the subtopics displayed when that item is expanded). Youwill see a list of all the Git root directories. Look for bazel-drakeon that list and select it. On the right hand side are + and - buttons;click - to remove the spurious root directory. After that you should beable to go to VCS > Commit Changes and there should be no changes seen.

CLion provides a mechanism for invoking external binaries/scripts/etc. withparameters derived from the CLion GUI. Below, we outline a number of commontools to aid with compliance with the Drake style guide. The work to createa new external tool is the same in all cases; only the specific tool settingsdiffer from tool to tool. We'll outline the general work here and provideper-tool details below. The GUI description applies to version 2018.1.6 andmay be slightly different in previous versions.

  1. Open the Settings dialog (File > Settings) or Alt+Ctrl+S.
  2. Navigate to Tools > External Tools.
  3. Click the + sign to add a newtool.
  4. Set the appropriate fields in the Edit Tool. See the following tools fordetails.
  5. Click Ok.

There are several ways to use an External Tool. One is to right-click on afile and select External Tools > Tool Name. Another is to selectTools > External Tools > Tool Name. For tools that operate on aselected file, make sure that file is 'active' by clicking on it. TheTool Name will be the value set in the Name field outlined below.

Formatting files

You can use clang format to modify the formatting of your file in the GUI. We'llintroduce three variants:

  • Apply clang-format to a whole file.
  • Apply clang-format to selected lines.
  • Apply clang-format to correct #include ordering.

These tools modify the selected file. There is a synchronization issue withCLion such that the modification may not be immediately apparent. When in doubt,select away from the target file and back; this will cause the file to refreshand you can confirm that the file has been modified as expected.

First, make sure you have installed clang-format-9(see Tools for Code Style Compliance).

Clang format selected file

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Clang Format Full File
  • Description:Apply clang-format to the active file
  • Program:clang-format-9
  • Arguments:-i $FileName$
  • Working directory:$FileDir$
  • Advanced Options: Uncheck Open console for tool output

Drupal frontend editing. Leave the checkbox options in their default state.

Clang format selected lines

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Clang Format Selected Lines
  • Description:Apply clang-format to the selected lines
  • Program:clang-format-9
  • Arguments:-lines $SelectionStartLine$:$SelectionEndLine$ -i $FileName$
  • Working directory:$FileDir$
  • Advanced Options: Uncheck Open console for tool output

Leave the checkbox options in their default state.

Correct #include ordering

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Clang Format Include Ordering
  • Description:Runs the clang format for correcting includes on the current file
  • Program:bazel
  • Arguments:run //tools/lint:clang-format-includes -- $FilePath$
  • Working directory:$Projectpath$
  • Advanced Options: Uncheck Open console for tool output

Leave the checkbox options in their default state.

'Linting' files

'Linting' refers to using tools to find aspects of code which don't conformto specified coding practices. You can apply Drake's linting tools in CLion tofind such issues. We'll define two tools:

  • General linting (via cpplint) which captures most of the Drake style guide.
  • Drake extended linting which captures aspects of the Drake style guide notcaptured by the general linting tool. This includes detecting out-of-order#include directives.

These tools produce reports. In some cases, the reports can be automaticallyconverted into clickable links so that you can click on a message and be takento the file and line indicated in the message. The configuration instructionsinclude the details of how to configure these clickable links.

You can also set the general coding style for CLion through the following steps

  1. Go to File > Settings > Editor > Code Style
  2. On the right panel, Go to Default Options > Right margin (columns):Set it to 80
  3. Go to File > Settings > Editor > Code Style > C/C++
  4. On the right panel, choose Set from > Predefined Style > Google

Lint selected file for google style guide

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Cpplint File
  • Description:Apply cpplint to the current file
  • Program:bazel
  • Arguments:run @styleguide//:cpplint -- --output=eclipse $FilePath$
  • Working directory:$Projectpath$
  • Advanced Options: Confirm Open console for tool output is checked

To configure the clickable links, enter the following string in the AdvancedOptions > Output filters window:

$FILE_PATH$:$LINE$

Lint selected file for Drake style addenda

This tool is a supplement to the google style cpplint. It tests for additionalstyle requirements which are otherwise missed by the general tool. The primaryreason to run this is to confirm that the order of the #include statementsis correct.

Open the Edit Tool for external tools as outlined above and enter thefollowing values for the fields:

  • Name:Drake Lint File
  • Description:Apply drake lint to the current file
  • Program:bazel
  • Arguments:run //tools/lint:drakelint -- $FilePath$
  • Working directory:$Projectpath$
  • Advanced Options: Confirm Open console for tool output is checked

In the event of finding a lint problem (e.g., out-of-order include files), theCLion output will contain a single clickable link. This link is only thefirst error encountered in the include section; there may be more. The linkmerely provides a hint to the developer to see the problem area. Rather thanfixing by hand, we strongly recommend executing the Clang Format IncludeOrdering external tool on the file.

Clion Open Source File

Alternative linting configuration

The linting tools have been configured to use the bazel system. The advantage indoing so is that it guarantees that the tools are built prior to being used.However, bazel only allows one instance of bazel to run at a time. For example,if building Drake in a command-line window, it would be impossible to lint filesat the same time.

The work around is to change the configurations to execute the binariesdirectly. This approach generally works but will fail if the corresponding bazeltargets have not been built. The tools would need to be built prior toexecution.

Clion Open Source Alternative

With this warning in place, you can make the following modifications to thelinting tools to be able to lint and compile simultaneously.

Google style guide linting

Change the following fields in the instructions given above:

  • Program:bazel-bin/external/styleguide/cpplint_binary
  • Arguments:--output=eclipse $FilePath$

Building the google styleguide lint tool:

bazel build @styleguide//:cpplint

Drake style addenda

Change the following fields in the instructions given above:

  • Program:bazel-bin/tools/lint/drakelint
  • Arguments:$FilePath$

Building the drake addenda lint tool:

bazel build //tools/lint:drakelint

Apparently CLion (or perhaps the Bazel plugin) has a certain amount ofauto-configuration of run/debug targets. It appears to hinge on the presence ofthe gtest.h header in source files. This is convenient, but only furthermystifies the process of debugging a non-gtest program. This section explainshow to configure debugging support for arbitrary programs in a Drake/CLionproject.

This section assumes all of the Drake-recommended installation andconfiguration is done.

Get the bazel target string

Find the source file of the program in the file tree view. Right-click on thefile, and select 'Copy BUILD Target String'. This will put the Bazel targetname into the clipboard.

Start a run configuration

Clion Open Source License

From the top menu, select 'Run/Edit Configurations…'. Select the '+' at theupper left of the dialog to add a new configuration. From the list, select'Bazel Command'.

Fill in the configuration

Now it's time to fill in the new blank configuration. Give it a name, thenselect the '+' at the right side to add the target expression. Once the editbox appears, paste the contents of the clipboard there. Hit 'Enter' or 'Tab' toconfirm the setting; a port number value should appear in the 'Port number'field below. In 'Bazel command', select either 'run' (for an arbitraryprogram), or 'test' (for a Bazel test target). Everything else can be left atdefault values. Click OK to finish.

Launch the debugger

At this point, the top menu 'Run' should have entries to run or debug the newconfiguration. Select the debug entry there, or use the controls at the upperright to launch the debugger.





broken image