Guidelines and HOWTOs/Build from source: Difference between revisions

From KDE Community Wiki
(→‎openSUSE 42.1: needs polkit-devel)
(98 intermediate revisions by 18 users not shown)
Line 1: Line 1:
= Build requirements =
= Build KDE Frameworks and Applications =
This section provides information about '''hard''' (required) and '''optional''' software packages needed to build the KDE Framework.


=== Dependencies ===
== Safety Precautions ==
*'''deb-based distributions (Debian, Kubuntu...):'''  
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.
  <pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">$ sudo apt-get build-dep qtbase5-dev
 
$ sudo apt-get install libbz2-dev libxslt-dev libxml2-dev shared-mime-info oxygen-icon-theme libgif-dev libvlc-dev libvlccore-dev doxygen gperf bzr libxapian-dev fontforge libgcrypt20-dev libattr1-dev network-manager-dev libgtk-3-dev xsltproc xserver-xorg-dev xserver-xorg-input-synaptics-dev libpwquality-dev modemmanager-dev libxcb-keysyms1-dev libepoxy-dev libpolkit-agent-1-dev libnm-util-dev libnm-glib-dev libegl1-mesa-dev libxcb-xkb-dev libqt5x11extras5-dev libwww-perl libxml-parser-perl libjson-perl libboost1.55-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libarchive-dev liblmdb-dev
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 <code>sudo make install</code> '''can not always be undone by''' a simple <code>sudo make uninstall.</code> 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.
</pre>
 
== 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.


