Guidelines and HOWTOs/Build from source: Difference between revisions

From KDE Community Wiki
(Added link to build on Ubuntu 14.04 LTS)
(58 intermediate revisions by 16 users not shown)
Line 4: Line 4:
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.
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 <tt>sudo make install</tt> can ''not'' always be undone by a simple <tt>sudo make uninstall.</tt> 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.
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.


== Configuration scripts  ==
== 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.
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 [[/Details| detailed instructions]].
If you want to do the work by hand you can follow the [[/Details|detailed instructions]] else continue here on.


== Install required devel packages ==
== Install required devel packages ==
Line 15: Line 15:
This section provides information about '''required''' and '''optional''' software packages needed to build the KDE applications.
This section provides information about '''required''' and '''optional''' software packages needed to build the KDE applications.


Qt 5 (http://qt.io/) is the base of KDE software. Your distro provides suitable devel packages. Optionally, you can [[/OwnQt5| build your own Qt5]].
[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]].


Follow this page to [[/Install the dependencies | install the required dependencies]].
Follow this page to [[/Install the dependencies|install the required dependencies]].


== Git remote prefix ==
== Git remote prefix ==
Line 24: Line 24:
[url "git://anongit.kde.org/"]
[url "git://anongit.kde.org/"]
   insteadOf = kde:
   insteadOf = kde:
[url "ssh://[email protected]/"]
   pushInsteadOf = kde:
   pushInsteadOf = kde:
</syntaxhighlight>
</syntaxhighlight>


== Install kdesrc-build ==
If you are behind a firewall, add the following text to your ~/.gitconfig :
''kdesrc-build'' isa user-space package manager, it is used to compile KDE-related projects from source and installs them into a designated directory.
<syntaxhighlight lang="ini">
[url "https://anongit.kde.org/"]
  insteadOf = kde:
  pushInsteadOf = kde:
</syntaxhighlight>
 
== 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])
 
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 <tt>~/kde</tt>, as well as install everything to <tt>~/kde/usr</tt>, 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'':
<syntaxhighlight lang="bash">
$ mkdir -p ~/kde/src
$ cd ~/kde/src
$ git clone kde:kdesrc-build
$ cd kdesrc-build
</syntaxhighlight>
 
Install a symlink of kdesrc-build to a location in PATH:
<syntaxhighlight lang="bash">
$ mkdir ~/bin
$ ln -s "$PWD/kdesrc-build" ~/bin
$ export PATH=~/bin:$PATH
</syntaxhighlight>


Follow the given steps to set up kdesrc-build to install KDevelop into our $HOME directory:
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
<pre>
mkdir ~/kdesrc 
cd ~/kdesrc 
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
=== Configure kdesrc-build ===
mkdir ~/bin 
ln -s $PWD/kdesrc-build ~/bin 
export PATH=~/bin:$PATH
</pre>


You will need to append the line <pre>export PATH=~/bin:$PATH</pre> to <pre>~/.bashrc</pre> so kdesrc-build is available in PATH whenever you open a terminal.
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
<syntaxhighlight lang="bash">
$ ./kdesrc-build-setup
</syntaxhighlight>
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.


'''Configure kdesrc-build
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'''.
edit<pre>~/.kdesrc-buildrc</pre> 
Replace <pre>/path/to/kdesrc-build/kf5-qt5-build-include</pre> with <pre>~/kdesrc/kdesrc-build/kf5-qt5-build-include</pre> in ~/.kdesrc-buildrc file


Add <pre>ignore-kde-structure true</pre> and <pre>make-options -jN</pre> to the global section in ~/.kdesrc-buildrc
2018-01-21: Dev response:
<pre>
* This has been fixed in kdesrc-build, to use as a default the paths given in this Wiki. This would have been fixed quicker if a bug had been filed against kdesrc-build though. ;-)
global 
* kdesrc-build-setup will now also set the include-dependencies flag by default, so you don't need to pass it as a command line option.  If you don't want dependencies then just edit the generated .kdesrc-buildrc to set the option to false or 0 instead.
  ...
  ignore-kde-structure true
  make-options -j5 # NOTE: 5 is the number of jobs, this should usually be (number-of-cpu-cores + 1)
  #stop-on-failure        true        # Stop kdesrc-build
  ...
