Get Involved/development/More: Difference between revisions

From KDE Community Wiki
(48 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This page is the continuation with more advanced topics of the page [[Get_Involved/development]].
This page is the continuation with more advanced topics of the page [[Get_Involved/development]].


== kdesrc-build Qt5 ==
== kde-builder is an alternative to kdesrc-build ==


kdesrc-build by default uses Qt6. Your kdesrc-build installation is configured for Qt6 if in the configuration file <code>kdesrc-buildrc</code> you have <code>branch-group kf6-qt6</code>.
kdesrc-build and kde-builder are two KDE build frameworks. They are used at the command line and have identical command line syntax, just replace the string "kdesrc-build" with "kde-builder". They use the same configuration file, named <code>kdesrc-buildrc</code>.


You can convert your kdesrc-build installation from Qt6 to Qt5 by editing the existing kdesrc-buildrc file to replace all occurrences of "6" with "5".
kde-builder is newer and regularly gets new features and is written in Python.


Set up kdesrc-build following the "Set up kdesrc-build" procedure. The resulting kdesrc-build installation will be of type kf6-qt6. In kdesrc-buildrc in the "global" section you will have "branch-group kf6-qt6".
kdesrc-build is in maintenance mode and feature frozen and written in Perl.


Edit the file <code>~/.config/kdesrc-buildrc</code>
The "how to install kde-builder" procedure is here https://invent.kde.org/sdk/kde-builder/-/blob/master/README.md .
* Replace all "6" with "5".
 
Example:
 
<pre>
# Make sure that you do not already have a kdesrc-build
# installation that uses the configuration file
# ~/.config/kdesrc-buildrc
 
mkdir -p ~/kde5/src
cd ~/kde5/src
mv ~/.config/kdesrc-buildrc ./config_kdesrc-buildrc_backup 2> /dev/null
git clone https://invent.kde.org/sdk/kdesrc-build.git && cd kdesrc-build
./kdesrc-build --initial-setup <<< 'N'
mv ~/.config/kdesrc-buildrc .
 
# Edit the file ~/kde5/src/kdesrc-build/kdesrc-buildrc:
# A. Replace "/home/username/kde5/src/kdesrc-build/" with "".
sed -i 's_/home/.*/src/kdesrc-build/__g' kdesrc-buildrc
 
# B. Replace "~/kde/" with "~/kde5/".
sed -i 's_~/kde/_~/kde5/_g' kdesrc-buildrc
 
# C. Replace "num-cores 4" with the count of your CPU threads (nproc) minus two. E.g. if you have 16 CPU threads, use "num-cores 14".
 
# D. If you plan to use the C++ debugger, replace "-DCMAKE_BUILD_TYPE=RelWithDebInfo" with "-DCMAKE_BUILD_TYPE=Debug".
 
# E. Replace "6" with "5".
sed -i 's/6/5/g' kdesrc-buildrc
 
# Make sure that the configuration file
# ~/kde5/src/kdesrc-build/kdesrc-buildrc looks OK
# E.g. kate ~/kde5/src/kdesrc-build/kdesrc-buildrc &
 
# From now on you will need to be in the directory
# ~/kde5/src/kdesrc-build before you can run kdesrc-build or kdesrc-run
 
# E.g.
cd ~/kde5/src/kdesrc-build
./kdesrc-build kconfig
./kdesrc-build kcalc
./kdesrc-run kcalc
./kdesrc-build frameworks --ignore-modules=kstatusnotifieritem
 
</pre>


== Develop in a Linux container ==
== Develop in a Linux container ==


When you start programming for KDE, it is recommended that you [[Get_Involved/development|use kdesrc-build in your main operating system or in a virtual machine]] running on a rolling-release Linux distribution (Arch, openSUSE Tumbleweed, KDE neon) or running on e.g. the latest version of Fedora KDE Spin or Kubuntu.
When you start programming for KDE, it is recommended that you [[Get_Involved/development|use kdesrc-build in your main operating system or in a virtual machine]] running on a [[Get_Involved/development#Operating_system|Linux operating system that is better supported by kdesrc-build]].


As an alternative, you can run kdesrc-build in a Linux container (docker, podman, toolbx, distrobox).
As an alternative, you can run kdesrc-build in a Linux container (docker, podman, toolbx, distrobox).
Line 76: Line 31:
* Fedora: sudo dnf install distrobox podman
* Fedora: sudo dnf install distrobox podman
* Arch: sudo pacman --sync distrobox podman
* Arch: sudo pacman --sync distrobox podman
On systems which are designed for you to not tamper with their root files (immutable distributions like openSUSE Kalpa, Fedora Kinoite, and SteamOS on the Steam Deck) you can use an [https://distrobox.it/#alternative-methods official alternative method] to install distrobox:
{{Input|<nowiki>
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --prefix ~/.local
</nowiki>}}
On the Steam Deck, you will additionally need to add <tt>~/.local/bin</tt> to the <code>$PATH</code>.


==== Building without kdesrc-build ====
==== Building without kdesrc-build ====
Line 129: Line 92:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
mkdir -p ~/kde/src
mkdir -p ~/.local/share/
cd ~/kde/src
cd ~/.local/share
git clone https://invent.kde.org/sdk/kdesrc-build.git
git clone https://invent.kde.org/sdk/kdesrc-build.git
cd kdesrc-build
cd kdesrc-build
./kdesrc-build --initial-setup
./kdesrc-build --initial-setup
source ~/.bashrc
mkdir -p ~/.local/bin
ln -sf ~/.local/share/kdesrc-build/kdesrc-build ~/.local/bin
</syntaxhighlight>
</syntaxhighlight>


Line 144: Line 108:


After compiling your program with kdesrc-build from inside the distrobox, you can run it with <code>kdesrc-build run</code>, and despite it originating from inside a container and using the libraries from the container, it will run just fine as a GUI application on your system!
After compiling your program with kdesrc-build from inside the distrobox, you can run it with <code>kdesrc-build run</code>, and despite it originating from inside a container and using the libraries from the container, it will run just fine as a GUI application on your system!
{{Note|If you are on an X11 session, you will need to create the file <tt>~/.config/distrobox/distrobox.conf</tt> and add <code>xhost +si:localuser:$USER</code> to it in order for distrobox to be able to run graphical applications.}}


The only few gotchas to using this method are:
The only few gotchas to using this method are:
Line 153: Line 119:
== Other operating systems ==
== Other operating systems ==


=== Kubuntu 23.10 ===
=== Kubuntu >= 23.10 ===


The default configuration of kdesrc-build requires Qt version 6.5. Kubuntu 23.10 has Qt version 6.4.2. It is recommended that you use a [[Get_Involved/development#Operating_system|Linux OS that is better supported by kdesrc-build]].
The default configuration of kdesrc-build requires Qt version 6.6. Kubuntu 23.10 has Qt version 6.4.2. It is recommended that you use a [[Get_Involved/development#Operating_system|Linux OS that is better supported by kdesrc-build]].
 
If you are a more seasoned developer you might be able to use Kubuntu for kdesrc-build by [[Get_Involved/development/More#Qt_6_installed_using_the_Qt_online_installer|installing Qt6 using the Qt online installer]] or by [[Get_Involved/development/More#Build_Qt_using_kdesrc-build|building Qt6 using kdesrc-build]].


=== FreeBSD ===
=== FreeBSD ===
Line 169: Line 137:
</pre>
</pre>


Then set up kdesrc-build using the same procedure as when installing kdesrc-build on a Linux operating system. FreeBSD is currently supported by kdesrc-build. See https://www.youtube.com/watch?v=v2wq0eTnUuc https://www.youtube.com/watch?v=MT-AN4J-hn8
Then set up kdesrc-build using the same procedure as when installing kdesrc-build on a Linux operating system. FreeBSD is currently supported by kdesrc-build. See https://www.youtube.com/watch?v=8MqBnb3Y9JU


=== Microsoft Windows ===
=== OpenBSD >= 7.5 ===


You can build and develop KDE projects using the [[Get_Involved/development/Windows|Microsoft Windows]] operating system.
Install OpenBSD version greater than or equal to 7.5. In the installer keep the defaults, the user created by the installer is named "administrator" in this example.
<pre>
# Enable doas
su -
cp /etc/examples/doas.conf /etc/doas.conf
exit
# kdesrc-build needs sudo.
mkdir -p ~/.local/bin ; ln -s /usr/bin/doas ~/.local/bin/sudo
echo "export PATH=~/.local/bin:\$PATH" >> ~/.bashrc


=== Apple macOS ===
# Test doas.
doas su
# kde-builder needs bash.
pkg_add bash
chsh -s /usr/local/bin/bash
exit


You can build and develop KDE projects using the [[Get_Involved/development/Mac|Apple macOS]] operating system.
# As user administrator
chsh -s /usr/local/bin/bash


== What to do if CMake configure fails because a build dependency is missing ==
# As per https://rsadowski.de/posts/2024-01-09-openbsd-kde/ , https://openports.pl/path/meta/kde,-plasma
doas su
pkg_add kde-plasma kate


See https://community.kde.org/Get_Involved/development/Install_the_dependencies .
# I recommend that you use tigervnc. https://nmariusp.github.io/install-os.html#openbsd--75
</pre>


== Advanced kdesrc-build ==
After you install kdesrc-build:
 
After you have edited a git repository and you want to build it, <code>--no-src</code> will make sure that <code>kdesrc-build</code> does not overwrite your changes with the latest source code from the official git repository (remote "origin" / https://invent/kde.org).
 
<code>--no-include-dependencies</code> only builds the git repository that you give as parameter to <code>kdesrc-build</code>.
 
<code>--debug</code> shows verbose output.
 
<code>--refresh-build</code> forces a rebuild (not an incremental build) and a full reinstall.
 
E.g. you have edited kcalc. You run:
<pre>
<pre>
kdesrc-build kcalc --no-src --no-include-dependencies --refresh-build --debug |& tee ~/a.txt
# Edit the kdesrc-buildrc file e.g.:
</pre>
cmake-options -DCMAKE_BUILD_TYPE=RelWithDebInfo -DKF_IGNORE_PLATFORM_CHECK=ON


For details, see:
# Also set environment variable:
<pre>
export CMAKE_PREFIX_PATH=/usr/local/lib/qt6/cmake
kdesrc-build --help
# Or
export CMAKE_PREFIX_PATH=/usr/local/lib/qt5/cmake
</pre>
</pre>


Note: the resources below might not be up to date.
=== Microsoft Windows ===


See the [https://docs.kde.org/trunk5/en/kdesrc-build/kdesrc-build/ kdesrc-build manual], [https://invent.kde.org/sdk/kdesrc-build/-/blob/master/README.md Readme #1], [https://invent.kde.org/sdk/kdesrc-build/-/blob/master/doc/README.md Readme #2], [https://invent.kde.org/sdk/kdesrc-build/-/blob/master/doc/source-reference/index.adoc Document #3] for more kdesrc-build information and options.
You can build and develop KDE projects using the [[Get_Involved/development/Windows|Microsoft Windows]] operating system.


== Qt 6 installed using Qt online installer ==
=== Apple macOS ===


The homepage of the Qt Framework is https://www.qt.io . Go to this web page, create an online account. https://www.qt.io/download-open-source > "Download the Qt Online Installer" > Linux > "Qt Online Installer for Linux (64-bit)" > download a file named e.g. qt-unified-linux-x64-4.6.1-online.run into the directory e.g. "~/Downloads".
You can build and develop KDE projects using the [[Get_Involved/development/Mac|Apple macOS]] operating system.


<pre>
== What to do if CMake configure fails because a build dependency is missing ==
ls -la ~/Downloads # The downloaded file needs to hace the "executable" chmod bit set.
chmod +x ~/Downloads/qt-unified-linux-x64-4.6.1-online.run
~/Downloads/qt-unified-linux-x64-4.6.1-online.run
</pre>


Login using your Qt online account. Next > check the checkbox "I have read and agree to the terms and conditions of using OpenSource Qt", check the checkbox "I'm an individual and do not use Qt for any company" > Next > Next > enable "Help us improve" > Next > Custom installation, notice that the install directory is "~/Qt" > Next. Install the latest version of Qt6 and the latest version of the Qt Creator integrated development environment (IDE). There are some Qt6 components that are not used by KDE and can be left out when installing Qt6 e.g. WebAssembly, Android, Sources, Qt Quick 3D, Qt 3D, "Quick: 3D Physics", "Qt debug Information Files".
See https://community.kde.org/Get_Involved/development/Install_the_dependencies .
 
In the KDE Plasma app launcher you now have the application "Qt Maintenance Tool".


Set up kdesrc-build from scratch as usual.
== Project Documentation ==


Edit the file kdesrc-buildrc to look like:
* [https://docs.kde.org/trunk5/en/kdesrc-build/kdesrc-build/ Handbook]
* [https://invent.kde.org/sdk/kdesrc-build/-/blob/master/README.md Readme #1]
* [https://invent.kde.org/sdk/kdesrc-build/-/blob/master/doc/README.md Readme #2]


<pre>
Developer's documentation can be found in the {{ic|doc/source-reference}} in the project repo.
global
...
    qtdir  ~/Qt/6.6.0/gcc_64 # Where to install Qt6 if kdesrc-build supplies it
    libname lib
...
end global
...
</pre>


Make gpgme build:
== kf6-qt6 vs. kf5-qt5 ==
 
<pre>
sudo su
mkdir -p /home/qt/work
chown -R username:username /home/qt/work
ln -s /home/username/Qt/6.6.0/gcc_64 /home/qt/work/install
ls -la /home/qt/work
</pre>
 
== kf5-qt5 vs. kf6-qt6 ==


Many KDE git repositories can build correctly and run correctly using "kdesrc-build kf6-qt6".  
Many KDE git repositories can build correctly and run correctly using "kdesrc-build kf6-qt6".  
Line 253: Line 207:
* A long lived git branch that does not contain the deprecated symbols from kf5-qt5, named e.g. "master".
* A long lived git branch that does not contain the deprecated symbols from kf5-qt5, named e.g. "master".
* And another long lived git branch for qt5-kf5, where the deprecated symbols still exist.
* And another long lived git branch for qt5-kf5, where the deprecated symbols still exist.
What is "kf5-qt5"? Follow the chapter "kdesrc-build Qt5". The resulting kdesrc-build installation will be of type kf5-qt5. In kdesrc-buildrc in the "global" section you will have "branch-group kf5-qt5". The git repositories that have only one long lived git branch e.g. named "master" will use that. The git repositories that have a second long lived git branch where the deprecated symbols still exist e.g. named "kf5" will use that.


What is "kf6-qt6"? You just set up kdesrc-build following the procedure. The resulting kdesrc-build installation will be of type kf6-qt6. In kdesrc-buildrc in the "global" section you will have "branch-group kf6-qt6". The git repositories that have only one long lived git branch e.g. named "master" will use that. The git repositories that have a second long lived git branch, will use the git branch where the deprecated symbols do not exist e.g. named "master".
What is "kf6-qt6"? You just set up kdesrc-build following the procedure. The resulting kdesrc-build installation will be of type kf6-qt6. In kdesrc-buildrc in the "global" section you will have "branch-group kf6-qt6". The git repositories that have only one long lived git branch e.g. named "master" will use that. The git repositories that have a second long lived git branch, will use the git branch where the deprecated symbols do not exist e.g. named "master".


== Build Qt6 using kdesrc-build ==
What is "kf5-qt5"? Follow the chapter "kdesrc-build Qt5". The resulting kdesrc-build installation will be of type kf5-qt5. In kdesrc-buildrc in the "global" section you will have "branch-group kf5-qt5". The git repositories that have only one long lived git branch e.g. named "master" will use that. The git repositories that have a second long lived git branch where the deprecated symbols still exist e.g. named "kf5" will use that.
 
A screen recording version is available https://www.youtube.com/watch?v=TDzX0376QyA
 
Note: If you cannot build the KDE frameworks using kdesrc-build and using the Qt6 provided by your OS (Linux distribution). Because the Qt6 is not complete. You might want to build Qt6 using kdesrc-build.
 
Note: Building Qt6 using kdesrc-build is an advanced topic.
 
Set up kdesrc-build clean from scratch.  


Edit two files.
== Build Qt using kdesrc-build ==


<code>~/.config/kdesrc-buildrc</code>:
=== Qt6 ===
If you cannot build the KDE frameworks using {{ic|kdesrc-build}} and the Qt provided by your Linux distribution is outdated, you might want to build the Qt framework using {{ic|kdesrc-build}}.


<syntaxhighlight lang="bash">
In your configuration file use the {{ic|qt-install-dir}} option (in the ''global'' section) with non-empty value, for example:
# This file controls options to apply when configuring/building modules, and
# controls which modules are built in the first place.
# List of all options: https://docs.kde.org/trunk5/en/kdesrc-build/kdesrc-build/conf-options-table.html


{{bc|
global
global
    branch-group kf6-qt6
  qt-install-dir ~/kde/usr
 
  branch-group kf6-qt6
    # Finds and includes *KDE*-based dependencies into the build.  This makes
    # it easier to ensure that you have all the modules needed, but the
    # dependencies are not very fine-grained so this can result in quite a few
    # modules being installed that you didn't need.
    include-dependencies true
 
    # Install directory for KDE software
    kdedir ~/kde/usr
 
    # Directory for downloaded source code
    source-dir ~/kde/src
 
    # Directory to build KDE into before installing
    # relative to source-dir by default
    build-dir ~/kde/build
 
    qtdir  ~/kde/usr # Where to install Qt6 if kdesrc-build supplies it
 
    cmake-options -DCMAKE_BUILD_TYPE=Debug
 
    # kdesrc-build sets 2 options which is used in options like make-options or set-env
    # to help manage the number of compile jobs that happen during a build:
    #
    # 1. num-cores, which is just the number of detected CPU cores, and can be passed
    #    to tools like make (needed for parallel build) or ninja (completely optional).
    #
    # 2. num-cores-low-mem, which is set to largest value that appears safe for
    #    particularly heavyweight modules based on total memory, intended for
    #    modules like qtwebengine
    num-cores 15
    num-cores-low-mem 4
 
    # kdesrc-build can install a sample .xsession file for "Custom"
    # (or "XSession") logins,
    install-session-driver false
 
    # or add a environment variable-setting script to
    # ~/.config/kde-env-master.sh
    install-environment-driver true
 
    # Stop the build process on the first failure
    stop-on-failure true
 
    # Use a flat folder layout under ~/kde/src and ~/kde/build
    # rather than nested directories
    directory-layout flat
 
    # Build with LSP support for everything that supports it
    compile-commands-linking true
    compile-commands-export true
 
    git-repository-base qt6-copy https://invent.kde.org/qt/qt/
end global
end global
}}


# With base options set, the remainder of the file is used to define modules to build, in the
It is recommended that if you build Qt6 using kdesrc-build, you also build qtwebengine. Edit the file {{ic|~/.local/state/sysadmin-repo-metadata/module-definitions/qt6.ksb}}. Follow the instructions found in the file: if you want qtwebengine, add it to use-modules after "qtwebchannel" and comment out the line "ignore-modules qtwebengine".
# desired order, and set any module-specific options.
#
# Modules may be grouped into sets, and this is the normal practice.
#
# You can include other files inline using the "include" command. We do this here
# to include files which are updated with kdesrc-build.


# Common options that should be set for some KDE modules no matter how
Then build Qt6: {{bc|kdesrc-build qt6-set}}
# kdesrc-build finds them. Do not comment these out unless you know
# what you are doing.
#include /home/username/kde/src/kdesrc-build/kf6-common-options-build-include


# Qt and some Qt-using middleware libraries. Uncomment if your distribution's Qt
To compile Qt6 with Qt X11 Extras (which is a necessary library to compile [https://api.kde.org/frameworks/kwindowsystem/html/ KWindowSystem]), you should enable XCB feature during compilation
# tools are too old but be warned that Qt take a long time to build!
include /home/username/kde/src/kdesrc-build/qt6-build-include
#include /home/username/kde/src/kdesrc-build/custom-qt6-libs-build-include


# KF6 and Plasma :)
{{bc|1=kdesrc-build qt6-set --cmake-options="-DQT_FEATURE_xcb=ON"}}
#include /home/username/kde/src/kdesrc-build/kf6-qt6-build-include


# To change options for modules that have already been defined, use an
=== Qt5 ===
# 'options' block. See kf6-common-options-build-include for an example
If you want the same for Qt5, change {{ic|branch-group}} option and use {{ic|qt5-set}} instead of {{ic|qt6-set}}.


</syntaxhighlight>
== Qt 6 installed using the Qt online installer ==


<code>~/kde/src/kdesrc-build/qt6-build-include</code>:
A screen recording version is available https://www.youtube.com/watch?v=3BIbYN2vIZw


<syntaxhighlight lang="bash">
The homepage of the Qt Framework is https://www.qt.io . Go to this web page, create an online account. https://www.qt.io/download-open-source > "Download the Qt Online Installer" > Linux > "Qt Online Installer for Linux (64-bit)" > download a file named e.g. qt-unified-linux-x64-4.6.1-online.run into the directory e.g. "~/Downloads".
# Downloads and installs Qt6 from the KDE mirror, using Qt6's CMake support
# exclusively.  Consider this an unofficial build that won't be supported by Qt
# upstream since we don't go through the init-repository script.
# It is probably better to install from your local distribution devel packages
# if possible!
module-set qt6-set
    override-build-system qt6 # technically optional for now
 
    repository qt6-copy # as defined in kdesrc-buildrc-kf6-sample
    branch    6.5
 
    # install path. This *MUST* match your qtdir setting in kdesrc-buildrc!
    prefix ${qtdir}
 
    # These have been manually placed in dependency order based on the
    # .gitmodules file in https://code.qt.io/cgit/qt/qt5.git/tree/.gitmodules
    # in "essential" or "addons" categories with some additions
    # qtdoc should be last to give it best opportunity to make needed docs
    use-modules qtbase qttools qtshadertools qtdeclarative qtsvg \
        qtimageformats qtmultimedia qtwayland                    \
        qtwebsockets qtwebchannel qtwebengine qtwebview qtsensors            \
        qtnetworkauth qt5compat qtdoc qtpositioning              \
        qtlocation qtvirtualkeyboard qttranslations              \
        qtlanguageserver
 
    # if you want qtwebengine, add it to use-modules after "qtwebchannel" and
    # comment this out. Note qtwebengine has significant and different build
    # requirements of its own.
    #ignore-modules qtwebengine
 
    # Archiving API requires zstd support which may not be present in your CMake
    cmake-options -DQT_BUILD_TESTS=FALSE -DCMAKE_BUILD_TYPE=RelWithDebInfo \
                  -DQT_AVOID_CMAKE_ARCHIVING_API=TRUE
 
    cmake-generator Ninja # comment out if you want the default CMake generator
end module-set
 
options qtwebengine
    # qtwebengine build system is weird, involving make as the top-level driver
    # and then calling ninja for the bulk of the build. qtwebengine is a bulky
    # module and having ninja use all cores at once may run out of memory if
    # not careful, so we use make to pass less aggressive Ninja flags.
    # num-cores-low-mem needs to be defined in your kdesrc-buildrc.
    make-options NINJAFLAGS=-j${num-cores-low-mem}
end options
 
# vim: set ft=kdesrc-buildrc:
</syntaxhighlight>
 
Debian/Ubuntu:
<syntaxhighlight lang="bash">
apt build-dep qt6-base-dev qt6-tools-dev qt6-shadertools-dev qt6-shadertools-dev qt6-svg-dev \
qt6-image-formats-plugins qt6-multimedia-dev qt6-wayland-dev \
qt6-websockets-dev qt6-webchannel-dev qt6-webengine-dev qt6-webview-dev qt6-sensors-dev\
qt6-networkauth-dev qt6-5compat-dev qt6-documentation-tools qt6-positioning-dev \
qt6-virtualkeyboard-dev qt6-translations-l10n \
qt6-languageserver-dev
 
# If qttools does not build because of missing "#include <litehtml.h>"
# as per https://groups.google.com/g/linux.debian.bugs.dist/c/xQS2TvgKn6E
# Edit ~/kde/src/qttools/src/assistant/qlitehtml/src/container_qpainter_p.h:80
# replace "#include <litehtml.h>" with "#include <litehtml/litehtml.h>".
 
kdesrc-build qt6-set
</syntaxhighlight>
 
To compile Qt6 with Qt X11 Extras which is a necessary library to compile [https://api.kde.org/frameworks/kwindowsystem/html/ KWindowSystem], you shoud enable XCB feature during compilation


<pre>
<pre>
kdesrc-build qt6-set --cmake-options="-DQT_FEATURE_xcb=ON"
ls -la ~/Downloads # The downloaded file needs to have the "executable" chmod bit set.
chmod u+x ~/Downloads/qt-unified-linux-x64-4.6.1-online.run
~/Downloads/qt-unified-linux-x64-4.6.1-online.run
</pre>
</pre>


== Portable installation of kdesrc-build ==
A graphical user interface (GUI) installer wizard starts. Login using your Qt online account. Next > check the checkbox "I have read and agree to the terms and conditions of using OpenSource Qt", check the checkbox "I'm an individual and do not use Qt for any company" > Next > Next > enable "Help us improve" > Next > Custom installation, notice that the install directory is "~/Qt" > Next. Install the latest version of Qt6 and the latest version of the Qt Creator integrated development environment (IDE). There are some Qt6 components that are not used by KDE and can be left out when installing Qt6 e.g. Qt Design Studio, WebAssembly, Android, Sources, Qt Quick 3D, Qt 3D, Qt Quick 3D Physics, "Qt Debug Information Files". Next > enable "I have read and agree" > Next > Install.


The current directory (pwd) is important when running kdesrc-build. If there exists a file <code>kdesrc-buildrc</code> in the the current directory (pwd), kdesrc-build will prefer that file over <code>~/.config/kdesrc-buildrc</code>.
In the KDE Plasma app launcher (start menu) you now have the application "Qt Maintenance Tool".


If you are interested in or need separate builds of KDE software, like when building with Qt5 or Qt6, you can create a self-contained, portable installation of kdesrc-build in its own folder. This way, you can manage your kdesrc-build configuration files each in their own environment without mixing configurations or having to rebuild the universe every time you want to test a different one.
Set up kdesrc-build from scratch as usual.


<syntaxhighlight lang="bash">
Edit the file kdesrc-buildrc to look like:
# To not lose your previous build, make a backup:
mv ~/.config/kdesrc-buildrc ~/.config/kdesrc-buildrc~bak && mv ~/kde ~/kde~bak
# Edit ~/.bashrc file and remove the kdesrc-build block.
# Set up kdesrc-build by following just the chapter https://community.kde.org/Get_Involved/development/Set_up_a_development_environment
# Make sure to answer "No" (or press the Enter key) when it asks if
# you want to add the kdesrc-build block to ~/.bashrc.
# Do not source ~/.bashrc.
# Edit ~/.bashrc file and remove the kdesrc-build block.
# Reboot the computer or relogin such that the $PATH environment variable
# does not contain the string "~/kde" or sub directories of "~/kde".
# You should not have built anything using kdesrc-build yet.
 
# Then move the generated kdesrc-buildrc to the directory where
# you git cloned kdesrc-build:
cd ~/kde/src/kdesrc-build
mv ~/.config/kdesrc-buildrc .
 
# If the current directory is ~/kde/src/kdesrc-build, kdesrc-build will use
# the file ~/kde/src/kdesrc-build/kdesrc-buildrc even if the file
# ~/.config/kdesrc-buildrc exists.
# Edit the file paths in the file ~/kde/src/kdesrc-build/kdesrc-buildrc by
# replacing the string "/home/username/kde/src/kdesrc-build/"
# with the empty string.
# Before running kdesrc-build or kdesrc-run, always make sure that
# you are in the directory ~/kde/src/kdesrc-build
cd ~/kde/src/kdesrc-build
# Calling ~/kde/src/kdesrc-build/kdesrc-build will then use the file
# kdesrc-buildrc from the current directory:
./kdesrc-build kconfig
</syntaxhighlight>


Whenever you move or copy this portable installation of kdesrc-build to another directory, do the following:
<pre>
<pre>
# E.g. copy the existing portable kdesrc-build installation
global
# from the directory ~/kde to the directory ~/kdenew
...
cp -r ~/kde ~/kdenew # Or to any other directory.
    qt-install-dir  ~/Qt/6.7.0/gcc_64 # Where to install Qt6 if kdesrc-build supplies it
# Edit the file paths in the file ~/kdenew/src/kdesrc-build/kdesrc-buildrc
    libname lib
# E.g. replace "~/kde/" with "~/kdenew/".
...
 
end global
# Cleanup. Binary files contain file full paths starting with "~/kde"
rm -rf ~/kdenew/usr
rm -rf ~/kdenew/build
 
cd ~/kdenew/src/kdesrc-build
./kdesrc-build frameworks
</pre>
</pre>


== Two independent kdesrc-build installations on the same machine: kf6-qt6 and kf5-qt5 ==
== Two independent kdesrc-build configurations: kf6-qt6 and kf5-qt5 ==


Make a backup of your existing kdesrc-build setup.
You can switch between configurations with {{ic|--rc-file}} command line option. Generate another config, make the changes for the {{ic|source-dir}}, {{ic|build-dir}}, {{ic|install-dir}},
<code>mv ~/.config/kdesrc-buildrc ~/.config/kdesrc-buildrc~bak && mv ~/kde ~/kde~bak</code>
and other changes you want. Make sure you use different value for {{ic|persistent-data-file}} option, to not mix things up.


Set up a portable kdesrc-build from scratch in the directory <code>~/kde</code>. See the chapter [[#Portable installation of kdesrc-build]] for details. But do not run kdesrc-build to build anything.
As an alternative, you can utilize custom variable to make switch from a single config:


In the directory <code>~/kde</code> there will be a new kdesrc-build installation of type <code>kf6-qt6</code>.
{{bc-hl|shell|
global
    _ver 5  # <-- Change this to switch
    source-dir ~/kde${_ver}/src
    build-dir ~/kde${_ver}/build
    install-dir ~/kde${_ver}/usr
    persistent-data-file ~/kde${_ver}/persistent-options.json
end global


At the end of this procedure there will be two independent and portable kdesrc-build installations:
include ~/.local/share/kdesrc-build/data/build-include/kf${_ver}-qt${_ver}.ksb
* In the directory <code>~/kde</code> a kdesrc-build installation for Qt6
}}
* In the directory <code>~/kde5</code> a kdesrc-build installation for Qt5


<syntaxhighlight lang="bash">
== Other CPU architectures than x86_64/amd64 and x86 ==
# You have a kdesrc-build kf6-qt6 installation in ~/kde


# kf5-qt5 kdesrc-build installation.
You can build and develop KDE projects using a Linux OS installed on an  [[Get_Involved/development/ARM|ARM]] architecture CPU.
cp -r ~/kde ~/kde5
# Edit the file ~/kde5/src/kdesrc-build/kdesrc-buildrc such that the kdesrc-build installation becomes one of type kf5-qt5, see chapter "kdesrc-build Qt5".
# Edit the file paths in the file ~/kde5/src/kdesrc-build/kdesrc-buildrc
# E.g. replace "~/kde/" with "~/kde5/".
# Now you have a kdesrc-build kf5-qt5 installation in ~/kde5
</syntaxhighlight>


Usage:
== kdesrc-build issues ==


<syntaxhighlight lang="bash">
See https://community.kde.org/Get_Involved/development/Install_the_dependencies
# Use different terminal windows or tabs (e.g. different Konsole tabs) for
# kf5-qt5 and kf6-qt6


# Go to the terminal window or tab for kf6-qt6.
=== wayland-protocols is too old, e.g. "kdesrc-build kidletime" fails ===
cd ~/kde/src/kdesrc-build
./kdesrc-build kcalc
./kdesrc-run kcalc


# Go to the terminal window or tab for kf5-qt5.
<pre>
cd ~/kde5/src/kdesrc-build
mkdir -p ~/kde/misc && cd ~/kde/misc
./kdesrc-build plasma-systemmonitor
wget https://gitlab.freedesktop.org/wayland/wayland-protocols/-/releases/1.31/downloads/wayland-protocols-1.31.tar.xz
./kdesrc-run plasma-systemmonitor
tar -xJvf wayland-protocols-*.tar.xz && mv wayland-protocols-*/ wayland-protocols
</syntaxhighlight>
cd wayland-protocols
meson setup builddir --prefix $HOME/kde/usr
meson compile -C builddir
meson install -C builddir
</pre>


== What is the command line of the processes started by kdesrc-build ==
=== "kdesrc-build kpat" fails because of black-hole-solitaire ===


E.g. what are the command lines that are run by kdesrc-build in order to run the CMake configure step for the kconfig KDE git repository?
This happens on Debian/Ubuntu/Kubuntu. Because there is no Linux distribution binary package for https://github.com/shlomif/black-hole-solitaire.


<syntaxhighlight lang="bash">
Solution: append at the end of kdesrc-buildrc file:
kdesrc-build kconfig --no-src --no-include-dependencies --debug --refresh-build |& tee ~/a.txt
<pre>
kate ~/a.txt &
options kpat
</syntaxhighlight>
    cmake-options -DWITH_BH_SOLVER=OFF
end options
</pre>


Returns:
=== libdisplay-info is not available ===


<syntaxhighlight lang="bash">
If your Linux OS does not have a package for libdisplay-info.
Building kconfig (build system KDE CMake) from frameworks (1/1)
Append at the end of the file <code>kdesrc-buildrc</code>:
Queueing PKG_CONFIG_PATH to be set to /home/username/kde/usr/lib/pkgconfig
<pre>
Queueing LD_LIBRARY_PATH to be set to /home/username/kde/usr/lib
module libdisplay-info
Queueing PATH to be set to /home/username/kde/usr/bin:/home/username/kde/src/kdesrc-build:/home/username/.local/bin:/home/username/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  repository https://gitlab.freedesktop.org/emersion/libdisplay-info.git
Not prepending /home/username/kde/usr/lib/pkgconfig to PKG_CONFIG_PATH as it appears to already be defined in PKG_CONFIG_PATH.
end module
Queueing PKG_CONFIG_PATH to be set to /home/username/kde/usr/lib/pkgconfig
</pre>
Not prepending /home/username/kde/usr/lib to LD_LIBRARY_PATH as it appears to already be defined in LD_LIBRARY_PATH.
Queueing LD_LIBRARY_PATH to be set to /home/username/kde/usr/lib
Not prepending /home/username/kde/usr/bin to PATH as it appears to already be defined in PATH.
Queueing PATH to be set to /home/username/kde/usr/bin:/home/username/kde/src/kdesrc-build:/home/username/.local/bin:/home/username/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Queueing CMAKE_PREFIX_PATH to be set to /home/username/kde/usr
Queueing CMAKE_MODULE_PATH to be set to /home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
Queueing XDG_DATA_DIRS to be set to /home/username/kde/usr/share:/usr/share/plasma:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
Source update complete for kconfig: Skipped
cd /home/username/kde/build


Preparing build system for kconfig.
=== Building applications against Qt5 after discontinued support ===
Removing files in build directory for kconfig
Old build system cleaned, starting new build system.
cd /home/username/kde/build/kconfig


Running cmake targeting Unix Makefiles...
With [https://invent.kde.org/sysadmin/repo-metadata/-/commit/b37ae38cefd9e1c9021afd74cc43e8e64847f550 this] commit, for some applications the support of building against Qt5 was intentionally disabled.
run_logged_p(): Module kconfig, Command: {'cmake', '-B', '.', '-S', '/home/username/kde/src/kconfig', '-G', 'Unix Makefiles', '-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON', '-DCMAKE_BUILD_TYPE=Debug', '-DQT_MAJOR_VERSION=6', '-DBUILD_WITH_QT6=ON', '-DBUILD_TESTING=TRUE', '-DBUILD_WITH_QT6=ON', '-DCMAKE_CXX_FLAGS:STRING=-pipe', '-DCMAKE_INSTALL_PREFIX=/home/username/kde/usr'} from /home/username/kde/build/kconfig
cd /home/username/kde/build/kconfig


log_command(): Module kconfig, Command: cmake -B . -S /home/username/kde/src/kconfig -G Unix Makefiles -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DQT_MAJOR_VERSION=6 -DBUILD_WITH_QT6=ON -DBUILD_TESTING=TRUE -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr
If for some reason you still want to build a Qt5 version of application, you can do it with some hacks. For example, lets say we want Ark. We need to manually see its dependencies listed in metadata:
run_logged_p(): kconfig cmake complete: 0
{{bc-hl|bash|
</syntaxhighlight>
$ ~/.local/state/sysadmin-repo-metadata/dependencies/dependency-data-kf5-qt5 {{!}} grep kde/kdeutils/ark
}}


Therefore, kdesrc-build has run the following commands:
Then for each dependency, find out the branch that is used for qt5.


<syntaxhighlight lang="bash">
Then create a custom ksb file with custom module-set:
# Preparing build system for kconfig. Removing files in build directory for kconfig. Old build system cleaned, starting new build system.
rm -rf /home/username/kde/build/kconfig
mkdir -p /home/username/kde/build/kconfig


# Queueing X to be set to ...
{{hbc-hl|shell|~/ark-qt5.ksb|
PKG_CONFIG_PATH=/home/username/kde/usr/lib/pkgconfig
module-set ark-qt5
LD_LIBRARY_PATH=/home/username/kde/usr/lib
    repository kde-projects
PATH=/home/username/kde/usr/bin:/home/username/kde/src/kdesrc-build:/home/username/.local/bin:/home/username/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    use-modules \
CMAKE_PREFIX_PATH=/home/username/kde/usr
        extra-cmake-modules \
CMAKE_MODULE_PATH=/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
        karchive \
XDG_DATA_DIRS=/home/username/kde/usr/share:/usr/share/plasma:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
        kconfig \
        kcoreaddons \
        kcrash \
        kdbusaddons \
        kdoctools \
        ki18n \
        kiconthemes \
        kio \
        kparts \
        kpty \
        kservice \
        kwidgetsaddons \
        kwindowsystem \
        ark
end module-set


cd /home/username/kde/build/kconfig


cmake -B . -S /home/username/kde/src/kconfig -G Unix\ Makefiles -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DQT_MAJOR_VERSION=6 -DBUILD_WITH_QT6=ON -DBUILD_TESTING=TRUE -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr
options extra-cmake-modules
</syntaxhighlight>
    branch kf5
end options


== How to write the entire verbose STDOUT and STDERR of kdesrc-build to a file ==
options karchive
    branch kf5
end options


<pre>
options kconfig
script -eq -c "kdesrc-build kconfig --no-src --no-include-dependencies --refresh-build --debug" ~/a.txt ;  sed -i $'s/\033\[[0-9]\+m//g' ~/a.txt
    branch kf5
</pre>
end options


The <code>sed</code> part removes the terminal ANSI color escape codes.
options kcoreaddons
    branch kf5
end options


<code>script -eq -c "command" ~/a.txt</code> is better than <code>command |& tee ~/a.txt</code> because kdesrc-build behaves differently if it is run in a user interactive terminal session (<code>isatty</code>).
options kcrash
    branch kf5
end options


If using <code>tee</code>, part of the output of kdesrc-build will not be written to file. E.g. the output of the <code>cmake</code> step, the final part of the <code>make -j</code> step, the final part of the <code>make install</code> step.
options kdbusaddons
    branch kf5
end options


== Other CPU architectures than x86_64/amd64 and x86 ==
options kdoctools
    branch kf5
end options


You can build and develop KDE projects using a Linux OS installed on an  [[Get_Involved/development/ARM|ARM]] architecture CPU.
options ki18n
    branch kf5
end options


== kdesrc-build issues ==
options kiconthemes
    branch kf5
end options


=== "kdesrc-build frameworks" fails because not enough packages from the Linux OS are installed ===
options kio
    branch kf5
end options


Expand the list of packages from https://community.kde.org/Get_Involved/development/Set_up_a_development_environment#Set_up_Qt and make sure that you have these packages installed.
options kparts
    branch kf5
end options


=== "kdesrc-build workspace" fails because not enough packages from the Linux OS are installed ===
options kpty
    branch kf5
end options


* Fedora
options kservice
    branch kf5
end options


<pre>
options kwidgetsaddons
# kwin
    branch kf5
sudo dnf install libdisplay-info-devel
end options


# kio-extras
options kwindowsystem
sudo dnf install qcoro-qt6-devel
    branch kf5
end options


# kgamma5
options ark
sudo dnf install libXxf86vm-devel
    branch release/23.08
end options


# kde-gtk-config
# --
sudo dnf install rubygem-sass


# flatpak-kcm
# dependency of extra-cmake-modules
sudo dnf install flatpak-devel
options polkit-qt-1
</pre>
    branch qt5
end options


=== wayland-protocols is too old, e.g. "kdesrc-build kidletime" fails ===
# dependency of kcoreaddons
 
options plasma-wayland-protocols
<pre>
    branch master
mkdir -p ~/kde/misc && cd ~/kde/misc
end options
wget https://gitlab.freedesktop.org/wayland/wayland-protocols/-/releases/1.31/downloads/wayland-protocols-1.31.tar.xz
tar -xJvf wayland-protocols-*.tar.xz && mv wayland-protocols-*/ wayland-protocols
cd wayland-protocols
meson setup builddir --prefix $HOME/kde/usr
meson compile -C builddir
meson install -C builddir
</pre>
 
=== "kdesrc-build kpat" fails because of black-hole-solitaire ===
 
This happens on Debian/Ubuntu/Kubuntu. Because there is no Linux distribution binary package for https://github.com/shlomif/black-hole-solitaire.


Solution: append at the end of kdesrc-buildrc file:
# dependency of karchive
<pre>
options qca
options kpat
     branch qt5
     cmake-options -DWITH_BH_SOLVER=OFF
end options
end options
</pre>
}}


=== "kdesrc-build frameworks" fails because of qtwebkit ===
After that, include it in your main config:


Note: qtwebkit and kdewebkit are Qt5 only.
{{bc|1=
global
    _ver 5
    _build_with_qt6 OFF
    branch-group kf${_ver}-qt${_ver}
    cmake-options -DCMAKE_BUILD_TYPE=Debug -DQT_MAJOR_VERSION=${_ver} -DBUILD_WITH_QT6=${_build_with_qt6}
end global


Some Linux OSes do not have a package for qtwebkit anymore. E.g. the Arch Linux family.
include ~/Development/kdesrc-build/data/build-include/kf${_ver}-qt${_ver}.ksb
include ~/ark-qt5.ksb
}}


When you want to build all of the KDE Frameworks 5 using kdesrc-build, exclude kdewebkit.
Then edit the metadata file:


<pre>
{{hbc-hl|json|~/.local/state/sysadmin-repo-metadata/dependencies/logical-module-structure.json|
kdesrc-build frameworks --ignore-modules kdewebkit
...
</pre>
        "kde/*" : {
            "kf6-qt6": "master",
            "kf5-qt5": "master",  // <-- it was empty string, place "master" here
            "stable-kf6-qt6": "release/24.02",
            "stable-kf5-qt5": ""
        },
...
}}


=== libdisplay-info is not available ===
Now you are able to build Ark with qt5:


If your Linux OS does not have a package for libdisplay-info.
{{hbc|$ kdesrc-build ark-qt5 --list-build|
Append at the end of the file <code>kdesrc-buildrc</code>:
Fetching remote changes to sysadmin-repo-metadata
<pre>
Merging sysadmin-repo-metadata changes from branch master
module libdisplay-info
        * You had local changes to sysadmin-repo-metadata, which have been re-applied.
  repository https://gitlab.freedesktop.org/emersion/libdisplay-info.git
...
end module
── ark : release/23.08
</pre>
}}
 
=== gpgme fails to build ===
 
See https://bugs.kde.org/show_bug.cgi?id=472917

Revision as of 12:32, 14 April 2024

This page is the continuation with more advanced topics of the page Get_Involved/development.

kde-builder is an alternative to kdesrc-build

kdesrc-build and kde-builder are two KDE build frameworks. They are used at the command line and have identical command line syntax, just replace the string "kdesrc-build" with "kde-builder". They use the same configuration file, named kdesrc-buildrc.

kde-builder is newer and regularly gets new features and is written in Python.

kdesrc-build is in maintenance mode and feature frozen and written in Perl.

The "how to install kde-builder" procedure is here https://invent.kde.org/sdk/kde-builder/-/blob/master/README.md .

Develop in a Linux container

When you start programming for KDE, it is recommended that you use kdesrc-build in your main operating system or in a virtual machine running on a Linux operating system that is better supported by kdesrc-build.

As an alternative, you can run kdesrc-build in a Linux container (docker, podman, toolbx, distrobox).

Option 1. The KDE PIM Docker image

You can install Docker and the KDE PIM Docker image. It provides a development environment that is isolated from your day-to-day system. It is based on KDE Neon Unstable.

Option 2. distrobox

It is possible to start developing KDE software using container images that are able to see inside your home folder. This can be done using distrobox and podman.

First, install distrobox and podman from your distribution repositories:

  • Debian/Ubuntu: sudo apt install distrobox podman
  • openSUSE: sudo zypper install distrobox podman
  • Fedora: sudo dnf install distrobox podman
  • Arch: sudo pacman --sync distrobox podman

On systems which are designed for you to not tamper with their root files (immutable distributions like openSUSE Kalpa, Fedora Kinoite, and SteamOS on the Steam Deck) you can use an official alternative method to install distrobox:

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --prefix ~/.local

On the Steam Deck, you will additionally need to add ~/.local/bin to the $PATH.

Building without kdesrc-build

You can build a single repository using the KDE Neon Unstable docker image. We will be using the plasma:unstable image, which comes with the latest KDE software and libraries, and we will be using the minimal version, which requires you to install development libraries before compiling your projects.

After installing distrobox and podman, run the following to create a new distrobox container:

podman pull invent-registry.kde.org/neon/docker-images/plasma:unstable
distrobox create --image invent-registry.kde.org/neon/docker-images/plasma:unstable

This will create a distrobox container named plasma-unstable.

Note

The plasma:unstable image size is 5.6 GB.


Lastly, enter the generated container:

distrobox enter plasma-unstable

You can then just clone the desired repository in your home folder and build it while being inside the container. If any development libraries are missing, you can just install them the same way you would install on Debian/Ubuntu/KDE Neon:

sudo apt install packagename-dev

You can also use build-dep to let apt install the required libraries for the program you will be compiling. For example, to install the development libraries for Kate, you can run:

sudo apt-get build-dep kate

Building with kdesrc-build

First, install distrobox and podman from your distribution repositories. Then run:

distrobox enter

This should create a container based on your current Linux OS and enter it. It is preferable to use one of the Linux distributions that is better suited for kdesrc-build, as mentioned in this wiki page, so if your distribution does not provide very up-to-date packages, you can download and use a different container image for your distrobox from Dockerhub. For example, with openSUSE Tumbleweed:

podman pull opensuse/tumbleweed
distrobox create --image opensuse/tumbleweed --name tumbleweed
distrobox enter tumbleweed

Then it's a matter of downloading and running kdesrc-build as detailed in Get_Involved/development/Set_up_a_development_environment:

mkdir -p ~/.local/share/
cd ~/.local/share
git clone https://invent.kde.org/sdk/kdesrc-build.git
cd kdesrc-build
./kdesrc-build --initial-setup
mkdir -p ~/.local/bin
ln -sf ~/.local/share/kdesrc-build/kdesrc-build ~/.local/bin

From this point on, one important thing to bear in mind is that a distrobox container is transparent in its user space and containerized in its root space: when you are inside a distrobox container, you can see the content of system's home folder, but not your system's root folders, only the container's root folders. This means that you can install packages inside the container using root privileges and access those packages to compile your programs stored in your home, without ever installing those packages in your actual system!

You can take advantage of this by installing, for instance, Qt development packages used for kdesrc-build from inside the container. This way, it is not necessary to compile Qt with kdesrc-build. This is particularly convenient if you want to compile KDE software with Qt6 quickly.

Likewise, you should install the required dependencies from inside the distrobox rather than from your system's repositories. Then you can start compiling as usual.

After compiling your program with kdesrc-build from inside the distrobox, you can run it with kdesrc-build run, and despite it originating from inside a container and using the libraries from the container, it will run just fine as a GUI application on your system!

Note

If you are on an X11 session, you will need to create the file ~/.config/distrobox/distrobox.conf and add xhost +si:localuser:$USER to it in order for distrobox to be able to run graphical applications.


The only few gotchas to using this method are:

  • You cannot use a full Plasma Desktop session made from git.
  • You will need qqc2-desktop-style and Breeze to show the correct theme for your applications.
  • You will need the QtWayland library and its respective development package to run your applications natively on a Wayland session.

Other operating systems

Kubuntu >= 23.10

The default configuration of kdesrc-build requires Qt version 6.6. Kubuntu 23.10 has Qt version 6.4.2. It is recommended that you use a Linux OS that is better supported by kdesrc-build.

If you are a more seasoned developer you might be able to use Kubuntu for kdesrc-build by installing Qt6 using the Qt online installer or by building Qt6 using kdesrc-build.

FreeBSD

Install the latest release of FreeBSD with KDE Plasma Desktop on your hardware computer or in a virtual machine.

Your user should be member of the "wheel" user group (e.g. this can be configured in the FreeBSD installer, when creating your user you can select additional user groups for your user). Your user should be able to use sudo:

pkg install sudo
visudo
# Uncomment the line: %wheel ALL=(ALL:ALL) ALL

Then set up kdesrc-build using the same procedure as when installing kdesrc-build on a Linux operating system. FreeBSD is currently supported by kdesrc-build. See https://www.youtube.com/watch?v=8MqBnb3Y9JU

OpenBSD >= 7.5

Install OpenBSD version greater than or equal to 7.5. In the installer keep the defaults, the user created by the installer is named "administrator" in this example.

# Enable doas
su -
cp /etc/examples/doas.conf /etc/doas.conf
exit
# kdesrc-build needs sudo.
mkdir -p ~/.local/bin ; ln -s /usr/bin/doas ~/.local/bin/sudo
echo "export PATH=~/.local/bin:\$PATH" >> ~/.bashrc

# Test doas.
doas su
# kde-builder needs bash.
pkg_add bash
chsh -s /usr/local/bin/bash
exit

# As user administrator
chsh -s /usr/local/bin/bash

# As per https://rsadowski.de/posts/2024-01-09-openbsd-kde/ , https://openports.pl/path/meta/kde,-plasma
doas su
pkg_add kde-plasma kate

# I recommend that you use tigervnc. https://nmariusp.github.io/install-os.html#openbsd--75

After you install kdesrc-build:

# Edit the kdesrc-buildrc file e.g.:
cmake-options -DCMAKE_BUILD_TYPE=RelWithDebInfo -DKF_IGNORE_PLATFORM_CHECK=ON

# Also set environment variable:
export CMAKE_PREFIX_PATH=/usr/local/lib/qt6/cmake
# Or
export CMAKE_PREFIX_PATH=/usr/local/lib/qt5/cmake

Microsoft Windows

You can build and develop KDE projects using the Microsoft Windows operating system.

Apple macOS

You can build and develop KDE projects using the Apple macOS operating system.

What to do if CMake configure fails because a build dependency is missing

See https://community.kde.org/Get_Involved/development/Install_the_dependencies .

Project Documentation

Developer's documentation can be found in the doc/source-reference in the project repo.

kf6-qt6 vs. kf5-qt5

Many KDE git repositories can build correctly and run correctly using "kdesrc-build kf6-qt6".

The KDE git repositories that can build correctly and run correctly using "kdesrc-build kf6-qt6" have two long lived git branches:

  • A long lived git branch that does not contain the deprecated symbols from kf5-qt5, named e.g. "master".
  • And another long lived git branch for qt5-kf5, where the deprecated symbols still exist.

What is "kf6-qt6"? You just set up kdesrc-build following the procedure. The resulting kdesrc-build installation will be of type kf6-qt6. In kdesrc-buildrc in the "global" section you will have "branch-group kf6-qt6". The git repositories that have only one long lived git branch e.g. named "master" will use that. The git repositories that have a second long lived git branch, will use the git branch where the deprecated symbols do not exist e.g. named "master".

What is "kf5-qt5"? Follow the chapter "kdesrc-build Qt5". The resulting kdesrc-build installation will be of type kf5-qt5. In kdesrc-buildrc in the "global" section you will have "branch-group kf5-qt5". The git repositories that have only one long lived git branch e.g. named "master" will use that. The git repositories that have a second long lived git branch where the deprecated symbols still exist e.g. named "kf5" will use that.

Build Qt using kdesrc-build

Qt6

If you cannot build the KDE frameworks using kdesrc-build and the Qt provided by your Linux distribution is outdated, you might want to build the Qt framework using kdesrc-build.

In your configuration file use the qt-install-dir option (in the global section) with non-empty value, for example:

global
  qt-install-dir ~/kde/usr
  branch-group kf6-qt6
end global

It is recommended that if you build Qt6 using kdesrc-build, you also build qtwebengine. Edit the file ~/.local/state/sysadmin-repo-metadata/module-definitions/qt6.ksb. Follow the instructions found in the file: if you want qtwebengine, add it to use-modules after "qtwebchannel" and comment out the line "ignore-modules qtwebengine".

Then build Qt6:

kdesrc-build qt6-set

To compile Qt6 with Qt X11 Extras (which is a necessary library to compile KWindowSystem), you should enable XCB feature during compilation

kdesrc-build qt6-set --cmake-options="-DQT_FEATURE_xcb=ON"

Qt5

If you want the same for Qt5, change branch-group option and use qt5-set instead of qt6-set.

Qt 6 installed using the Qt online installer

A screen recording version is available https://www.youtube.com/watch?v=3BIbYN2vIZw

The homepage of the Qt Framework is https://www.qt.io . Go to this web page, create an online account. https://www.qt.io/download-open-source > "Download the Qt Online Installer" > Linux > "Qt Online Installer for Linux (64-bit)" > download a file named e.g. qt-unified-linux-x64-4.6.1-online.run into the directory e.g. "~/Downloads".

ls -la ~/Downloads # The downloaded file needs to have the "executable" chmod bit set.
chmod u+x ~/Downloads/qt-unified-linux-x64-4.6.1-online.run
~/Downloads/qt-unified-linux-x64-4.6.1-online.run

A graphical user interface (GUI) installer wizard starts. Login using your Qt online account. Next > check the checkbox "I have read and agree to the terms and conditions of using OpenSource Qt", check the checkbox "I'm an individual and do not use Qt for any company" > Next > Next > enable "Help us improve" > Next > Custom installation, notice that the install directory is "~/Qt" > Next. Install the latest version of Qt6 and the latest version of the Qt Creator integrated development environment (IDE). There are some Qt6 components that are not used by KDE and can be left out when installing Qt6 e.g. Qt Design Studio, WebAssembly, Android, Sources, Qt Quick 3D, Qt 3D, Qt Quick 3D Physics, "Qt Debug Information Files". Next > enable "I have read and agree" > Next > Install.

In the KDE Plasma app launcher (start menu) you now have the application "Qt Maintenance Tool".

Set up kdesrc-build from scratch as usual.

Edit the file kdesrc-buildrc to look like:

global
...
    qt-install-dir  ~/Qt/6.7.0/gcc_64 # Where to install Qt6 if kdesrc-build supplies it
    libname lib
...
end global

Two independent kdesrc-build configurations: kf6-qt6 and kf5-qt5

You can switch between configurations with --rc-file command line option. Generate another config, make the changes for the source-dir, build-dir, install-dir, and other changes you want. Make sure you use different value for persistent-data-file option, to not mix things up.

As an alternative, you can utilize custom variable to make switch from a single config:

global
    _ver 5  # <-- Change this to switch
    source-dir ~/kde${_ver}/src
    build-dir ~/kde${_ver}/build
    install-dir ~/kde${_ver}/usr
    persistent-data-file ~/kde${_ver}/persistent-options.json
end global

include ~/.local/share/kdesrc-build/data/build-include/kf${_ver}-qt${_ver}.ksb

Other CPU architectures than x86_64/amd64 and x86

You can build and develop KDE projects using a Linux OS installed on an ARM architecture CPU.

kdesrc-build issues

See https://community.kde.org/Get_Involved/development/Install_the_dependencies

wayland-protocols is too old, e.g. "kdesrc-build kidletime" fails

mkdir -p ~/kde/misc && cd ~/kde/misc
wget https://gitlab.freedesktop.org/wayland/wayland-protocols/-/releases/1.31/downloads/wayland-protocols-1.31.tar.xz
tar -xJvf wayland-protocols-*.tar.xz && mv wayland-protocols-*/ wayland-protocols
cd wayland-protocols
meson setup builddir --prefix $HOME/kde/usr
meson compile -C builddir
meson install -C builddir

"kdesrc-build kpat" fails because of black-hole-solitaire

This happens on Debian/Ubuntu/Kubuntu. Because there is no Linux distribution binary package for https://github.com/shlomif/black-hole-solitaire.

Solution: append at the end of kdesrc-buildrc file:

options kpat
    cmake-options -DWITH_BH_SOLVER=OFF
end options

libdisplay-info is not available

If your Linux OS does not have a package for libdisplay-info. Append at the end of the file kdesrc-buildrc:

module libdisplay-info
  repository https://gitlab.freedesktop.org/emersion/libdisplay-info.git
end module

Building applications against Qt5 after discontinued support

With this commit, for some applications the support of building against Qt5 was intentionally disabled.

If for some reason you still want to build a Qt5 version of application, you can do it with some hacks. For example, lets say we want Ark. We need to manually see its dependencies listed in metadata:

$ ~/.local/state/sysadmin-repo-metadata/dependencies/dependency-data-kf5-qt5 | grep kde/kdeutils/ark

Then for each dependency, find out the branch that is used for qt5.

Then create a custom ksb file with custom module-set:

~/ark-qt5.ksb
module-set ark-qt5
    repository kde-projects
    use-modules \
        extra-cmake-modules \
        karchive \
        kconfig \
        kcoreaddons \
        kcrash \
        kdbusaddons \
        kdoctools \
        ki18n \
        kiconthemes \
        kio \
        kparts \
        kpty \
        kservice \
        kwidgetsaddons \
        kwindowsystem \
        ark
end module-set


options extra-cmake-modules
    branch kf5
end options

options karchive
    branch kf5
end options

options kconfig
    branch kf5
end options

options kcoreaddons
    branch kf5
end options

options kcrash
    branch kf5
end options

options kdbusaddons
    branch kf5
end options

options kdoctools
    branch kf5
end options

options ki18n
    branch kf5
end options

options kiconthemes
    branch kf5
end options

options kio
    branch kf5
end options

options kparts
    branch kf5
end options

options kpty
    branch kf5
end options

options kservice
    branch kf5
end options

options kwidgetsaddons
    branch kf5
end options

options kwindowsystem
    branch kf5
end options

options ark
    branch release/23.08
end options

# --

# dependency of extra-cmake-modules
options polkit-qt-1
    branch qt5
end options

# dependency of kcoreaddons
options plasma-wayland-protocols
    branch master
end options

# dependency of karchive
options qca
    branch qt5
end options

After that, include it in your main config:

global
    _ver 5
    _build_with_qt6 OFF
    branch-group kf${_ver}-qt${_ver}
    cmake-options -DCMAKE_BUILD_TYPE=Debug -DQT_MAJOR_VERSION=${_ver} -DBUILD_WITH_QT6=${_build_with_qt6}
end global

include ~/Development/kdesrc-build/data/build-include/kf${_ver}-qt${_ver}.ksb
include ~/ark-qt5.ksb

Then edit the metadata file:

~/.local/state/sysadmin-repo-metadata/dependencies/logical-module-structure.json
...
        "kde/*" : {
            "kf6-qt6": "master",
            "kf5-qt5": "master",  // <-- it was empty string, place "master" here
            "stable-kf6-qt6": "release/24.02",
            "stable-kf5-qt5": ""
        },
...

Now you are able to build Ark with qt5:

$ kdesrc-build ark-qt5 --list-build
Fetching remote changes to sysadmin-repo-metadata
Merging sysadmin-repo-metadata changes from branch master
        * You had local changes to sysadmin-repo-metadata, which have been re-applied.
...
 ── ark : release/23.08