*'''openSUSE:''' All the necessary dependencies:
If you want to do the work by hand you can follow the [[/Details|detailed instructions]] else continue here on.
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">$ sudo zypper si -d libqt5-qtbase
$ sudo zypper in libbz2-devel libxslt-devel libxml2-devel shared-mime-info oxygen-icon-theme giflib-devel vlc-devel doxygen gstreamer-0_10-devel gstreamer-0_10-plugins-base-devel docbook-xml-slides docbook-xsl-stylesheets xcb-util-keysyms-devel perl-JSON boost-devel libxcb-devel libXrender-devel xcb-util-wm-devel xcb-util-devel xcb-util-image-devel gettext-tools libepoxy-devel
$ sudo zypper in gtk3-devel # for kde-gtk-config
$ sudo zypper in grantlee5 # for kdevplatform
$ sudo zypper in libkdcraw-devel liblcms2-devel # for gwenview
</pre>
Optional for kdeplasma-addons: libibus >=1.4.2 (see http://software.opensuse.org/package/libibus-1_0-5)
*'''Fedora:''' All the dependencies used for building frameworks can be installed by running:
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
$ sudo yum-builddep qt phonon-backend-vlc phonon-backend-gstreamer
$ sudo yum install gcc-c++ ruby doxygen git bzr flex bison gperf socat boost-devel bzip2-devel libxslt-devel libxml2-devel shared-mime-info oxygen-icon-theme giflib-devel xcb-util-keysyms-devel perl-JSON perl-Pod-Usage "*xcb*-devel" perl-XML-Parser NetworkManager-glib-devel xapian-core-devel libxkbcommon-devel libxkbcommon-x11-devel  systemd-devel libwayland-cursor-devel libwayland-server-devel libepoxy-devel gtk3-devel sane-backends-devel libattr-devel libcanberra-devel libusb-devel libxkbfile-devel fontforge-devel libical-devel gpgme-devel cyrus-sasl-devel openldap-devel libpwquality-devel polkit-devel lmdb-devel
</pre>
*'''Arch Linux:''' All the dependencies used for building frameworks can be installed by running:
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
$ sudo pacman -Sy --needed phonon-qt5 qt5-webkit qt5-script qt5-svg qt5-tools qt5-x11extras enchant jasper openexr libutempter docbook-xsl shared-mime-info giflib libxss upower udisks2 bzr git doxygen perl-json perl-libwww perl-xml-parser akonadi xorg-server-devel libpwquality fontforge eigen libfakekey qca-qt5 xapian-core xsd
</pre>


=== Qt 5 ===
== Install required devel packages ==
Qt 5 (http://qt.io/) is the base of KDE software. Choose one of the following sections to get your Qt setup. If you build Qt with the intention to actually develop Qt patches then you should go for a full debug build. If you merely need Qt to develop KDE applications then you should go for the release with debug symbol version.


{{Note|<b>ArchLinux users</b>: qtwebkit and qtwebengine use Python to generate some files, but they use Python 2.x syntax. So you have to make ''python'' pointing to ''/usr/bin/python2'', to do that see the [https://wiki.archlinux.org/index.php/Python#Python_2 Arch Wiki].}}
This section provides information about '''required''' and '''optional''' software packages needed to build the KDE applications.


==== Qt5 full debug build ====
[https://www.qt.io/ Qt5] is the base of KDE software. Your distro provides suitable devel packages. Optionally, you can [[/OwnQt5| build your own Qt5]].
* PRO: full control and debugging capabilities
* CON: takes long to compile on the first time, might be an additional source of errors for beginners


To build all of qt5 execute:
Follow this page to [[/Install the dependencies|install the required dependencies]].
<syntaxhighlight lang="bash">
git clone git://code.qt.io/qt/qt5.git --branch 5.5
cd qt5
./init-repository
./configure -prefix $PWD/qtbase -opensource -confirm-license -nomake tests -nomake examples \
  -dbus -no-separate-debug-info -xcb -system-xcb -qpa xcb -no-gtkstyle -developer-build
make
</syntaxhighlight>


To update qt5 later:
== Git remote prefix ==
<syntaxhighlight lang="bash">
Let's setup a "kde:" prefix for git commands. Add the following text to your ~/.gitconfig:
git pull
<syntaxhighlight lang="ini">
git submodule sync
[url "git://anongit.kde.org/"]
git submodule update --recursive
  insteadOf = kde:
[url "ssh://git@git.kde.org/"]
  pushInsteadOf = kde:
</syntaxhighlight>
</syntaxhighlight>


If you saw changes (i.e. qt5.git got updated since last time),
If you are behind a firewall, add the following text to your ~/.gitconfig :
<syntaxhighlight lang="bash">
<syntaxhighlight lang="ini">
./configure [...same as above...]
[url "https://anongit.kde.org/"]
make
  insteadOf = kde:
echo $?   # you should make extra sure that 'make' didn't abort with an error, especially when using -j
[url "ssh://git@git.kde.org/"]
   pushInsteadOf = kde:
</syntaxhighlight>
</syntaxhighlight>


Experimental and not officially supported: if you don't have enough time and disk space for all of qt5, you could restrict yourself to separate checkouts of qtbase.git, qtsvg.git, qtx11extras.git, qtscript.git and qttools.git, this is enough to build  frameworks/* (but not enough for plasma-framework).
== 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. (see current master [https://cgit.kde.org/kdesrc-build.git/tree/README here])


==== Qt5 release with debug symbols build ====
This guide assumes that
* PRO: This build is the most ideal build when developing applications and tuning performance. It has the speed of a release build but with debug symbols which give you more information in for example kcachegrind with data collected through valgrind.
* you want to install KDevelop inside your home directory,
* CON: The Qt libraries will be quite a lot bigger due to the debug symbols.
* you want to put sources, build and log files into separate subdirectories under <tt>~/kde</tt>, as well as install everything to <tt>~/kde/usr</tt>, and
* you use a Linux system and are familiar with bash.


To build all of qt5 execute:
Make sure to adapt these steps to your needs.
<syntaxhighlight lang="bash">
git clone git://code.qt.io/qt/qt5.git --branch 5.5
cd qt5
./init-repository
./configure -prefix $PWD/qtbase -opensource -confirm-license -nomake tests -nomake examples -dbus \
  -no-separate-debug-info -xcb -system-xcb -qpa xcb -no-gtkstyle -release -force-debug-info -reduce-relocations \
  -optimized-qmake
make
</syntaxhighlight>


==== Use packages from your distribution ====
=== Install kdesrc-build ===
* PRO: faster to get started, one source of errors less
* CON: usually doesn't have debug symbols. Great for developing applications and measuring performance. Not so great for tuning performance (you'd need debug symbols for that).


Note that the Qt version currently must be '''>= 5.5'''
Start off by installing ''kdesrc-build'' and creating a basic configuration file:
<pre>
mkdir -p ~/kde/src
cd ~/kde/src
git clone kde:kdesrc-build
cd kdesrc-build


===== openSUSE 13.2 =====
# Install a symlink of kdesrc-build to a location in PATH
* 13.2: add the repository http://download.opensuse.org/repositories/KDE:/Qt54/openSUSE_13.2/
mkdir ~/bin
* install packages:
ln -s "$PWD/kdesrc-build" ~/bin
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
export PATH=~/bin:$PATH
$ sudo zypper install libqt5-qttools libgypsy0 libqt5-creator libqt5-linguist libqt5-qtbase-common-devel libqt5-qtbase-debugsource libqt5-qtbase-devel libqt5-qtbase-doc libqt5-qtbase-examples libqt5-qtdeclarative-debugsource libqt5-qtdeclarative-devel libqt5-qtdeclarative-examples libqt5-qtdeclarative-tools libqt5-qtdoc libqt5-qtgraphicaleffects libqt5-qtimageformats libqt5-qtimageformats-debugsource libqt5-qtimageformats-devel libqt5-qtmultimedia-devel libqt5-qtmultimedia-examples libqt5-qtquick1-devel libqt5-qtquickcontrols libqt5-qtscript-devel libqt5-qtscript-examples libqt5-qtsvg-devel libqt5-qttools-debugsource libqt5-qttools-devel libqt5-qtx11extras-devel libqt5-qtxmlpatterns-devel libqt5-qtxmlpatterns-examples libQt5CLucene5 libQt5Concurrent-devel libQt5Concurrent5 libQt5Core-devel libQt5Core5 libQt5DBus-devel libQt5DBus5 libQt5Declarative5 libQt5Designer5 libQt5DesignerComponents5 libQt5Gui-devel libQt5Gui5 libQt5Help5 libQt5Multimedia5 libQt5Network-devel libQt5Network5 libQt5OpenGL-devel libQt5OpenGL5 libQt5Positioning5 libQt5PrintSupport-devel libQt5PrintSupport5 libQt5Script5 libQt5Sensors5 libQt5Sql-devel libQt5Sql5 libQt5Sql5-mysql libQt5Sql5-postgresql libQt5Sql5-sqlite libQt5Sql5-unixODBC libQt5Svg5 libQt5Test-devel libQt5Test5 libQt5WebKit5 libQt5WebKitWidgets5 libQt5Widgets-devel libQt5Widgets5 libQt5X11Extras5 libQt5Xml-devel libQt5Xml5 libQt5XmlPatterns5 libQtQuick5 libQt5WebKitWidgets-devel libqt5-qtbase-private-headers-devel
</pre>
</pre>
(these might be too much packages but with those the KF5 build worked)


===== openSUSE 42.1 =====
You will need to append the line <code>export PATH=~/bin:$PATH</code> to your <tt>~/.bashrc</tt> so <code>kdesrc-build</code> is available in PATH whenever you open a terminal. Also check that PATH variable is not set to anything by default in <tt>.bashrc</tt> file


* Use the package list from above but these packages were not found: libqt5-qtimageformats-debugsource, libqt5-qttools-debugsource.
=== Configure kdesrc-build ===


* Plus, Install these packages:
The easiest way to prepare your system is to use the wizard to create the ~/.kdesrc-buildrc you will need, the default options should be ok
<pre>
./kdesrc-build-setup
</pre>
Note: do not quote or escape any file paths.


ninja bzr gettext-tools xcb-util-keysyms-devel docbook-xsl-stylesheets doxygen polkit-devel
If you get an error saying "Unable to run the dialog(1) program" or similar, then install the "dialog" package, such as by running "sudo apt-get install dialog" on Debian / Ubuntu / KDE NEON.


* TODO/OPEN ISSUES:
2017-04-23: User question:
** on my system 'ninja-1.6.0' was installed and when using 'custom-build-command ninja' in the kdesrc-buildrc below, the build of modules fails), maybe see https://bugs.kde.org/show_bug.cgi?id=331654
* When I take a look at ~/.kdesrc-buildrc I see this line `source-dir ~/kdesrc` ("Directory for downloaded source code") and I wonder if this is correct because above we said that the source directory is '''~/kde/src'''.


===== Debian =====
These modifications to the file should be fixed in the repo:
* For now, Qt >= 5.5 can only be found in experimental repository. If it's not already the case, add it to your sources list and update : 
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
$ sudo sh -c "echo 'deb http://ftp.debian.org/debian experimental main' >> /etc/apt/sources.list"
$ sudo apt-get update


* If you have key warnings, you can install them with
    # The path to your Qt installation.
$ gpg --keyserver pgpkeys.mit.edu --recv-keys 8B48AD6246925553
    # qtdir ~/qt5              # OLD, 2017-04-23
$ gpg -a --export 8B48AD6246925553 | sudo apt-key add -
    qtdir /usr # If system Qt
$ gpg --keyserver pgpkeys.mit.edu --recv-keys 7638D0442B90D010
$ gpg -a --export 7638D0442B90D010 | sudo apt-key add -


$ sudo apt-get install -t experimental qtbase5-dev qtbase5-private-dev libqt5x11extras5-dev qtscript5-dev qttools5-dev libqt5svg5-dev libqt5xmlpatterns5-dev qttools5-dev-tools qtdeclarative5-dev
    # Install directory for KDE software
</pre>
    # kdedir ~/kde-latest      # OLD, 2017-04-23
    kdedir ~/kde/usr


===== Other distributions =====
    # Directory for downloaded source code
    # source-dir ~/kdesrc      # OLD, 2017-04-23
    source-dir ~/kde/src


yet to be documented
=== Run kdesrc-build (build an application) ===


=== Alternative: compile KF5 into Docker ===
To let <code>kdesrc-build</code> handle the compilation and installation of KDevelop and its (direct) dependencies  (the other dependencies should be already present if you use a recent distribution, like openSUSE Tumbleweed), type
You can use Docker to keep your main system clean and avoid to install a lot of packages.


Follow the instructions given at the follow repository: https://github.com/Mathux/docker-kdesrc-build
<syntaxhighlight lang="bash">
$ kdesrc-build grantlee libkomparediff2 kdevplatform kdevelop-pg-qt kdevelop
</syntaxhighlight>


Hints for openSUSE to get started:
The path to the log files (cmake, build, install) will be shown at the end of the compilation.


1) '''install'''
Hints:
sudo zypper install docker
* You can also pass the <tt>--debug</tt> parameter to enable the verbose output during the build process (all command invocations and compiler output).
* If you want to compile and install indirect dependencies as well, or at least the dependencies specified in the kde-build-metadata repository, make sure to add the <tt>--include-dependencies</tt> parameter as well.


2) If the error message
=== Set up the runtime environment ===
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
 
FATA[0000] Post http:///var/run/docker.sock/v1.16/images/create?fromImage=busybox%3Alatest: dial unix /var/run/docker.sock: no such file or directory
Copy and use these commands to a new file called ~/kde/.setup-env:
</pre>
<syntaxhighlight lang="ini">
appears whenever trying to execute any docker command then you have to start:
export KF5=~/kde/usr
sudo systemctl '''start docker'''
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
export SASL_PATH=/usr/lib/sasl2:$KF5/lib/sasl2
# (lib64 instead of lib on some systems, like openSUSE)
PS1="(kdesrc) $PS1"
</syntaxhighlight>


3) Add your user to the '''docker group'''
A guide for building Plasma 5 specifically on Ubuntu 14.04 LTS can be found [[/Plasma_5_on_Ubuntu_14.04_LTS|here]].


4) Proceed as described in the github project.
2017-04-24: User feedback:
* Is there a reason why the .setup-dev file must be hidden (i.e. start with a dot)?


5) Beware of '''low disk space''' on your root partition (see http://blog.eye48.com/post/98551740424/when-docker-io-eats-up-your-disc-space)
=== Run a previously built application ===


= Build KDE Frameworks and its dependencies =
Whenever you want to run a self-compiled KDevelop, you just have to do the following commands in terminal:
{{Note|For instructions on building and running Plasma 5, see [[Plasma/Building]].}}
<syntaxhighlight lang="bash">
== Git remote prefix ==
$ source ~/kde/.setup-env
Let's setup a "kde:" prefix for git commands. Add the following text to your ~/.gitconfig:
$ kdevelop
<syntaxhighlight lang="ini">
[url "git://anongit.kde.org/"]
  insteadOf = kde:
[url "ssh://git@git.kde.org/"]
  pushInsteadOf = kde:
</syntaxhighlight>
</syntaxhighlight>


== Clone kdesrc-build ==
=== Analyse and fix build errors ===
First you need kdesrc-build, it can be done with the following commands:
 
First and foremost check that you have installed the dependencies mentioned in the wiki at [https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source/Install_the_dependencies here]
 
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.
 
<pre>
<pre>
mkdir -p extragear/utils
<<<  PACKAGES FAILED TO BUILD  >>>
git clone kde:kdesrc-build extragear/utils/kdesrc-build
libkomparediff2 - ~/kde/log/<build-date>/libkomparediff2/error.log  :-(
ln -s extragear/utils/kdesrc-build/kdesrc-build .
</pre>
</pre>


== Download the configuration file ==
Inspect that log to figure out what's going on:
At this point,
 
# download http://www.davidfaure.fr/kde/kf5-qt5-kdesrc-buildrc into your source dir
==== Missing ecm-config.cmake ====
# rename it to '''kdesrc-buildrc'''
<syntaxhighlight lang="bash">
You can use this command:
$ cat ~/kde/log/<build-date>/libkomparediff2/error.log
</syntaxhighlight>
<pre>
<pre>
wget "http://www.davidfaure.fr/kde/kf5-qt5-kdesrc-buildrc" -O "kdesrc-buildrc"
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.
</pre>
</pre>
== Adjust the paths ==
Take a look at those lines in the configuration file you've downloaded:
<pre>
  # note that the qtdir line is not needed and can be commented out
  #  when using distro installed Qt 5 packages
  # qtdir /d/qt/5/kde/qtbase


  source-dir /d/kde/src/5
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 <tt>--include-dependencies</tt> parameter mentioned above.
  build-dir /d/kde/build/5
  kdedir /d/kde/inst/kde_frameworks
</pre>
and adjust the paths the way you want.
* qtdir = Where Qt 5 is installed, or qtbase build dir if using uninstalled or comment out this line to use distro-installed Qt packages
* source-dir = where KDE Frameworks 5 sources should be downloaded, e.g. /home/dev/dev/kde/src
* build-dir = where KDE Frameworks 5 should be built, e.g. /home/dev/kde/build
* kdedir = your KDE Frameworks 5 installation directory, e.g. /home/dev/kde/usr


NOTE, that it is not possible to use variables like $HOME (and probably not recommended to use the tilde for home: ~).
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.


Note: Append '''-std=c++11''' to the '''cxxflags''' in the '''kdesrc-buildrc'''. Otherwise, you'll be no able to build libdbusmenu-qt.
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 <tt>extra-cmake-modules</tt> being a hot candidate; to fix above error we simply install the package and the restart the build:
{{Note|The value of <tt>'''''kde-dir'''''/share</tt> must be included in the environment variable <tt>'''XDG_DATA_DIRS'''</tt> or otherwise the build will fail. kdesrc-build should handle this for you.}}
{{Note|The Qt dir must be included in the environment variable <tt>'''CMAKE_PREFIX_PATH'''</tt> otherwise kdesrc-build will fail to configure most modules.}}


== Run kdesrc-build ==
<syntaxhighlight lang="bash">
{{Note|Note that this script uses GIT and Bazaar to download the sources, so ensure you have both installed. }}
$ sudo apt-get install extra-cmake-modules
{{Note|Ensure that C++ compiler is g++. Building KDE with clang has linking errors.}}
$ kdesrc-build ...
You just have to run <code>./kdesrc-build</code> to build the KDE Frameworks.
</syntaxhighlight>
It is the preferred way of building KDE Frameworks.


{{Note|kdesrc-build will only pick up the kdesrc-buildrc file you downloaded and edited above if it is in the same directory you run kdesrc-build from. If you save it to ~/.kdesrc-buildrc, however, it will be used no matter where you run kdesrc-build from. }}
The error should be gone now.
==== Missing Qt5Config.cmake====


If you want you can also do the work by hand following the detailed instructions: [[Frameworks/Building/Details]].
<pre>
CMake Error at CMakeLists.txt:45 (find_package):
  Could not find a package configuration file provided by "Qt5" (requested
  version 5.2.0) with any of the following names:


Example for openSUSE 13.1 with pre-built Qt 5 packages installed via zypper:
    Qt5Config.cmake
# directory structure looks like this now:
    qt5-config.cmake
# src/
</pre>
#  extragear/
#    utils/
#      kde-srcbuild/
#  kdesrc-build [symlink to extragear/utils/kde-srcbuild/kdesrc-build]
#
$ cd <your kf5 src dir where kdesrc-build symlink is located>
$ export CMAKE_PREFIX_PATH=/usr/lib64/cmake/Qt5
$ ./kdesrc-build


NOTE 2016-01-18 / openSUSE 42.1, that the build seems to work without the "export CMAKE_PREFIX_PATH=/usr/lib64/cmake/Qt5"
It can be fixed by installing the dependeny
<pre>sudo apt-get install qtbase5-dev</pre>


=== Analyse and fix build errors ===
Run again the kdesrc-build command, and it should be fine
 
==== Missing Qt5WebKitWidgetsConfig.cmake====


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:
<pre>
* The latest build log is written to <pre>src/log/latest/<module-name>/</pre>
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake:26 (find_package):
* In case of error there will be an '''error.log''' file with useful information. You will often see that there is only a build dependency missing.
  Could not find a package configuration file provided by "Qt5WebKitWidgets"
  with any of the following names:


== Use Kubuntu CI ==
    Qt5WebKitWidgetsConfig.cmake
[https://community.kde.org/Kubuntu/PPAs#Kubuntu_Continuous_Integration_.28CI.29 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.
    qt5webkitwidgets-config.cmake
</pre>


= Runtime setup =
It can be fixed by installing the dependeny
To use your new KF5 install prefix (let's call it $KF5) :
<pre>sudo apt-get install libqt5webkit5-dev</pre>
<syntaxhighlight lang="bash">
 
export KF5=<path to your intended frameworks install directory>
Run again the kdesrc-build command, and it should be fine
export QTDIR=<path to your qt5 install dir, or qtbase build dir if using uninstalled>
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 OpenSUSE and similar)
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
</syntaxhighlight>


Note that LD_LIBRARY_PATH isn't set. You shouldn't set it, the builtin rpath works magic instead, and if you set it you'll have issues when running tools that use uninstalled libs while building frameworks (e.g. meinproc, kconfig_compiler...)
==== kdelibs4support and qca fail on openssl ====
At least arch linux has openssl 1.1 by default, but it seems like kdelibs4support/qca needs to be built against 1.0 for the time being.


For what works on Debian Sid alongside with packaged KF5 nicely see:
Add this to your .kdesrc-buildrc to let it pick up the right headers (make sure to have openssl 1.0 and the header location is correct):
[https://wiki.debian.org/KdeBuildingFromSource Using (parts of) self-built KF 5, Plasma 5 and/or KDE Applications on Debian] (note I do set LD_LIBRARY_PATH there and it still uses any libraries from system that are not available self-built, it may depend on whether you want to build all of KF5/Plasma or just parts of it and whether you want the system wide parts to use your newly compiled stuff)
<pre>
options kdelibs4support
    cmake-options -DOPENSSL_INCLUDE_DIR=/usr/include/openssl-1.0
end options


To use separate user settings for KF5:
options qca
<syntaxhighlight lang="bash">
    cmake-options -DOPENSSL_INCLUDE_DIR=/usr/include/openssl-1.0
export XDG_DATA_HOME=$HOME/.local5/share
end options
export XDG_CONFIG_HOME=$HOME/.config5
</pre>
export XDG_CACHE_HOME=$HOME/.cache5
</syntaxhighlight>


To be able to compile other stuff on top of KF5:
= Testing =
<syntaxhighlight lang="bash">
== Running unit tests ==
export CMAKE_PREFIX_PATH=$KF5:$CMAKE_PREFIX_PATH
Unit tests are ran from the build dir of each framework; you should first <code>cd</code> into it.
</syntaxhighlight>


To get more information out of qDebug statements (i.e. make it more like kDebug) :
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).
<syntaxhighlight lang="bash">
export QT_MESSAGE_PATTERN='%{appname}(%{pid})/%{category} %{function}: %{message}'
</syntaxhighlight>
or even better, to get colors:
<syntaxhighlight lang="bash">
c=`echo -e "\033"`
export QT_MESSAGE_PATTERN="%{appname}(%{pid})/(%{category}) ${c}[31m%{if-debug}${c}[34m%{endif}\
%{function}${c}[0m: %{message}"
unset c
</syntaxhighlight>


To set a KDE5 default editor (for git and svn)
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
export EDITOR="kwrapper5 kwrite"
$ eval `dbus-launch`
$ kdeinit5
$ make test
</syntaxhighlight>
</syntaxhighlight>


Don't bother with KDEDIR and KDEHOME etc.  this stuff isn't used anymore.
'''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.  


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


should show you now the location of the built version, ''not'' the one in the system path /usr/bin/ if you setup the paths correctly.
'''Note:''' <tt>KDE_FULL_SESSION=true</tt> is needed to make sure that the correct QPA will be loaded.


To '''run an application''', e.g. ksnapshot, 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). (Only needed when working under KDE4?). Kded5 is not needed for every feature but everytime when kioexec (which is used by KRun) is involved.
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


  $ eval `dbus-launch` # no console output expected, (kdeinit5 is started automatically when needed)
<syntaxhighlight lang="bash">
$ ksnapshot
  $ xvfb-run -s '-screen 0 1024x768x24' make test
</syntaxhighlight>


= Running unit tests =
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 <tt>DBUS_SESSION_BUS_ADDRESS</tt> is not set, the tests should not find your existing DBus session, and instead launch a new DBus instance.
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).
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 [http://awesome.naquadah.org/ awesome] installed, you could create a script called <tt>awesome-run</tt> as follows:


<pre>
<syntaxhighlight lang="bash">
eval `dbus-launch`
kdeinit5
make test
</pre>
 
Note: Regular apps will start kdeinit5 automatically. The reason it has to be started by hand when running unittests 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 <pre>
xvfb-run -s '-screen 0 1024x768x24' make test
</pre>
(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 <tt>DBUS_SESSION_BUS_ADDRESS</tt> is not set, the tests should not find your existing D-Bus session, and instead launch a new D-Bus 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 [http://awesome.naquadah.org/ awesome] installed, you could create a script called <tt>awesome-run</tt> as follows: <syntaxhighlight lang="bash">
#!/bin/sh
#!/bin/sh
awesome &
awesome &
exec "$@"
exec "$@"
</syntaxhighlight>
</syntaxhighlight>
and then run the tests as <pre>
 
and then run the tests as
 
<syntaxhighlight lang="bash">
xvfb-run -s '-screen 0 1024x768x24' /path/to/awesome-run make test
xvfb-run -s '-screen 0 1024x768x24' /path/to/awesome-run make test
</pre>
</syntaxhighlight>
 
If you want to publish your test results, instead of "make test" run


If you want to publish your test results, instead of "make test" run <pre>
<syntaxhighlight lang="bash">
make Experimental
make Experimental
</pre>
</syntaxhighlight>
 
The test results will appear on http://my.cdash.org/index.php?project=&lt;projectname&gt;
The test results will appear on http://my.cdash.org/index.php?project=&lt;projectname&gt;
== Testing Plasma ==
The following page details how to [[/Test plasma | test Plasma]].


= Troubleshooting =
= Troubleshooting =
Line 327: Line 280:
== Compilation: how to quickly solve build problems ==
== Compilation: how to quickly solve build problems ==


Situation:
'''Situation:'''


One or more modules fail to build via kdesrcbuild (displayed in red font).
One or more modules fail to build via <code>kdesrc-build</code> (displayed in red font).


'''Steps to solve''' (in the given order):
'''Steps to solve''' (in the given order):


1) Check KDE build server if the module is maybe currently broken: http://build.kde.org/view/FAILED/
The following steps assume the directory structure as proposed in the ''kdesrc-build'' guide above.
 
For the next two steps we assume your kf5 development directory structure looks like this:
# 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.
kf5
# Check the [https://build.kde.org/view/FAILED/ list of currently broken modules] on the KDE build server.
  `- build
# If you get a build failure, simple fix might be to delete the build folder for that module and try building it again.
  `- src
# See [[#Analyse_and_fix_build_errors | Analyse and fix build errors]].
  `- usr
# Delete <tt>~/kde/build</tt> and <tt>~/kde/usr</tt>. Run <code>kdesrc-build</code> again.
 
# Ask for help on IRC or some mailing list, see [[Getinvolved/development#Communicating_with_the_team| Communicating with the team]].
2) Delete '''usr''' and run kdesrcbuild again.
# Check if there are changes in the build instructions: see [https://community.kde.org/index.php?title=Guidelines_and_HOWTOs/Build_from_source&action=history History of this wiki page].
 
# Start over from scratch.
3) see [https://community.kde.org/Frameworks/Building#Analyse_and_fix_build_errors Analyse and fix build errors]
 
4) Delete '''build''' and '''usr'''. Run kdesrcbuild again.
 
5a) Ask on IRC or mailing list (see [https://community.kde.org/Getinvolved/development#Communicating_with_the_team Communicating with the team])
 
5b) Check if there are changes in the build instructions: see History of this wiki page.
 
6) Start over from scratch.
 
== Runtime: generic runtime problem ==
 
Try to delete ~/.cache5, ~/.config5, ~/.local5
 
(WARN: make sure not accidently delete your own config, the directories without the 5)


== Runtime: Segfault when a sound is about to play (e.g. for a message box) ==
== Runtime: Segfault when a sound is about to play (e.g. for a message box) ==
Line 364: Line 302:
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:
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:


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


This command can solve the problem:
This command can solve the problem:


  sudo /usr/lib64/vlc/vlc-cache-gen -f /usr/lib64/vlc/plugins
<syntaxhighlight lang="bash">
  $ sudo /usr/lib64/vlc/vlc-cache-gen -f /usr/lib64/vlc/plugins
</syntaxhighlight>


See also:
See also:
* https://community.kde.org/Plasma/5.1_Errata
* [[Plasma/5.1_Errata]]
* https://forum.kde.org/viewtopic.php?f=289&t=122996
* https://forum.kde.org/viewtopic.php?f=289&t=122996


Line 380: Line 322:
(added: 2015-Jan)
(added: 2015-Jan)


Situation:
'''Situation:'''
kded5 is started but crashes because of some dependency. Stacktraces show for example `bluedevil` as possible cause.
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.
'''Goal 1: Disable the component to verify it as crash cause.'''


Steps:
Steps:


1) locate bluedevil files using `locate bluedevil`, for example.  
# Locate bluedevil files using <code>locate bluedevil</code>, for example.  
 
# Among the files there is <tt>kde/usr/share/kservices5/kded/bluedevil.desktop</code>. Remove it. If it was the cause, kded should stop crashing
2) Among the files there is `dev/kf5/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.
'''Goal 2: Remove bluedevil from kdesrcbuild until it gets fixed.'''


Steps:
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.
# Search through the <code>dev/kf5/src/extragear/utils/kdesrc-build/*-build-include</code> files to find the component. In this case, it was found in kf5-workspace-build-include.
 
# Comment it out:
2) Comment it out:
<pre>
  # module-set kf5-bluetooth-management
  # module-set kf5-bluetooth-management
  #    repository kde-projects
  #    repository kde-projects
  #    use-modules libbluedevil bluedevil
  #    use-modules libbluedevil bluedevil
  # end module-set
  # end module-set
Further calls of `kdesrcbild` 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
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
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
</pre>
</pre>


Solution (not verified yet): as said in the article, run this command before starting the app itself:
Further calls of <code>kdesrc-build</code> will not include the component.
. setup-kf5-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) ==
== Get more help ==
(added: 2014-Oct, verified: 2015-Feb)


Situation: developing and executing KF5 apps under KDE 4.
If you still have trouble with the building process or runtime setup, you can contact people as described in [[Get_Involved/development#Communicating_with_the_team|Communicating with the team]].


Problem: After working a bit with KF5 applications your regular KDE icon theme might be changed from oxygen to breeze.
Feel free to join us by visiting [irc://irc.freenode.net/#kde-devel #kde-devel on Freenode]. A web-based client can be found at https://kiwiirc.com/client/irc.freenode.org/kde-devel


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


If you still have trouble with the building process or runtime setup you can contact people as described in [https://community.kde.org/Getinvolved/development#Communicating_with_the_team Communicating with the team].  
== Kubuntu CI ==
[[Kubuntu/PPAs#Kubuntu_Continuous_Integration_.28CI.29|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.


More specifically, here is a list of beginner people who have recently had built the project and would like to specifically help with build problems. Feel free to add them to the recipient list when writing to the mailing list:
== openSUSE Build Service ==
[https://en.opensuse.org/SDB:KDE_repositories#Unstable_Frameworks.2C_Plasma_and_Applications The openSUSE Build Service] provides packages of KDE Git master for KDE Frameworks, Plasma, Applications and Extragear. It offers repositories for Tumbleweed and the latest stable (Leap) release.


* Gregor Mi (codestruct at posteo dot org) (build KF5 on openSUSE 13.2 running latest KDE 4)
== Docker ==
* [[/Alternatives | Build with docker]]

Revision as of 08:31, 13 September 2017

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 else continue here on.

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:

If you are behind a firewall, add the following text to your ~/.gitconfig :

[url "https://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. (see current master here)

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

# 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. Also check that PATH variable is not set to anything by default in .bashrc file

Configure kdesrc-build

The easiest way to prepare your system is to use the wizard to create the ~/.kdesrc-buildrc you will need, the default options should be ok

./kdesrc-build-setup

Note: do not quote or escape any file paths.

If you get an error saying "Unable to run the dialog(1) program" or similar, then install the "dialog" package, such as by running "sudo apt-get install dialog" on Debian / Ubuntu / KDE NEON.

2017-04-23: User question:

  • When I take a look at ~/.kdesrc-buildrc I see this line `source-dir ~/kdesrc` ("Directory for downloaded source code") and I wonder if this is correct because above we said that the source directory is ~/kde/src.

These modifications to the file should be fixed in the repo:

   # The path to your Qt installation.
   # qtdir ~/qt5               # OLD, 2017-04-23
   qtdir /usr # If system Qt
   # Install directory for KDE software
   # kdedir ~/kde-latest       # OLD, 2017-04-23
   kdedir ~/kde/usr
   # Directory for downloaded source code
   # source-dir ~/kdesrc       # OLD, 2017-04-23
   source-dir ~/kde/src

Run kdesrc-build (build an application)

To let kdesrc-build handle the compilation and installation of KDevelop and its (direct) dependencies (the other dependencies should be already present if you use a recent distribution, like openSUSE Tumbleweed), type

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

The path to the log files (cmake, build, install) will be shown at the end of the compilation.

Hints:

  • You can also pass the --debug parameter to enable the verbose output during the build process (all command invocations and compiler output).
  • If you want to compile and install indirect dependencies as well, or at least the dependencies specified in the kde-build-metadata repository, make sure to add the --include-dependencies parameter as well.

Set up the runtime 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
export SASL_PATH=/usr/lib/sasl2:$KF5/lib/sasl2
# (lib64 instead of lib on some systems, like openSUSE)
PS1="(kdesrc) $PS1"

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

2017-04-24: User feedback:

  • Is there a reason why the .setup-dev file must be hidden (i.e. start with a dot)?

Run a previously built application

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

First and foremost check that you have installed the dependencies mentioned in the wiki at here

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:

Missing ecm-config.cmake

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

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

The error should be gone now.

Missing Qt5Config.cmake

CMake Error at CMakeLists.txt:45 (find_package):
  Could not find a package configuration file provided by "Qt5" (requested
  version 5.2.0) with any of the following names:

    Qt5Config.cmake
    qt5-config.cmake

It can be fixed by installing the dependeny

sudo apt-get install qtbase5-dev

Run again the kdesrc-build command, and it should be fine

Missing Qt5WebKitWidgetsConfig.cmake

CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake:26 (find_package):
  Could not find a package configuration file provided by "Qt5WebKitWidgets"
  with any of the following names:

    Qt5WebKitWidgetsConfig.cmake
    qt5webkitwidgets-config.cmake

It can be fixed by installing the dependeny

sudo apt-get install libqt5webkit5-dev

Run again the kdesrc-build command, and it should be fine

kdelibs4support and qca fail on openssl

At least arch linux has openssl 1.1 by default, but it seems like kdelibs4support/qca needs to be built against 1.0 for the time being.

Add this to your .kdesrc-buildrc to let it pick up the right headers (make sure to have openssl 1.0 and the header location is correct):

options kdelibs4support
    cmake-options -DOPENSSL_INCLUDE_DIR=/usr/include/openssl-1.0
end options

options qca
    cmake-options -DOPENSSL_INCLUDE_DIR=/usr/include/openssl-1.0
end options

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.

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.

openSUSE Build Service

The openSUSE Build Service provides packages of KDE Git master for KDE Frameworks, Plasma, Applications and Extragear. It offers repositories for Tumbleweed and the latest stable (Leap) release.

Docker