end global 
</pre>


== Run kdesrc-build ==
=== Run kdesrc-build (build an application) ===
Installing KDevelop and dependencies


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


$ kdesrc-build --debug libkomparediff2 grantlee kdevplatform kdevelop-pg-qt kdevelop
<syntaxhighlight lang="bash">
$ kdesrc-build kdevelop
</syntaxhighlight>


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


The --debug parameter will give you the verbose output, all command invocations and compiler output. Helpful for trouble-shooting.
Hints:
* By default, if the kdesrc-build configuration was created using <tt>kdesrc-build-setup</tt>, also all dependencies developed in the KDE community (like KDE Frameworks), will be fetched, compiled and installed. If you don't want that, edit your <tt>~/.kdesrc-buildrc</tt> and change the related option into <tt>include-dependencies false</tt>.
* You can also pass the <tt>--debug</tt> parameter to enable the verbose output during the build process (all command invocations and compiler output).


=== Set up the runtime environment ===


#Set up a script for preparing the environment
Copy and use these commands to a new file called ~/kde/.setup-env (or a different name, but you need to adjust the "source" command below to match):


Copy and use these commands to a new file called ~/.env-kf5:
<syntaxhighlight lang="sh">
<syntaxhighlight lang="ini">
export KF5=$HOME/kde/usr
export KF5=~/kde-5 
export QTDIR=/usr   
export QTDIR=/usr   
export CMAKE_PREFIX_PATH=$KF5:$CMAKE_PREFIX_PATH   
export CMAKE_PREFIX_PATH=$KF5:$CMAKE_PREFIX_PATH   
Line 86: Line 108:
export PATH=$KF5/bin:$QTDIR/bin:$PATH   
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   
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)
# (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 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 QML_IMPORT_PATH=$QML2_IMPORT_PATH   
export KDE_SESSION_VERSION=5   
export KDE_SESSION_VERSION=5   
export KDE_FULL_SESSION=true
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>
</syntaxhighlight>


A guide for building Plasma 5 specifically on Ubuntu 14.04 LTS can be found [[/Plasma_5_on_Ubuntu_14.04_LTS|here]].
A guide for building Plasma 5 specifically on Ubuntu 14.04 LTS can be found [[/Plasma_5_on_Ubuntu_14.04_LTS|here]].


== Run Kdevelop ==
=== Run a previously built application ===
Whenever you feel to run a self-compiled KDevelop, you just have to do the following commands in terminal:
 
<syntaxhighlight lang="ini">
Whenever you want to run a self-compiled KDevelop, you just have to do the following commands in terminal (remember to replace the name of the .setup-env script with the name you chose, if you picked a different name):
  $ source ~/.env-kf5
<syntaxhighlight lang="bash">
  $ source ~/kde/.setup-env
  $ kdevelop
  $ kdevelop
</syntaxhighlight>
</syntaxhighlight>


== Analyse and fix build errors ==
=== 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:
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]


