User:Nmariusp/Clion

From KDE Community Wiki
Revision as of 13:23, 21 March 2024 by Nmariusp (talk | contribs) (Created page with "== 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=G4CzVfSzv3s https://www.youtube.com/watch?v=_V5AqMj2fWc See also https://community.kde.org/Get_Involved/development/IDE_configuration/CLion == Install CLion == Instal the app "JetBrains Toolbox" https://www.jetbrains.com/toolbox-app > "Do...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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=G4CzVfSzv3s https://www.youtube.com/watch?v=_V5AqMj2fWc

See also https://community.kde.org/Get_Involved/development/IDE_configuration/CLion

Install CLion

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-2.1.3.18901.tar.gz will be downloaded. Download it to the directory ~/Downloads.

mkdir -p ~/.opt/jetbrains-toolbox
cd ~/Downloads
tar -xzvf jetbrains-toolbox-2.1.3.18901.tar.gz -C ~/.opt/jetbrains-toolbox --strip-components=1

Execute ~/.opt/jetbrains-toolbox/jetbrains-toolbox. E.g.:

~/.opt/jetbrains-toolbox/jetbrains-toolbox &

The "Welcome to Toolbox App" first run wizard is shown > Continue > Accept License Agreement > Dark > Get Started.

The main window of the app "JetBrains Toolbox" is shown. From the button with gear icon and tooltip "Toolbox App Menu" > "Quit Ctrl+Q".

In your start menu you will now have the application "JetBrains Toolbox", which is actually installed in ~/.local/share/JetBrains/Toolbox/bin/jetbrains-toolbox.

From the start menu, open the application "JetBrains Toolbox". From the "Tools" tab > Available > "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.sh.

Alternative installation instructions

E.g. from the official webpage of CLion, select "Get Free 30-day Trial". A file such as https://download-cdn.jetbrains.com/cpp/CLion-2023.2.1.tar.gz will be downloaded. Download it to the directory ~/Downloads.

mkdir -p ~/.opt/clion
cd ~/Downloads
tar -xzvf CLion-2023.2.1.tar.gz -C ~/.opt/clion --strip-components=1

Execute ~/.opt/clion/bin/clion.sh. E.g.:

~/.opt/clion/bin/clion.sh &

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".

The "Licenses" dialog is shown, select the radio button "Start trial", click on the "Start Trial" button, click on the "Continue" button.

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).

Open a KDE project in CLion

I configure kdesrc-build to use the CMake build configuration "Debug" in order to be able to use the debugger in the IDE, and I use more than 4 CPU threads. For more details see the wiki page for the IDE [Qt Creator](https://community.kde.org/Get_Involved/development/IDE_configuration/Qt_Creator).

cmake-options -DCMAKE_BUILD_TYPE=Debug
...
num-cores 14

Build a KDE project e.g.

kdesrc-build kcalc

Build just the project but with verbose output this time:

kdesrc-build kcalc --no-src --no-include-dependencies --refresh-build --debug

Look at the output, write down the part similar to:

        Running cmake targeting Kate - Ninja...
        cd /home/username/kde/build/kcalc

run_logged_command(): Module kcalc, Command: cmake -B . -S /home/username/kde/src/kcalc -G Kate - Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DQT_NO_CAST_FROM_ASCII=ON -DQT_NO_CAST_TO_ASCII=ON -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr -DCMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64
                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
        Setting environment variable PATH to /home/username/kde/usr/bin:/home/username/Qt/6.6.1/gcc_64/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 PKG_CONFIG_PATH to /home/username/kde/usr/lib/pkgconfig:/home/username/Qt/6.6.1/gcc_64/lib/pkgconfig
        Setting environment variable CMAKE_PREFIX_PATH to /home/username/Qt/6.6.1/gcc_64:/home/username/kde/usr
        Setting environment variable LD_LIBRARY_PATH to /home/username/kde/usr/lib:/home/username/Qt/6.6.1/gcc_64/lib
        Setting environment variable CMAKE_MODULE_PATH to /home/username/Qt/6.6.1/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
# kdesrc-build running: 'cmake' '-B' '.' '-S' '/home/username/kde/src/kcalc' '-G' 'Kate - Ninja' '-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON' '-DCMAKE_BUILD_TYPE=Debug' '-DQT_NO_CAST_FROM_ASCII=ON' '-DQT_NO_CAST_TO_ASCII=ON' '-DBUILD_WITH_QT6=ON' '-DCMAKE_CXX_FLAGS:STRING=-pipe' '-DCMAKE_INSTALL_PREFIX=/home/username/kde/usr' '-DCMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64'
# from directory: /home/username/kde/build/kcalc

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".

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 "Kate - Ninja" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DQT_NO_CAST_FROM_ASCII=ON -DQT_NO_CAST_TO_ASCII=ON -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr -DCMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/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 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
        Setting environment variable PATH to /home/username/kde/usr/bin:/home/username/Qt/6.6.1/gcc_64/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 PKG_CONFIG_PATH to /home/username/kde/usr/lib/pkgconfig:/home/username/Qt/6.6.1/gcc_64/lib/pkgconfig
        Setting environment variable CMAKE_PREFIX_PATH to /home/username/Qt/6.6.1/gcc_64:/home/username/kde/usr
        Setting environment variable LD_LIBRARY_PATH to /home/username/kde/usr/lib:/home/username/Qt/6.6.1/gcc_64/lib
        Setting environment variable CMAKE_MODULE_PATH to /home/username/Qt/6.6.1/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake

by replacing " Setting environment variable " with "", and by replacing " to " with "=" to:

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
PATH=/home/username/kde/usr/bin:/home/username/Qt/6.6.1/gcc_64/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
PKG_CONFIG_PATH=/home/username/kde/usr/lib/pkgconfig:/home/username/Qt/6.6.1/gcc_64/lib/pkgconfig
CMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64:/home/username/kde/usr
LD_LIBRARY_PATH=/home/username/kde/usr/lib:/home/username/Qt/6.6.1/gcc_64/lib
CMAKE_MODULE_PATH=/home/username/Qt/6.6.1/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake

Select the text block above and in "Environment:", 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". 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".

From the CLion main menu > Run > Edit Configurations... > kcalc > Environment variables: > use the button with the tooltip "Paste" to paste the same text block as above in the "Settings > Build, Execution, Deployment" >"Environment:".

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.

If CLion starts the process kcalc (for running or for debugging), you can make sure that the process was started correctly. In Clion > 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

The value of the environment variables should be the same as in part that you have written down previously from the output of kdesrc-build kcalc --debug ....