(before-building)=
# Preparing the System to Build KDE

(before-building-users)=
## Setup a new user account

It is recommended that you use a different user account to build,
install, and run your KDE software from, since less permissions are
required, and to avoid interfering with your distribution's packages. If
you already have KDE packages installed, the best choice would be to
create a different (dedicated) user to build and run the new KDE.

```{tip}
Leaving your system KDE untouched also allows you to have an emergency
fallback in case a coding mistake causes your latest software build to
be unusable.
```

You can do also setup to install to a system-wide directory (⪚
`/usr/src/local`) if you wish. This document does not cover this
installation type, since we assume you know what you are doing.

(before-building-preparation)=
## Ensure your system is ready to build KDE software

Before using the kdesrc-build script (or any other building strategy)
you must install the development tools and libraries needed for KDE. The
nearly complete list of required tools can be found from the [KDE
Community Wiki Build
Requirements](https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source#Install_required_devel_packages)
page.

Here is a list of some of the things you will need:

- You will need CMake, this software is what KDE uses to handle
  build-time configuration of the source code and generation of the
  specific build commands for your system. The required version will
  vary depending on what versions of KDE software you are building (see
  TechBase for specifics), but with modern distributions the CMake
  included with your distribution should be quite sufficient.

- You must also install the source control clients needed to checkout
  the KDE source code. This means you need at least the following:

  - The [Git source control manager](https://git-scm.com/), which is
    used for all KDE [source code]( https://commits.kde.org/)

  - Although it is not required, the
    [Bazaar](http://bazaar.canonical.com/) source control manager is
    used for a single module (libdbusmenu-qt) that is required for the
    KDE libraries. Most users can install this library through their
    distribution packages but kdesrc-build supports building it as well
    if you desire. But to build libdbusmenu-qt, you must have Bazaar
    installed.

- The Perl scripting language is required for kdesrc-build, some KDE
  repositories, and Qt (if you build that from source).

  The Perl that comes with your distribution should be suitable (it
  needs to be at least Perl 5.14), but you will also need some
  additional modules (kdesrc-build will warn if they are not present):

  - IO::Socket::SSL

  - JSON::PP or JSON::XS

  - YAML::PP, YAML::XS, or YAML::Syck

- You will need a full C++ development environment (compiler, standard
  library, runtime, and any required development packages). The minimum
  required versions vary based on the KDE module: the KDE Frameworks 5
  collection supports the oldest compilers, while KDE Plasma 5 and KDE
  Applications tend to require more recent compilers.

  The GCC 4.8 or Clang 4 compilers are the minimum recommended. Many
  distributions support easily installing these tools using a
  “build-essentials” package, an option to install "build dependencies"
  with Qt, or similar features. The KDE Community Wiki has a page
  [tracking recommended packages for major
  distributions](https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source/Install_the_dependencies).

- You will need a build tool that actually performs the compilation
  steps (as generated by CMake). GNU Make is recommended and should be
  available through your package manager. CMake does support others
  options, such as the Ninja build tool, which can be used by
  kdesrc-build using the
  [custom-build-command](#conf-custom-build-command) configuration file
  option.

- Finally, you will need the appropriate Qt libraries (including
  development packages) for the version of KDE software you are
  building. kdesrc-build does not officially support building Qt 5 (the
  current major version), so it is recommended to use your
  distribution's development packages or to see the KDE Community wiki
  page on [self-building Qt
  5](https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source/OwnQt5).

```{note}
Most operating system distributions include a method of easily
installing required development tools. Consult the Community Wiki page
[Required devel
packages](https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source#Install_required_devel_packages)
to see if these instructions are already available.
```

```{important}
Some of these packages are divided into libraries (or programs or
utilities), and development packages. You will need at least the program
or library *and* its development package.
```

(before-building-prepare-script)=
## Setup kdesrc-build

(get-kdesrc-build)=
### Install kdesrc-build

The KDE developers make frequent changes to kdesrc-build to keep it in
sync with advances in KDE development, including improvements to the
recommended kdesrc-build configuration, added modules, improving CMake
flags, etc

Because of this, we recommend obtaining kdesrc-build directly from its
source repository and then periodically updating it.

You can obtain kdesrc-build from its source repository by running:

```
$ git clone https://invent.kde.org/sdk/kdesrc-build.git ~/kdesrc-build
```

Replace `~/kdesrc-build` with the directory you would like to install
to.

You can update kdesrc-build later by running:

```
$ cd ~/kdesrc-build
$ git pull
```

```{tip}
We recommend adding the kdesrc-build installation directory to your
`PATH` environment variable, so that you can run kdesrc-build without
having to fully specify its path every time.
```

(setup-rcfile)=
### Prepare the configuration file

kdesrc-build uses a [configuration file](./configure-data) to control
which modules are built, where they are installed to, etc. This file is
located at `~/.config/kdesrc-buildrc`
(`$XDG_CONFIG_HOME/kdesrc-buildrc`, if `$XDG_CONFIG_HOME` is set).

You can use kdesrc-build --generate-config in order to prepare a simple
kdesrc-build configuration. You can then edit the
`~/.config/kdesrc-buildrc` configuration file to make any changes you
see fit.

(setup-rcfile-manually)=
#### Manual setup of configuration file

You can also setup your configuration file manually, by copying the
included sample configuration file `kdesrc-buildrc-kf5-sample` to
`~/.config/kdesrc-buildrc` and then editing the file.
[](../chapter_04/index) will be a useful reference for this, especially
its [table of configuration options](../chapter_04/conf-options-table).

kdesrc-build contains many recommended configuration files to support
KDE Frameworks 5, Plasma 5, and other KDE applications. See the section called
[](#kdesrc-buildrc-including) for information on how to use other
configuration files from your own `kdesrc-buildrc`.

You can find more information about the syntax of the [configuration
file](./configure-data) in the section called [](./configure-data) and in
[](../chapter_04/index).