* <<<  PACKAGES FAILED TO BUILD  >>>
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.
libkomparediff2 - ~/kdesrc/log/<build-date>/libkomparediff2/cmake.log  :-(
 
<pre>
<<<  PACKAGES FAILED TO BUILD  >>>
libkomparediff2 - ~/kde/log/<build-date>/libkomparediff2/error.log  :-(
</pre>


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


* $ cat ~/kdesrc/log/<build-date>/libkomparediff2/cmake.log
==== Missing ecm-config.cmake ====
CMake Error at CMakeLists.txt:5 (find_package):
<syntaxhighlight lang="bash">
$ cat ~/kde/log/<build-date>/libkomparediff2/error.log
</syntaxhighlight>
<pre>
CMake Error at CMakeLists.txt:5 (find_package):
   Could not find a package configuration file provided by "ECM" (requested
   Could not find a package configuration file provided by "ECM" (requested
   version 0.0.9) with any of the following names:
   version 0.0.9) with any of the following names:
Line 120: Line 154:
   to a directory containing one of the above files.  If "ECM" provides a
   to a directory containing one of the above files.  If "ECM" provides a
   separate development package or SDK, be sure it has been installed.
   separate development package or SDK, be sure it has been installed.
</pre>


In this case: the ECM (extra cmake modules) package is missing. The way you usually fix these kind of problems is to head over to http://packages.ubuntu.com and search for the distro package providing a particular file (ECMConfig.cmake in this case).
In this case, the ECM (extra cmake modules) package is missing. Since ECM is a KDE Framework, this error would have been avoided by having the "kdesrc-buildrc" config option <tt>include-dependencies</tt> set to <tt>true</tt> or explicitly passing the <tt>--include-dependencies</tt> parameter when calling ''kdesrc-build''.


So 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:
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.


* $ apt-get install extra-cmake-modules
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:
  <restart build
  $ kdesrc-build ...


The errors should be gone by now.
<syntaxhighlight lang="bash">
$ sudo apt-get install extra-cmake-modules
$ kdesrc-build ...
</syntaxhighlight>


= Testing =
The error should be gone now.
== 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).
==== Missing Qt5Config.cmake====


<pre>
<pre>
eval `dbus-launch`
CMake Error at CMakeLists.txt:45 (find_package):
kdeinit5
  Could not find a package configuration file provided by "Qt5" (requested
make test
  version 5.2.0) with any of the following names:
 
    Qt5Config.cmake
    qt5-config.cmake
</pre>
</pre>


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.
It can be fixed by installing the dependeny
<syntaxhighlight lang="bash">
$ sudo apt-get install qtbase5-dev
</syntaxhighlight>
 
Run again the kdesrc-build command, and it should be fine


Warning: never start a KDE 4 application in this separate DBus session, it would conflict with your running Plasma 4 desktop.
==== Missing Qt5WebKitWidgetsConfig.cmake====
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>
<pre>
xvfb-run -s '-screen 0 1024x768x24' make test
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
</pre>
</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">
It can be fixed by installing the dependeny:
#!/bin/sh
<syntaxhighlight lang="bash">
awesome &
$ sudo apt-get install libqt5webkit5-dev
exec "$@"
</syntaxhighlight>
</syntaxhighlight>
and then run the tests as <pre>
 
xvfb-run -s '-screen 0 1024x768x24' /path/to/awesome-run make test
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):
<pre>
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
</pre>
</pre>


If you want to publish your test results, instead of "make test" run <pre>
= Testing =
make Experimental
== Running unit tests ==
</pre>
Unit tests are ran from the build dir of each framework; you should first <code>cd</code> into it.
The test results will appear on http://my.cdash.org/index.php?project=&lt;projectname&gt;
 
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">
$ eval `dbus-launch`
$ kdeinit5
$ make test
</syntaxhighlight>
 
'''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:''' <tt>KDE_FULL_SESSION=true</tt> is needed to make sure that the correct QPA will be loaded.


== Testing Plasma ==
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


The following page details how to [[/Test plasma | test Plasma]].
<syntaxhighlight lang="bash">
$ xvfb-run -s '-screen 0 1024x768x24' make test
</syntaxhighlight>


= Troubleshooting =
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.


== Compilation: how to quickly solve build problems ==
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:  


Situation:
<syntaxhighlight lang="bash">
#!/bin/sh
awesome &
exec "$@"
</syntaxhighlight>


One or more modules fail to build via kdesrcbuild (displayed in red font).
and then run the tests as


'''Steps to solve''' (in the given order):
<syntaxhighlight lang="bash">
$ xvfb-run -s '-screen 0 1024x768x24' /path/to/awesome-run make test
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.
</syntaxhighlight>


2) Check KDE build server if the module is maybe currently broken: http://build.kde.org/view/FAILED/
If you want to publish your test results, instead of "make test" run


