User:Nmariusp/Clion
JetBrains CLion for programming for KDE
JetBrains CLion (CLion) is a proprietary IDE for C++. For pricing details see https://www.jetbrains.com/clion/buy
A screen recording version is available https://www.youtube.com/watch?v=j2bCBlZLujA https://www.youtube.com/watch?v=kJptE1mdL7s https://www.youtube.com/watch?v=G4CzVfSzv3s https://www.youtube.com/watch?v=_V5AqMj2fWc
See also https://community.kde.org/Get_Involved/development/IDE_configuration/CLion
Install CLion from the JetBrains Toolbox app
Instal the app "JetBrains Toolbox" https://www.jetbrains.com/toolbox-app > "Download .tar.gz (Linux 64-bit x86)". A file such as https://download-cdn.jetbrains.com/toolbox/jetbrains-toolbox-3.1.2.64642.tar.gz will be downloaded. Download it to the directory ~/Downloads.
mkdir -p ~/.opt/jetbrains-toolbox cd ~/Downloads tar -xvf jetbrains-toolbox-3.1.2.64642.tar.gz -C ~/.opt/jetbrains-toolbox --strip-components=1
Execute ~/.opt/jetbrains-toolbox/bin/jetbrains-toolbox. E.g.:
~/.opt/jetbrains-toolbox/bin/jetbrains-toolbox &
Enable the checkbox to Accept License Agreement > Get Started.
The main window of the app "JetBrains Toolbox" is shown. From the top right button with gear icon and tooltip "Menu" > "Quit Ctrl+Q".
In your start menu you will now have the application "JetBrains Toolbox".
From the start menu, open the application "JetBrains Toolbox". From the "Tools" tab > "Available tools" > "CLion A cross-platform C and C++ IDE" > "Install" button.
In your start menu you will now have the application "CLion A cross-platform C and C++ IDE", which is actually installed in ~/.local/share/JetBrains/Toolbox/apps/clion/bin/clion.
First run
When CLion starts for the first time, the dialog "Import CLion Settings" is shown, select "Do not import settings", OK. Data Sharing dialog > "Don't Send".
For CLion licensing you can create a jetbrains online account. In JetBrains Toolbox log into this account.
Then for CLion select the "For non-commercial use only" license.
The CLion application is started. Make sure that you have in the start menu the app "CLion A cross-platform C and C++ IDE". If you do not have it, you can create a desktop entry, from the CLion main menu > Tools > Create Desktop Entry. Now you can start CLion from the start menu (e.g. from the KDE Application Launcher or from krunner).
Keyboard layout
From CLion main menu > File > Settings > Keymap. From the Keymap combo box I select "Visual Studio", press the OK button.
Open a KDE project in CLion
I configure kde-builder to use the CMake build configuration "Debug" in order to be able to use the debugger in the IDE.
cmake-options: >
-DCMAKE_BUILD_TYPE=Debug
We'll use kcalc as an example KDE module and git repository. First, make sure it was built correctly using kde-builder.
kde-builder kcalc
Build just the project but with verbose output this time:
kde-builder kcalc --no-src --no-include-dependencies --refresh-build --debug
Look at the output, write down the part similar to:
Running cmake targeting Ninja...
cd /home/username/kde/build/kcalc
run_logged_command(): Module kcalc, Command: cmake -B . -S /home/username/kde/src/kcalc -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr -DCMAKE_PREFIX_PATH=/home/username/Qt/6.9.0/gcc_64
Setting environment variable PKG_CONFIG_PATH to /home/username/kde/usr/lib/x86_64-linux-gnu/pkgconfig:/home/username/Qt/6.9.0/gcc_64/lib/x86_64-linux-gnu/pkgconfig
Setting environment variable LD_LIBRARY_PATH to /home/username/kde/usr/lib/x86_64-linux-gnu:/home/username/Qt/6.9.0/gcc_64/lib/x86_64-linux-gnu
Setting environment variable PATH to /home/username/kde/usr/bin:/home/username/Qt/6.9.0/gcc_64/bin:/home/username/.cargo/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts
Setting environment variable CMAKE_PREFIX_PATH to /home/username/Qt/6.9.0/gcc_64:/home/username/kde/usr
Setting environment variable CMAKE_MODULE_PATH to /home/username/Qt/6.9.0/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
Setting environment variable QT_PLUGIN_PATH to /home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins
Setting environment variable XDG_DATA_DIRS to /home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
run_logged() completed with exitcode: 0. Log file: /home/username/kde/log/2025-01-25_22/kcalc/cmake.log
In the "Welcome to CLion" wizard > "Open" > "/home/username/kde/src/kcalc/CMakeLists.txt" > OK. The dialog "Open Project CMakeLists.txt is a project file. Would you like to open the project?" is shown, select "Open as Project". Enable check box "Trust projects in ~/kde/src" > "Trust Project" button. In the "Open Project Wizard" dialog select "OK".
CMake configure
Look at the the part that you have written down previously, from the output of kdesrc-build kcalc --debug ... .
In the CLion main menu > File > Settings > Build, Execution, Deployment > CMake > select the "Profile" named "Debug". "Build directory:" "/home/username/kde/build/kcalc". You can find the build directory above in the part "cd /home/username/kde/build/kcalc".
CMake options:
-G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr -DCMAKE_PREFIX_PATH=/home/username/Qt/6.9.0/gcc_64
You can find the value of "CMake options:" above in the part ", Command: cmake -B ". Ignore the command line parameters "-B" and "-S" and paste the rest of the cmake command line into "CMake options:".
Convert using a text editor and text replace:
Setting environment variable PKG_CONFIG_PATH to /home/username/kde/usr/lib/x86_64-linux-gnu/pkgconfig:/home/username/Qt/6.9.0/gcc_64/lib/x86_64-linux-gnu/pkgconfig
Setting environment variable LD_LIBRARY_PATH to /home/username/kde/usr/lib/x86_64-linux-gnu:/home/username/Qt/6.9.0/gcc_64/lib/x86_64-linux-gnu
Setting environment variable PATH to /home/username/kde/usr/bin:/home/username/Qt/6.9.0/gcc_64/bin:/home/username/.cargo/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts
Setting environment variable CMAKE_PREFIX_PATH to /home/username/Qt/6.9.0/gcc_64:/home/username/kde/usr
Setting environment variable CMAKE_MODULE_PATH to /home/username/Qt/6.9.0/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
Setting environment variable QT_PLUGIN_PATH to /home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins
Setting environment variable XDG_DATA_DIRS to /home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
by replacing " Setting environment variable " with "", and by replacing " to " with "=" to:
PKG_CONFIG_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/pkgconfig:/home/username/Qt/6.9.0/gcc_64/lib/x86_64-linux-gnu/pkgconfig LD_LIBRARY_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu:/home/username/Qt/6.9.0/gcc_64/lib/x86_64-linux-gnu PATH=/home/username/kde/usr/bin:/home/username/Qt/6.9.0/gcc_64/bin:/home/username/.cargo/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts CMAKE_PREFIX_PATH=/home/username/Qt/6.9.0/gcc_64:/home/username/kde/usr CMAKE_MODULE_PATH=/home/username/Qt/6.9.0/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake QT_PLUGIN_PATH=/home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins XDG_DATA_DIRS=/home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
Save the text block above to file ~/kde/clion-cmake.txt. The same text block will be needed when opening in CLion other KDE project.
Copy to clipboard the content of the file ~/kde/clion-cmake.txt. In "Environment:" on the button at the right side of the edit box with tooltip "Edit environment variables (Shift+Enter)". Click on the button with the tooltip "Paste". Press "OK" button.
rm -rf ~/kde/build/kcalc
In the bottom left select the button with the tooltip "CMake", this will open the CMake tool window. Press the button with tooltip "Clear All", press the "Reload CMake Project" button. Make sure that the output is correct. From the CLion main menu > Build > Rebuild "kcalc".
Run
cat ~/kde/build/kcalc/prefix.sh
says:
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
export MANPATH=/home/username/kde/usr/share/man:${MANPATH:-/usr/local/share/man:/usr/share/man}
export SASL_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/sasl2:${SASL_PATH:-/usr/lib/x86_64-linux-gnu/sasl2}
Run:
source ~/kde/build/kcalc/prefix.sh echo PATH=$PATH echo XDG_DATA_DIRS=$XDG_DATA_DIRS echo XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS echo QT_PLUGIN_PATH=$QT_PLUGIN_PATH echo QML2_IMPORT_PATH=$QML2_IMPORT_PATH echo QT_QUICK_CONTROLS_STYLE_PATH=$QT_QUICK_CONTROLS_STYLE_PATH echo MANPATH=$MANPATH echo SASL_PATH=$SASL_PATH
says:
PATH=/home/username/kde/usr/bin:/home/username/.cargo/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts XDG_DATA_DIRS=/home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:/home/username/.config/kdedefaults:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings QT_PLUGIN_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/plugins: QML2_IMPORT_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml: QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/: MANPATH=/home/username/kde/usr/share/man:/usr/local/share/man:/usr/share/man SASL_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/sasl2:/usr/lib/x86_64-linux-gnu/sasl2
Save the text block above to file ~/kde/expanded-prefix-sh.txt. The same text block will be needed when opening in the IDE JetBrains CLion other KDE projects. The content of this file is also needed when running or debugging a KDE project in other IDEs e.g. Qt Creator.
Copy to clipboard the content of the file ~/kde/expanded-prefix-sh.txt. From the CLion main menu > Run > Edit Configurations... > kcalc. In "Environment variables:" click on the button at the right side of the edit box with tooltip "Edit environment variables (Shift+Enter)". Click on the button with the tooltip "Paste" to paste from the clipboard. Press "OK" button twice.
Now you can run kcalc correctly, from the CLion main menu > Run > Run 'kcalc' Shift + F10.
Now you can debug kcalc correctly, from the CLion main menu > Run > Debug 'kcalc' Shift + F9.
As a test that CLion runs kcalc correctly, in CLion, start debugging the process kcalc and pause the debugger e.g. by pressing the pause program kcalc button. In the bottom left button "Debug Alt+5" > tab "GDB" > run the command info proc. It says:
(gdb) info proc process 89954 cmdline = '/home/username/kde/build/kcalc/bin/kcalc' cwd = '/home/username/kde/build/kcalc/bin' exe = '/home/username/kde/build/kcalc/bin/kcalc'
In a terminal:
xargs -0 printf %s\\n < /proc/89954/environ
Make sure that the value of the environment variables is correct.