Guidelines and HOWTOs/Build from source

From KDE Community Wiki
Revision as of 13:42, 23 September 2016 by Apol (talk | contribs) (→‎Run Kdevelop: my eyes!)

Build KDE Frameworks and Applications

Safety Precautions

Configuring your build environment is the single most important step in building KDE. Luckily, KDE frameworks development libraries are packaged by most major distributions. In general, building and installing user space programs such as Calligra can be done safely without altering any system files. Whenever possible, it is recommended that you build KDE using your normal user account. Unless you are interested in changing the behavior of your system, you should build with a normal account. Even if you are a a KWin or Plasma developer wishing to test a full KDE session with compositing effects, there are ways to construct the desired testing bed entirely within your normal user account, e.g. running Plasma through a nested X server using xypher.

However, to permanently alter your KDE/Plasma desktop environment through new System Configuration Modules and the like, you will often need to install shared libraries and other files in system folders. In these cases, bad installation can render your system unstable or your desktop environment unusable. Always take caution before executing any commands as root! A sudo make install can not always be undone by a simple sudo make uninstall. Technologies like containerization may help solve these problems in the future, but current distribution systems have no way to monitor the alterations you make to system shared libraries as the system administrator. Always keep records of what you are doing and make sure you know how to access the install logs to give yourself a better chance of reverting files by hand if necessary. And of course, please keep high quality, frequent backups of your data.

Configuration scripts

A set of configuration scripts and bash commands are provided as a recommended configuration when building KDE manually. If you use these as provided then your KDE build will be a lot easier and it will be easier for you to find support online. The one disadvantage to these scripts is that they hide important details from you which you may want to learn about. However the scripted and by-hand methods are completely interchangeable so once you are comfortable building KDE using the scripts you can learn more by doing everything yourself.

If you want to do the work by hand you can follow the detailed instructions.

Install required devel packages

This section provides information about required and optional software packages needed to build the KDE applications.

Qt5 is the base of KDE software. Your distro provides suitable devel packages. Optionally, you can build your own Qt5.

Follow this page to install the required dependencies.

Git remote prefix

Let's setup a "kde:" prefix for git commands. Add the following text to your ~/.gitconfig:

[url "git://anongit.kde.org/"]
   insteadOf = kde:
[url "ssh://[email protected]/"]
   pushInsteadOf = kde:

kdesrc-build

kdesrc-build is a user-space package manager. It is used to compile KDE-related projects from source, and to install them into a designated directory.

This guide assumes that

  • you want to install KDevelop inside your home directory,
  • you want to put sources, build and log files into separate subdirectories under ~/kde, as well as install everything to ~/kde/usr, and
  • you use a Linux system and are familiar with bash.

Make sure to adapt these steps to your needs.

Install kdesrc-build

Start off by installing kdesrc-build and creating a basic configuration file:

mkdir -p ~/kde/src
cd ~/kde/src
git clone kde:kdesrc-build
cd kdesrc-build
cp kdesrc-buildrc-kf5-sample ~/.kdesrc-buildrc

# Install a symlink of kdesrc-build to a location in PATH
mkdir ~/bin
ln -s $PWD/kdesrc-build ~/bin
export PATH=~/bin:$PATH

You will need to append the line export PATH=~/bin:$PATH to your ~/.bashrc so kdesrc-build is available in PATH whenever you open a terminal.


Configure kdesrc-build

Edit ~/.kdesrc-buildrc and replace /path/to/kdesrc-build/kf5-qt5-build-include with ~/kdesrc/kdesrc-build/kf5-qt5-build-include. Add ignore-kde-structure true and make-options -jN to the global section. Finally, point kdesrc-build to the correct source, build, log, and install directories.

global
  ...
  # Do not introduce an extra directory hierarchy
  ignore-kde-structure true

  # set the number of jobs to 5; this should usually
  # be (number-of-cpu-cores + 1)
  make-options      -j5

  # Stop kdesrc-build
  #stop-on-failure  true

  # Directory structure
  source-dir        ~/kde/src
  build-dir         ~/kde/src
  log-dir           ~/kde/log
  kdedir            ~/kde/usr
  ...
end global

Run kdesrc-build

To let kdesrc-build handle the compilation and installation of KDevelop and its (direct) dependencies, type

$ kdesrc-build --debug libkomparediff2 grantlee kdevplatform kdevelop-pg-qt kdevelop

