Jump to content

Get Involved/development/IDE configuration/CLion: Difference between revisions

From KDE Community Wiki
Ashark (talk | contribs)
Use trailing $ for variable expansion, see https://youtrack.jetbrains.com/issue/IDEA-85313/Provide-ability-to-reference-parent-environment-variables-in-Run-Configuration-dialog-on-Windows
Ashark (talk | contribs)
Set run environment variables with script file
Line 27: Line 27:


Press OK.
Press OK.
In the run/debug target (in the upper right corner of main window), select "dolphin".
[[File:Clion select run debug configuration.png|frameless|300px|select run debug configuration]]
Expand it and choose Edit.
[[File:Clion go to run debug configuration edit.png|frameless|300px|go to run debug configuration edit]]
The Run/Debug Configurations window will appear.
[[File:Clion run debug configuration.png|frameless|500px|run debug configuration]]
In the Environment variables field click edit button.
You can add variables in there manually or reuse exports from <code>prefix.sh</code> script from build directory.
Note: if you want to modify debugging output messages, you can add corresponding variables there. See [[Guidelines and HOWTOs/Debugging/Using Error Messages#Controlling_Messages]].
=== Reusing existing prefix.sh ===
For convenience, copy the <code>/home/username/kde/build/dolphin/prefix.sh</code> to <code>/home/username/kde/clion_run_environment.sh</code>. [https://www.jetbrains.com/help/clion/2023.2/run-debug-configuration.html#envvars-progargs Use] the following syntax for setting variables in that script: <code>export VAR=value</code>.
In the Environment Variables dialog, in the Load Variables from file field, paste the path <code>/home/username/kde/clion_run_environment.sh</code>.
=== Setting variables manually ===


Translate the content of the file <code>~/kde/build/dolphin/prefix.sh</code> to the variables list that you can paste to CLion. E.g. if <code>~/kde/build/dolphin/prefix.sh</code> is like:
Translate the content of the file <code>~/kde/build/dolphin/prefix.sh</code> to the variables list that you can paste to CLion. E.g. if <code>~/kde/build/dolphin/prefix.sh</code> is like:
Line 55: Line 81:
QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH$
QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH$
</syntaxhighlight>
</syntaxhighlight>
Note: if you want to modify debugging output messages, you can add corresponding variables here. See [[Guidelines and HOWTOs/Debugging/Using Error Messages#Controlling_Messages]].


You probably want to save the above block of text, in order to reuse it when loading other KDE git repositories in CLion. E.g. to file <code>~/kde/clion_run_environment.txt</code>.
You probably want to save the above block of text, in order to reuse it when loading other KDE git repositories in CLion. E.g. to file <code>~/kde/clion_run_environment.txt</code>.


In the run/debug target (in the upper right corner of main window), select "dolphin".
Then in the Environment Variables dialog, paste the contents of the <code>~/kde/clion_run_environment.txt</code>.
 
[[File:Clion select run debug configuration.png|frameless|300px|select run debug configuration]]
 
Expand it and choose Edit.
 
[[File:Clion go to run debug configuration edit.png|frameless|300px|go to run debug configuration edit]]
 
The Run/Debug Configurations window will appear.
 
[[File:Clion run debug configuration.png|frameless|500px|run debug configuration]]


In the Environment variables field click edit button. Add variables, that you prepared in <code>~/kde/clion_run_environment.txt</code> as described above.
== Additional settings ==


In the Settings | Build, Execution, Deployment | Toolchains you can use bundled cmake and gdb. In Arch Linux their versions are very recent and not yet supported by CLion. They can be installed with [https://aur.archlinux.org/packages/clion-cmake clion-cmake] and [https://aur.archlinux.org/packages/clion-gdb clion-gdb].
In the Settings | Build, Execution, Deployment | Toolchains you can use bundled cmake and gdb. In Arch Linux their versions are very recent and not yet supported by CLion. They can be installed with [https://aur.archlinux.org/packages/clion-cmake clion-cmake] and [https://aur.archlinux.org/packages/clion-gdb clion-gdb].

Revision as of 10:45, 5 September 2023

CLion is a proprietary IDE for C++.

Install CLion

On Arch Linux install the clion.

Setup

Open a new project in CLion. Locate it to the folder with CMakeLists.txt. It will ask how do you want to open the project. Select CMake project.

open as cmake project

In CMake configuration, choose Debug build. In the Generator, set "Let Cmake decide". In the Build directory, insert the build directory path, for example, "/home/username/kde/build/dolphin".

build configuration

In this same window, under CMake options, we must set some important variables such as CMAKE_PREFIX_PATH. If the prefix was in "/home/username/kde", then the CMake options line would look like:

-DCMAKE_PREFIX_PATH=/home/username/kde/usr
-DCMAKE_MODULE_PATH=/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
-DQT_PLUGIN_PATH=/home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins
-DXDG_DATA_DIRS=/home/username/kde/usr/share

You probably would want to save that to file `~/kde/clion_cmake_options.txt` for future use.

Press OK.

In the run/debug target (in the upper right corner of main window), select "dolphin".

select run debug configuration

Expand it and choose Edit.

go to run debug configuration edit

The Run/Debug Configurations window will appear.

run debug configuration

In the Environment variables field click edit button.

You can add variables in there manually or reuse exports from prefix.sh script from build directory.

Note: if you want to modify debugging output messages, you can add corresponding variables there. See Guidelines and HOWTOs/Debugging/Using Error Messages#Controlling_Messages.

Reusing existing prefix.sh

For convenience, copy the /home/username/kde/build/dolphin/prefix.sh to /home/username/kde/clion_run_environment.sh. Use the following syntax for setting variables in that script: export VAR=value.

In the Environment Variables dialog, in the Load Variables from file field, paste the path /home/username/kde/clion_run_environment.sh.

Setting variables manually

Translate the content of the file ~/kde/build/dolphin/prefix.sh to the variables list that you can paste to CLion. E.g. if ~/kde/build/dolphin/prefix.sh is like:

export PATH=/home/username/kde/usr/bin:$PATH

# LD_LIBRARY_PATH only needed if you are building without rpath
# export LD_LIBRARY_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

export XDG_DATA_DIRS=/home/username/kde/usr/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}
export XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}

export QT_PLUGIN_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/plugins:$QT_PLUGIN_PATH
export QML2_IMPORT_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml:$QML2_IMPORT_PATH

export QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH

Then the same thing in the form of variables list for CLion looks like this block of text:

PATH=/home/username/kde/usr/bin:$PATH$
XDG_DATA_DIRS=/home/username/kde/usr/share:$XDG_DATA_DIRS$:/usr/local/share/:/usr/share/}
XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:$XDG_CONFIG_DIRS$:/etc/xdg
QT_PLUGIN_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/plugins:$QT_PLUGIN_PATH$
QML2_IMPORT_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml:$QML2_IMPORT_PATH$
QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH$

You probably want to save the above block of text, in order to reuse it when loading other KDE git repositories in CLion. E.g. to file ~/kde/clion_run_environment.txt.

Then in the Environment Variables dialog, paste the contents of the ~/kde/clion_run_environment.txt.

Additional settings

In the Settings | Build, Execution, Deployment | Toolchains you can use bundled cmake and gdb. In Arch Linux their versions are very recent and not yet supported by CLion. They can be installed with clion-cmake and clion-gdb.

use bundled cmake and gdb

Tips and Tricks

Out of tree breakpoints

You may want the debugger to stop on a specific breakpoint, that is located out of project tree. For example, you run and debug dolphin project: select several files, with context menu you add them to archive. And you want the debugger to stop on some function of Ark's code.

For this, you just open the corresponding file, and put a breakpoint there. No even need to map sources, like you need in Qt Creator.