Get Involved/development/More

From KDE Community Wiki

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

This paged is not meant for people that are starting to program for KDE.

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 rolling-release Linux distribution (Arch, openSUSE Tumbleweed, KDE neon) or running on e.g. the latest version of Fedora KDE Spin or Kubuntu.

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

Or, you can just create a long lived (pet not cattle) container using distrobox and podman (or docker). See https://www.youtube.com/watch?v=9JEALbcmcCg https://github.com/89luca89/distrobox

Start with the official Docker hub container image of one of the Linux distributions that is better suited for kdesrc-build. Then setup kdesrc-build in the container. distrobox makes it such that you can run GUI apps in the container. Also, your user's home directory (~) is the same in the host operating system and in the container. Warning: the container will write to your home directory and may conflict with your host operating system.

Other operating systems

FreeBSD

Install the latest release of FreeBSD with KDE Plasma Desktop on your hardware computer or in a virtual machine. 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

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.

Advanced kdesrc-build

Note: these resources might not be up to date.

See the kdesrc-build manual, Readme #1, Readme #2, Document #3 for more kdesrc-build information and options.

Build Qt using kdesrc-build

Set up kdesrc-build from scratch as usual.

Open the configuration file ~/.config/kdesrc-buildrc and confirm that qtdir and the lines include...qt5-build-include and include...custom-qt5-libs-build-include are not commented out (i.e. there should not be a # in front of the lines). E.g. (replace "username" with your Linux user's name):

qtdir ~/kde/usr # Where to make install Qt5
include /home/username/kde/src/kdesrc-build/qt5-build-include
include /home/username/kde/src/kdesrc-build/custom-qt5-libs-build-include

Run in a terminal:

kdesrc-build Qt5
kdesrc-build frameworks

kdesrc-build, Qt6 and KDE Frameworks 6

Set up kdesrc-build clean from scratch following the same procedure as when using "Qt5 and KDE Frameworks 5". Before building anything using kdesrc-build, do:

sed -i 's/kf5-common/kf6-common/' ~/.config/kdesrc-buildrc
sed -i 's/kf5-qt5/kf6-qt6/' ~/.config/kdesrc-buildrc

The file ~/.config/kdesrc-buildrc should contain the not commented out lines:

include /home/username/kde/src/kdesrc-build/kf6-common-options-build-include
...
include /home/username/kde/src/kdesrc-build/kf6-qt6-build-include

In the file ~/.config/kdesrc-buildrc, in the "global" section, the line "cmake-options" should contain "-DBUILD_WITH_QT6=ON".

Then build KDE Frameworks 6:

kdesrc-build frameworks

Note: kdesrc-build --initial-setup does not install the packages needed for building with kdesrc-build "Qt6 and KDE Frameworks 6". The instructions on how to install the dependencies are for "Qt5 and KDE Frameworks 5" only, they do not work for "Qt6 and KDE Frameworks 6". Therefore many kdesrc-build modules will fail to build because of missing dependencies (CMake errors).

Install the dependencies

See below for some ideas about how to find out what Linux packages you need to install.

E.g. I am on Kubuntu 22.10, kdesrc-build frameworks fails, module kcoreaddons has CMake (configure) error Could NOT find Qt6LinguistTools (missing: Qt6LinguistTools_DIR).

Option 1:

Search on the internet for ubuntu packages Qt6LinguistTools it returns https://packages.ubuntu.com/kinetic/amd64/qt6-tools-dev Expand "amd64 [list of files]": /usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/Qt6LinguistToolsConfig.cmake

sudo apt install qt6-tools-dev

Option 2:

sudo apt install apt-file
sudo apt-file update
apt-file find Qt6LinguistToolsConfig.cmake
# qt6-tools-dev: /usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/Qt6LinguistToolsConfig.cmake
sudo apt install qt6-tools-dev

If the error is:

The imported target "Qt6::qtwaylandscanner" references the file
     "/usr/lib/qt6/libexec/qtwaylandscanner"
but this file does not exist.

Then:

apt-file find /usr/lib/qt6/libexec/qtwaylandscanner
# qt6-wayland-dev-tools: /usr/lib/qt6/libexec/qtwaylandscanner
sudo apt install qt6-wayland-dev-tools

Option 3:

apt search linguist | grep qt6
# linguist-qt6/kinetic 6.3.1-2 amd64
sudo apt install linguist-qt6

Ubuntu

sudo apt install qt6-tools-dev qt6-declarative-dev libqt6core5compat6-dev qt6-wayland-dev qt6-wayland-dev-tools qt6-base-private-dev libqt6svg6-dev libqt6opengl6-dev libqt6shadertools6-dev

Build Qt6 using kdesrc-build

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 following the same procedure as when using "Qt5 and KDE Frameworks 5".

Edit two files:

cat ~/.config/kdesrc-buildrc
# 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

global
    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 Qt5 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 16
    num-cores-low-mem 12

    # 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

# With base options set, the remainder of the file is used to define modules to build, in the
# 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
# 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
# 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

# KF5 and Plasma :)
#include /home/username/kde/src/kdesrc-build/kf6-qt6-build-include

# To change options for modules that have already been defined, use an
# 'options' block. See kf6-common-options-build-include for an example

cat ~/kde/src/kdesrc-build/qt6-build-include 
# 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.4

    # Controls where Qt6 is installed
    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 qtshadertools qtdeclarative qtsvg qttools \
        qtimageformats qtmultimedia qtwayland                    \
        qtwebsockets qtwebchannel qtwebengine qtwebview qtsensors            \
        qtnetworkauth qt5compat qtdoc

    # 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: