CLion
💡 This tutorial works ONLY with kde-builder
This is a kde-builder exclusive feature.CLion is a proprietary IDE for C++ from JetBrains.
This article will show you how to configure and develop KDE projects in CLion. We will use KCalc as an example project.
Install CLion
Follow the Install CLion documentation.
If you are using Arch Linux, you can install the AUR package clion or clion-eap.
KDE Builder configuration
To allow kde-builder to generate CLion project files, add the following to your ~/.config/kdesrc-buildrc
:
global
# other options
generate-clion-project-config true
end global
Instead of enabling the generate-clion-project-config
option globally, you may choose to enable it only for a single project:
options kcalc
generate-clion-project-config true
end options
Ensure you have successfully built kcalc following the kde-builder instructions.
In case you enabled generate-clion-project-config
after you have built kcalc previously, or do not want to edit your config, you can generate CLion
configs by running:
kde-builder kcalc --no-include-dependencies --no-src --build-system-only --generate-clion-project-config
Using generated project in CLion
Opening project
From the CLion main menu, select File | Open.
An "Open File or Project" dialog will show up. Choose ~/kde/src/kcalc
directory and press OK.
Alternative ways of opening projects
If you have not yet opened any projects, or you have disabled "Reopen projects on startup" setting, when starting CLion, you will see a "Welcome to Clion" window. Press the "Open" button.
In "Open or Import Project" dialog, you can also select the root CMakeLists.txt file (i.e. ~/kde/src/kcalc/CMakeLists.txt
) and choose to open it as a
project.
Selecting CMake Profile
The "Open Project Wizard" window will open:
Tip
You can reach these settings later by going to Settings | Build, Execution, Deployment | CMake.If the project has a CMakePresets.json
in its root directory (KCalc does), you will see many greyed-out CMake Profiles. They are read only, and
disabled by default. You do not need them. Scroll the list down to be able to see the "KDE Builder cmake profile", which you want to select.
The very first time you use a kde-builder generated CLion project, you will need to create a toolchain named "KDE Builder toolchain". Press "Manage toolchains" link, and follow the next section instructions.
If you have done that, proceed by pressing OK.
Creating the toolchain
Tip
This is a global IDE setting, so you will only need to do it once.The "Toolchains" window will appear:
Tip
You can reach these settings later by going to Settings | Build, Execution, Deployment | Toolchains.- Press "+" icon, and select "System" from the list.
- In the Name field, enter exactly "KDE Builder toolchain".
- In the CMake field, enter "cmake".
- In the Debugger field, select "Custom GDB executable" and enter "gdb".
You can specify the full path to the tools or use bundled tools for CMake and GDB. But note that the toolchain name should be exactly that, because it is used in generated project configurations.
Press OK.
Selecting Run/Debug Configuration
In the upper right corner of CLion's window, you will see that "KDE Builder cmake profile" is applied, and "KDE Builder run/debug configuration" is applied.
You can now start developing. Set a breakpoint, start a debugging session, create your own run/debug configuration based on original, and so on.
Tips and Tricks
JetBrains Dolphin Plugin
JetBrains Dolphin Plugin is a service menu plugin (context menu action) which allows you to easily open folders as IDE projects.
You can install it from the store.kde.org (in the Configure Dolphin choose Context Menu, then press Download New Services... button. Search for Jetbrains Dolphin Plugin by alex1701c).
If you are using Arch Linux, you will prefer to install from AUR: kf6-servicemenus-jetbrains-dolphin-plugin-git.
JetBrains Runner
You can install JetBrainsRunner search plugin to be able to quickly open recent projects in JetBrains IDEs.
If you are using Arch Linux, you will prefer to install from AUR: plasma6-runners-jetbrains-runner-git.
Plugins for CLion
Qt6Renderer
Currently, the Qt classes do not support pretty printing in debugger in CLion out of the box. See Bug CPP-605 for more information.
You can install Qt6Renderer plugin.
GNU GetText files support (*.po)
Install the GetText files support (*.po) plugin. It will make the source lines in the po files clickable.
For example, you search the strings in local language, to find the place in code where it is used, you find it in *.po files. They contain stanzas like this:
~/kde/src/ark/po/ru/ark.po
#: part/part.cpp:132
#, kde-format
msgid "Comment has been modified."
msgstr "Комментарий был изменен."
You want to quickly jump to the source file. That source file (part/part.cpp:132
) becomes a clickable link if you install the plugin.
Non-project executable to run
When developing a library, it may be convenient to launch some application that uses it, from the current project. For example, you work with Ark's libraries used in Dolphin context menu actions. You can make your run configuration to launch custom binary - dolphin.
To do that, do the following:
- Open
Run/Debug Configurations
window - Click "Copy" icon to create a new run configuration based on the run configuration we have generated with kde-builder.
The new configuration will appear.
- Give it a meaningful name, for example ark (run dolphin).
- In the Executable field, specify path to dolphin binary: /home/username/kde/build/dolphin/bin/dolphin.
- Press OK.
Now when you run this configuration, the Ark will be built, but Dolphin will be launched.
Use native titlebar with New UI
It is possible to show a normal window titlebar. For this, open the registry (double-tap Shift, search for "Registry") and disable the
property ide.linux.hide.native.title
.
Use KWallet for git credentials
You need to enable this key in Registry: credentialStore.linux.prefer.kwallet
. It allows to use KWallet if KWallet and SecretService are both available.