The --debug parameter will give you the verbose output, all command invocations and compiler output. Helpful for trouble-shooting. If you want to compile and install indirect dependencies as well, make sure to add the --include-dependencies parameter as well.

Set up a script for preparing the environment

Copy and use these commands to a new file called ~/kde/.setup/env:

export KF5=~/kde/usr
export QTDIR=/usr  
export CMAKE_PREFIX_PATH=$KF5:$CMAKE_PREFIX_PATH  
export XDG_DATA_DIRS=$KF5/share:$XDG_DATA_DIRS:/usr/share  
export XDG_CONFIG_DIRS=$KF5/etc/xdg:$XDG_CONFIG_DIRS:/etc/xdg  
export PATH=$KF5/bin:$QTDIR/bin:$PATH  
export QT_PLUGIN_PATH=$KF5/lib/plugins:$KF5/lib64/plugins:$KF5/lib/x86_64-linux-gnu/plugins:$QTDIR/plugins:$QT_PLUGIN_PATH  
# (lib64 instead of lib on some systems, like OpenSUSE)
export QML2_IMPORT_PATH=$KF5/lib/qml:$KF5/lib64/qml:$KF5/lib/x86_64-linux-gnu/qml:$QTDIR/qml  
export QML_IMPORT_PATH=$QML2_IMPORT_PATH  
export KDE_SESSION_VERSION=5  
export KDE_FULL_SESSION=true
PS1="(kdesrc) $PS1"

A guide for building Plasma 5 specifically on Ubuntu 14.04 LTS can be found here.

Run KDevelop

Whenever you want to run a self-compiled KDevelop, you just have to do the following commands in terminal:

 $ source ~/kde/.setup/env
 $ kdevelop

Analyse and fix build errors

If kdesrc-build shows you red module names with messages like "Unable to configure plasma-mediacenter with CMake!" or "Unable to build kdepim!", you have to start troubleshooting.