For the next two steps we assume your kf5 development directory structure looks like this:
<syntaxhighlight lang="bash">
kf5
$ make Experimental
  `- build
</syntaxhighlight>
  `- src
  `- usr


3) If you get a build failure, simple fix might be to delete the build folder for that module and try building it again.
The test results will appear on http://my.cdash.org/index.php?project=&lt;projectname&gt;


4) see [[#Analyse_and_fix_build_errors | Analyse and fix build errors]]
== Testing Plasma ==


5) Delete '''build''' and '''usr'''. Run kdesrcbuild again.
The following page details how to [[/Test plasma | test Plasma]].


6a) Ask on IRC or mailing list (see [[Getinvolved/development#Communicating_with_the_team| Communicating with the team]])
= Troubleshooting =


6b) Check if there are changes in the build instructions: see History of this wiki page.
== Compilation: how to quickly solve build problems ==


7) Start over from scratch.
'''Situation:'''


== Runtime: generic runtime problem ==
One or more modules fail to build via <code>kdesrc-build</code> (displayed in red font).


Try to delete ~/.cache5, ~/.config5, ~/.local5
'''Steps to solve''' (in the given order):


(WARN: make sure not accidently delete your own config, the directories without the 5)
The following steps assume the directory structure as proposed in the ''kdesrc-build'' guide above.
# 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.
# Check the [https://build.kde.org/view/FAILED/ list of currently broken modules] on the KDE build server.
# If you get a build failure, simple fix might be to delete the build folder for that module and try building it again.
# See [[#Analyse_and_fix_build_errors | Analyse and fix build errors]].
# 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]].
# 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.


== 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 214: Line 297:
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 230: Line 317:
(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 <code>locate bluedevil</code>, 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 <code>dev/kf5/usr/share/kservices5/kded/bluedevil.desktop</code>. 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.'''
Line 246: Line 331:
Steps:
Steps:


1) 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.
# 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>
<pre>
  # module-set kf5-bluetooth-management
  # module-set kf5-bluetooth-management
Line 256: Line 340:
</pre>
</pre>


Further calls of <code>kdesrcbild</code> will not include the component.
Further calls of <code>kdesrc-build</code> 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>
 
Solution (not verified yet): as said in the article, run this command before starting the app itself:
. 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) ==
(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 ==
== 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].  
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]].


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:
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
 
Feel free to join us by visiting #kdevelop on Freenode. A web-based client can be found here: https://kiwiirc.com/client/irc.freenode.org/kdevelop


= Alternative building methods =
= Alternative building methods =


== Kubuntu CI ==
== Kubuntu CI ==
[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.
[[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.
 
== 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.


== Docker ==
== Docker ==
* [[/Alternatives | Build with docker]]
* [[/Alternatives | Build with docker]]

Revision as of 19:26, 12 September 2018

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 "[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 "[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:

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

2018-01-21: Dev response:

  • This has been fixed in kdesrc-build, to use as a default the paths given in this Wiki. This would have been fixed quicker if a bug had been filed against kdesrc-build though. ;-)
  • kdesrc-build-setup will now also set the include-dependencies flag by default, so you don't need to pass it as a command line option. If you don't want dependencies then just edit the generated .kdesrc-buildrc to set the option to false or 0 instead.

Run kdesrc-build (build an application)

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

$ kdesrc-build kdevelop

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

Hints:

  • By default, if the kdesrc-build configuration was created using kdesrc-build-setup, also all dependencies developed in the KDE community (like KDE Frameworks), will be fetched, compiled and installed. If you don't want that, edit your ~/.kdesrc-buildrc and change the related option into include-dependencies false.
  • You can also pass the --debug parameter to enable the verbose output during the build process (all command invocations and compiler output).

Set up the runtime environment

Copy and use these commands to a new file called ~/kde/.setup-env (or a different name, but you need to adjust the "source" command below to match):

export KF5=$HOME/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.

Run a previously built application

Whenever you want to run a self-compiled KDevelop, you just have to do the following commands in terminal (remember to replace the name of the .setup-env script with the name you chose, if you picked a different name):

 $ 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 having the "kdesrc-buildrc" config option include-dependencies set to true or explicitly passing the --include-dependencies parameter when calling kdesrc-build.

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