<<<  PACKAGES FAILED TO BUILD  >>>
libkomparediff2 - ~/kde/log/<build-date>/libkomparediff2/error.log  :-(

Inspect that log to figure out what's going on:

 $ cat ~/kde/log/<build-date>/libkomparediff2/error.log
CMake Error at CMakeLists.txt:5 (find_package):
  Could not find a package configuration file provided by "ECM" (requested
  version 0.0.9) with any of the following names:
   ECMConfig.cmake
   ecm-config.cmake
  Add the installation prefix of "ECM" to CMAKE_PREFIX_PATH or set "ECM_DIR"
  to a directory containing one of the above files.  If "ECM" provides a
  separate development package or SDK, be sure it has been installed.

In this case, the ECM (extra cmake modules) package is missing. Since ECM is a KDE Framework, this error would have been avoided by the --include-dependencies parameter mentioned above.

However, this might also happen with dependencies that kdesrc-build is not able to handle itself. In such cases, you have to install additional packages via your system package manager. Most distribution offer ways to determine which package contains the missing files.

For Ubuntu, you would head over to http://packages.ubuntu.com and search for the distro package providing a particular file (ECMConfig.cmake in this case). The package search reveals extra-cmake-modules being a hot candidate; to fix above error we simply install the package and the restart the build:

 $ apt-get install extra-cmake-modules
 $ kdesrc-build ...

The error should be gone now.

Testing

Running unit tests

Unit tests are ran from the build dir of each framework; you should first cd into it.

You need a separate DBus session because the dbus server needs to have the right value of XDG_DATA_DIRS, in order to find $KF5/share/dbus-1/services for starting services (e.g. kded5).

 $ eval `dbus-launch`
 $ kdeinit5
 $ make test

Note: Regular apps will start kdeinit5 automatically. The reason it has to be started by hand when running unit tests is some strange interaction with ctest.

Warning: never start a KDE 4 application in this separate DBus session. It would conflict with your running Plasma 4 desktop.

Note: KDE_FULL_SESSION=true is needed to make sure that the correct QPA will be loaded.

Many of the tests require an X server, and will pop up windows briefly. An easy way to allow these tests to run without interfering with your normal X session is to do

 $ xvfb-run -s '-screen 0 1024x768x24' make test

The -s argument tells Xvfb to set the first screen to be 1024x768 pixels, with a depth of 24; at least one test requires a depth greater than 8. In this case, if you also ensure DBUS_SESSION_BUS_ADDRESS is not set, the tests should not find your existing DBus session, and instead launch a new DBus instance.

Note that the KWindowSystem tests require a NETWM-compatible window manager to be running. One way to do this is to create a script to run such a window manager, followed by whatever is passed to it. For example, if you have the window manager awesome installed, you could create a script called awesome-run as follows:

#!/bin/sh
awesome &
exec "$@"

and then run the tests as

xvfb-run -s '-screen 0 1024x768x24' /path/to/awesome-run make test

If you want to publish your test results, instead of "make test" run

make Experimental

The test results will appear on http://my.cdash.org/index.php?project=<projectname>

Testing Plasma

The following page details how to test Plasma.

Troubleshooting

Compilation: how to quickly solve build problems

Situation:

One or more modules fail to build via kdesrc-build (displayed in red font).

Steps to solve (in the given order):

The following steps assume the directory structure as proposed in the kdesrc-build guide above.

  1. You may not have all dependencies installed. Read the output to see what missing dependency it is complaining about, search for the corresponding package for your distro, and install it.
  2. Check the list of currently broken modules on the KDE build server.
  3. If you get a build failure, simple fix might be to delete the build folder for that module and try building it again.
  4. See Analyse and fix build errors.
  5. Delete ~/kde/build and ~/kde/usr. Run kdesrc-build again.
  6. Ask for help on IRC or some mailing list, see Communicating with the team.
  7. Check if there are changes in the build instructions: see History of this wiki page.
  8. Start over from scratch.

Runtime: Segfault when a sound is about to play (e.g. for a message box)

(added: 2015-02-27)

Example of the problem: open kate, edit some file without saving, Ctrl+W to close, a message box is about to appear and the then segfault:

 kate(9037)/default KNotificationManager::notify: Calling notify on "Sound"
 Segmentation fault

This command can solve the problem:

 $ sudo /usr/lib64/vlc/vlc-cache-gen -f /usr/lib64/vlc/plugins

See also:

Alternative: go to kf5/build/kdesupport/phonon/phonon-vlc/ and exec `make uninstall`

Runtime: kded5 crashes because of some component

(added: 2015-Jan)

Situation: kded5 is started but crashes because of some dependency. Stacktraces show for example `bluedevil` as possible cause.

Goal 1: Disable the component to verify it as crash cause.

Steps:

  1. Locate bluedevil files using locate bluedevil, for example.
  2. Among the files there is kde/usr/share/kservices5/kded/bluedevil.desktop. Remove it. If it was the cause, kded should stop crashing

Goal 2: Remove bluedevil from kdesrcbuild until it gets fixed.

Steps:

  1. Search through the dev/kf5/src/extragear/utils/kdesrc-build/*-build-include files to find the component. In this case, it was found in kf5-workspace-build-include.
  2. Comment it out:
 # module-set kf5-bluetooth-management
 #     repository kde-projects
 #     use-modules libbluedevil bluedevil
 # end module-set

Further calls of kdesrc-build will not include the component.

Runtime: Couldn't start kded5 (KDE4)

(added: 2014-Dec)

Situation: Developing and executing KF5 apps under KDE 4.

Problem by example: Error message on console when starting ksnapshot in KF5 environment

ksnapshot(26577)/default KSycocaPrivate::checkDatabase: Couldn't start kded5 from org.kde.kded5.service: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kded5 was not provided by any .service files") , falling back to running kbuildsycoca5

Solution (not verified yet): As said in the article, run this command before starting the app itself:

 $ . ~/kde/.setup/env       # (or as your script is called)
 $ eval `dbus-launch`    # no output expected
 $ ksnapshot             # no kded5 error message expected

Runtime: Icon theme was changed (KDE4)

(added: 2014-Oct, verified: 2015-Feb)

Situation: developing and executing KF5 apps under KDE 4.

Problem: After working a bit with KF5 applications, your regular KDE icon theme might be changed from oxygen to breeze.

Solution: see https://forum.kde.org/viewtopic.php?f=67&t=25032: Open "Icons - KDE Control Module" and change the theme back to Oxygen.

Get more help

If you still have trouble with the building process or runtime setup, you can contact people as described in Communicating with the team.

Feel free to join us by visiting #kde-devel on Freenode. A web-based client can be found at https://kiwiirc.com/client/irc.freenode.org/kde-devel

Alternative building methods

Kubuntu CI

Kubuntu CI (replaces Project Neon 5) provides packages of KDE Git master for KDE Frameworks and Plasma 5. Install them on your Kubuntu system to work with KDE Git.

Docker