Getting Started/Build/KDE4

From KDE TechBase
Revision as of 14:49, 12 January 2008 by Powerfox (talk | contribs)


Getting_Started/Build/KDE4


Abstract

This tutorial shows one way to get KDE from trunk running on Linux/BSD systems. There are also tutorials for FreeBSD, Windows, Mac OS X and Solaris. Throughout the tutorial the bash shell is used.

Warning
Expect a higher risk of build failure on Mondays when most kdelibs changes are committed. Dashboard reports unexpected breakages. You are encouraged to fix failing modules.


Software Requirements

The following needs to be installed to successfully use this tutorial:

  • gcc and g++, preferably version 4.2 or higher
  • svn, the subversion revision control client
  • pkg-config
  • development libraries and headers for X11, OpenGL (mesa-common-dev and libglu1-mesa-dev), libjpeg, libpng, libungif, libclucene, librdf, libxml2 and libxslt
  • the makeobj script, which is included in kdesdk. You can install it from kdesdk (kdesdk-scripts on Debian) or similar packages, or download at WebSVN
  • the shared-mime-info package, is the freedesktop MIME standard now used in KDE
  • boost, used by kdebase; after build and/or install, in order to make cmake aware about its location (FindBoost), add the boost directory (which contains the include subdirectory) to CMAKE_INCLUDE_PATH or set a environment variable called BOOST_ROOT that points to the boost directory.


Create a user account for KDE4 development

Note
Some people like to have a separate user account for KDE 4 (for instance an old bug deleted files by mistake), and the instructions below were written with that approach.

However it is much more efficient to do everything with a single user account, see Increased Productivity in KDE4 with Scripts for more details.

You can still follow the instructions below, but don't put the environment variables in your .bashrc, put them in a separate file that you source to switch to the KDE 4 environment.


Option 1: Command Line

Note
On some systems a new user is configured by default to use /bin/sh. Using /bin/sh can be very inconvenient to work with and you may want to change it to /bin/bash or another shell. On Ark Linux and Fedora, you can skip the -s /bin/bash switch - /bin/sh is bash.

useradd -m kde-devel -s /bin/bash passwd kde-devel


Warning
The new kde-devel user will not be added automatically to all the user groups, which will result in not having sound, not being able to sudo, etc. Edit your /etc/groups file to add the kde-devel user to all the groups that you need (probably the groups that your usual username is already assigned to).


Option 2: Using KControl

Instead of using the commands above, you can also use the User module in the KDE Control Center if you already have KDE3 installed.

Setting up the environment

Copy the ~/.bashrc from your normal user account to the new kde-devel account. Next, copy and paste the contents of the example .bashrc into ~kde-devel/.bashrc. Be sure to comment out the line alias make=makeobj if you do not have the makeobj command available. You will probably also want to modify the path to make sure it doesn't include your kde3 paths. Also if you want to use KDevelop to develop KDE 4 applications you may pass the -GKDevelop3 flag to the cmake command (to make CMake generate KDevelop project files, it will help to avoid rebuilding in the future, see this). To make it run, you have to open a new bash or to execute source ~/.bashrc

This will provide access to commands such as cmakekde that are used in this tutorial as well as ensure that the proper paths are in place for Qt, KDE and CMake binaries.

For more information, please read the Getting Started/Increased Productivity in KDE4 with Scripts tutorial.

Switching to the New User

Switch to the user kde-devel: (don't forget the dash) ssh -X kde-devel@localhost

Note
If the ssh command fails, check out the Launching KDE 4 apps section of the KDE4 development guide.


Required packages from your distribution

The requirements to build kde4 from source vary from distribution to distribution. Instructions for your distribution are provided below:

Your next compilation step depends on the packages supplied by your distro.

D-Bus

QtDBus and KDE are known to work with D-Bus versions 0.62, as well as 0.92 and upwards. Versions 0.60 and 0.61 may work too but are not tested. Versions 0.90 and 0.91 are known not to work. We recommend using post-1.0 release versions (at least 0.94), so consider upgrading if you haven't done so.

You may skip this section if you have a recent D-Bus version or if you don't want to upgrade. You probably want to skip building the bindings until/unless you know you will be building HAL (see below).

Before running these steps in the recipe, make sure your X11 headers and libraries are available. The configure script run on line 5 of the following instructions should output:

Building X11 code:        yes

The Recipe

Tip
Make sure you did set up your environment correctly as described above. This is necessary for the cs and cb functions to work.


cs # 'cs' is a bash function, click here to learn more 
wget http://dbus.freedesktop.org/releases/dbus/dbus-1.0.2.tar.gz
tar -xvzf dbus-1.0.2.tar.gz
cd dbus-1.0.2/
./configure --prefix=$DBUSDIR --localstatedir=/var
make
sudo make install
sudo dbus-uuidgen --ensure
cs # see above
wget http://dbus.freedesktop.org/releases/dbus-glib/dbus-glib-0.74.tar.gz
tar -xvzf dbus-glib-0.74.tar.gz
cd dbus-glib-0.74/
./configure --prefix=$DBUSDIR
make
sudo make install
cd
sudo chown -R kde-devel:kde-devel *

What's Happening

After changing into the source directory (line 1), D-Bus source code is downloaded from freedesktop.org (line 2) and unpacked (line 3). After going into the newly created D-Bus directory (line 4), the build is set up using the supplied configure script (line 5). After building (line 6) and installing (line 7) D-Bus, we use the dbus-uuidgen tool to install a machine identification file that allows the bus to start automatically when the desktop session starts (line 8).

Note that you need write access to /var for the last two steps. If your system does not have the sudo command, you can use the su command instead, e.g. su -c "make install".

The steps for building the glib bindings are similar to the above.

When these two packages are done building, we must fix the file ownership because 'sudo make install' has created root owned files and directories in ~kde-devel/kde.

CMake

Skip this if you have CMake >=2.4.5 installed. You should be able to directly use the binary packages available on the CMake site. There are also distribution specific packages available.

The Recipe

cs # 'cs' is a bash function, click Here to learn more 
wget http://www.cmake.org/files/v2.4/cmake-2.4.6.tar.gz
tar -zxf cmake-2.4.6.tar.gz
mkdir cmake-build
cd cmake-build 
../cmake-2.4.6/bootstrap
make
sudo make install

What's Happening

First, we go back to the kde-devel user's source directory (line 1), get the CMake sources (line 2) and unpack them (line 3). We create a directory to build CMake in (line 4) and go into it (line 5). We then run the CMake bootstrap script to set up the CMake build (line 6), then make (line 7) and install it (line 8) using the root user.

If your system does not have the sudo command, you can instead do su -c "make install".

Qt

Next we need to get Qt4. KDE is guaranteed to build against any Qt 4.3. Qt 4.2 and earlier are not supported and will not work.

If your distribution has a recent version of Qt4, that should work. Most distros backport bugfixes, and some distros, like Debian or openSUSE, even use the patches from KDE svn. In other cases, using the recipe below will give you a more stable Qt than your distro. Refer to the distribution specific sections above for more information.

As for now Qt3 compatibility layer in Qt 4 is mandatory, so please avoid using "-no-qt3support" option when building Qt4 from sources.

The Recipe

cd # Note: qt-copy lives in $HOME/qt-copy. See $QTDIR in .bashrc 
svn checkout svn://anonsvn.kde.org/home/kde/trunk/qt-copy
cd qt-copy
./apply_patches
./configure -nomake examples -nomake demos -qt-gif \
-no-exceptions -debug -fast -prefix $QTDIR 
make -j2
# if we don't install, we'll just clear obj files to
# save disk space
if [ $QTDIR = `pwd` ]; then \
find . -name '*.o' -delete ; \
else make install; fi;

What's Happening

We switch back to the kde-devel user's home directory (line 1) and download the source code using subversion (svn) from KDE's repository (line 2). After changing into the resulting qt-copy directory (line 3), we run a script that manages the patches that come with qt-copy (line 4).

Once the patches have been applied, we then set up the build using the configure script (line 5-6). The various command line options used are explained in the qt-copy/README.qt-copy file. Finally, we build the minimal requirements for KDE (line 7) and install (line 10) Qt. If install dir is the same as the current dir (line 8), then we just free some space (line 9) instead. If you want all the example and demo applications, you can either build them individually or simply do a make from the qt-copy directory.

Note that the installation does not require root as it installs Qt locally into $QTDIR. Anyway, installation is only needed if $QTDIR differs from $HOME/qt-copy, which is not the case if you have exactly followed the instructions.

Troubleshooting

If you get "error: X11/Xlib.h: No such file or directory", install the devel package of xorg (the actual name may vary between operating systems, for example it is xorg-dev on Ubuntu based systems such as Kubuntu).

If you get an error in the configure step about missing defines, check the value of $QMAKESPEC. Some distributions set this to point directly to the system-installed Qt. If unset QMAKESPEC solves the problem, you probably want to add it to the ~/.bashrc script.

If you get an error ".pch/debug-shared/QtCore", this is because Qt-4.3 enables precompiled headers if your gcc supports it, but for some reason it doesn't work for you. If you use distcc, configure qt with -no-pch. If you use icecream, update to the latest icecream from svn trunk.

Try running any Qt program, like assistant. Note: You may need to run xhost +local:kde-devel as your regular kde3 user to run this application. If it crashes in QSpanData::adjustSpanMethods, then your problem is the oxygen style. Try removing lib/kde4/plugins/styles/kstyle-oxygen.so and lib/kde4/plugins/styles/oxygen.so if they exist in the KDE install prefix.

HAL

Tip
You can use qdbusviewer to see if you have org.freedesktop.hal. If not, you might need a newer version of hal. If you have org.freedesktop.hal, you probably don't need to, and don't want to, roll your own HAL.


If your system requires you to build a newer version of HAL, there's a decent chance you'll need to build other stuff as well, some of which may not be straight forward. Since this should only be required for older distros, instructions are on a separate page.

kdesupport

Warning
Don't forget to read the Setting Up The Environment section first.


There are several libraries that KDE applications rely on in the kdesupport module. This includes Strigi and Soprano for file metadata and search, QImageBlitz for image manipulation needed in kdebase, eigen for visual effects in applications such as Kalzium, taglib for music players and qca for some cryptographic needs.

Strigi itself has a few dependencies as well: you will need the libraries and headers for libz, libbz2, openssl (libcrypto or libssl), libclucene (>=0.9.16a but watch out: version 0.9.17 does not work), and either libxml2 or libexpat.

Please remember that if you use openSUSE, you can install the needed packages from the KDE:KDE4 buildservice repository and do not have to bother with fiddling the details below. Skip to the kdelibs section.

The Recipe

cs # 'cs' is a bash function, click here to learn more
svn checkout svn://anonsvn.kde.org/home/kde/trunk/kdesupport/
cd kdesupport
cmakekde

What's Happening

We change to the base source directory (line 1). We download the sources in kdesupport using subversion (line 2), go into the new ~/kde/src/kdesupport directory (line 3), and commence the build (line 4). This will leave us in the kdesupport build directory after the build is completed.

Troubleshooting

If you get

  cmakekde: command not found

then you have to go manually into the kdesupport directory in ~ and execute the command cmakekde. if this still doesn't work, then something is wrong with your bashrc.

If you get

CMake Error: This project requires some variables to be set,
and cmake can not find them.
Please set the following variables:
LIBXML2_INCLUDE_DIR (ADVANCED)

you should install the development package for libxml2.

If you get

CMake Error: Could NOT find REDLAND

then you need librdf from the Redland. If your distribution does not provide the librdf package, you can download the source there: http://download.librdf.org/source/ and build it. (Gentoo users: The ebuild for librdf is named dev-libs/redland)

If you get

Fetching external item into 'kdesupport/admin'
Error validating server certificate for 'https://...'

see Using Subversion with KDE

If you get

FILE cannot create directory: /usr/lib[64]/qt4/plugins/crypto. Maybe need administrative privileges.

make: *** [install] Error 255

take a second look in the .bashrc file described above, are paths correct? ($QTDIR and $PATH are used to get the QT installation path) Alternatively, you may see this error if you decided to use a distribution installed version of qt4 and skipped the Qt install above. Either install qt-copy as describe above, or "sudo make install". If you use "sudo make install", make sure that you change the ownership back to your user for some of the ~/kde subdirectories that were effected by using sudo (ie. "sudo chown -R kde-devel:kde-devel ~/kde").

If you get a message related to

  target libQtTest.so not found

you may need to recompile qt-copy. This time you should take out

  -nomake demos -nomake examples

from the configure command, so that Qt generates library QtTest.

kdelibs

We can now move on to building KDE's base libraries.

The Recipe

cd   
cs # 'cs' is a bash function, click here to learn more
mkdir KDE && cd KDE
svn checkout svn://anonsvn.kde.org/home/kde/branches/KDE/4.0/kdelibs
cd kdelibs
cmakekde

What's Happening

We change to the base source directory (line 1) then make and go into the KDE directory (line 2). We download the sources for kdelibs using subversion (line 3), go into the new ~/kde/src/KDE/kdelibs directory (line 4), and commence the build (line 5). This will leave us in the kdelibs build directory after the build is completed.

Tip
There might be missing dependencies on your system! They are easily overlooked in the output of cmakekde. You might want to do a cmake $KDE_SRC/KDE/MODULE_NAME prior to compiling any kde modules (like kdelibs, kdepimlibs etc.)


Additional KDE-specific CMake modules

There are additional CMake modules in kdelibs/cmake/modules/ that are necessary for building KDE4 applications. These will be installed for you when kdelibs itself is installed.

Troubleshooting

If you have problems compiling kdelibs, first make sure the software in the Required Software section above is installed and works. Other possible hints include:

  • If the cmakekde command fails stating that CMake requires an out of source build directory, remove ~/kde/src/KDE/kdelibs/CMakeCache.txt, and try again.

If cmakekde still gives the same error then try this

cd
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DCMAKE_BUILD_TYPE=debugfull \
-DKDE4_BUILD_TESTS=ON \
~/kde/src/KDE/kdelibs
make
make install
  • If you received an error stating "Please create a separate build directory and run 'cmake path_to_kdelibs [options]' there.", then you need to change to your build directory before running cmakekde. (e.g cs KDE/kdelibs && cb && cmakekde) If the message stays, run 'svn status' in the kdelibs directory and remove all files labeled with '?'.
  • If Qt wasn't found or the wrong version of Qt was found, make sure that the qmake from the Qt you need is the first qmake in the path.
  • If qmake wasn't found and you are using Debian packages, /usr/bin/qmake probably points to a wrong qmake version. To fix this run as root:
update-alternatives --config qmake
  • If the problems persist, try the CMake make-option --keep-going.
  • Here you need the libungif library, otherwise you will get an error message like "Could NOT find GIF".
  • Qt-4.3 upgrade: if you get a link error in kjsembed talking about QScriptEngine, edit CMakeCache.txt in kdelibs and remove the lines that talk about QT_QTUITOOLS_LIBRARY, then type make again (that static library has a new dependency, and the cmake code that adds it needs to run).
  • if you get CMake Error: KDE Requires Qt to be built with SSL support

, install openssl-devel, remove CMakeCache.txt and re-compile QT.

  • if you get kdelibs/kimgio/ico.cpp:188: undefined reference to `QImage::jumpTable()' it means you compiled QT without QT3 support(no, linking to a true QT3 install won't work)
  • if none of the errors above match yours, you might just try a quick'n'dirty make clean in kdelibs.

kdepimlibs

After kdelibs, but before kdebase, you need to build and install kdepimlibs.

The Recipe

cs KDE # 'cs' is a bash function, click here to learn more
svn checkout svn://anonsvn.kde.org/home/kde/branches/KDE/4.0/kdepimlibs
cd kdepimlibs
cmakekde

What's Happening

We go into the KDE source directory (line 1), download the source code for kdepimlibs using subversion (line 2) and then go into the new ~/kde/src/KDE/kdepimlibs directory (line 3). We then commence the build (line 4). This will leave us in the kdepimlibs build directory after the build is completed.

Troubleshooting

If you have trouble compiling kdepimlibs:

  • the cmakekde command may require a later version of the gpgme library. This is available from the project's web site: http://www.gnupg.org/(en)/download/index.html - please note that the build of gpgme also requires libgpg-error, also available from the same location. Both libraries are installed by the "./configure", "make" and "sudo make install" sequence, with the gpgme library configured with the additional "--with-gpg-error-prefix" parameter. You may need to overwrite your existing "/usr/bin/gpgme-config" file with the newer version for the kdepimlibs to pick up the new install.

kdebase

kdebase is divided into three parts:

  • apps
This contains applications like Dolphin or KWrite.
  • runtime
This contains things needed by every application at runtime, like icons. It is a required dependency for each KDE application, so you have to compile and install this.
  • workspace
This contains things specific to the KDE desktop, like Plasma or the window manager. Most stuff here depends on X11. You only need it if you want to build a full KDE desktop.

You can build all of kdebase at once, which is described in the recipe below. If you only want to build kdebase-runtime, which is the only requirement, you can replace cd kdebase with cd kdebase/runtime in the recipe below.

The Recipe

cs KDE # 'cs' is a bash function, click here to learn more
svn checkout svn://anonsvn.kde.org/home/kde/branches/KDE/4.0/kdebase
cd kdebase
cmakekde

Troubleshooting

If you have troubles compiling kdebase:

  • Make sure you have the libxss headers installed. (Usually you got undefined references on xscreensaver objects if you do not have those headers)
  • which meinproc has to deliver /home/kde-devel/kde/bin/meinproc
  • if cmakekde can not find the path of kdepimlibs, edit the file $KDE_BUILD/KDE/kdebase/CMakeCache.txt and manually set KDEPIMLIBS_INCLUDE_DIR:PATH=$KDE_BUILD/kdepimlibs
  • if you get an error saying "Please set the following variables: X11_XTest_LIB (ADVANCED)", install the devel package of Xtst. On some systems, this is packaged separately from xext and called x11proto-xext-dev or libxtst-dev. You may also need to remove the CMakeCache.txt file in the build dir after installing the package.
  • the same for "X11_Xinerama_LIB (ADVANCED)" where you will need the devel package for xinerama.
  • if you get an error complaining about a missing variable X11_Xrandr_LIB, you need the devel package for libxrandr (libxrandr-devel on ubuntu-systems)
  • if you get the error "Please set the following variables: FONTCONFIG_INCLUDE_DIR, FONTCONFIG_LIBRARIES (ADVANCED)", then you need to install the libfontconfig headers
  • if you get the error "CMake Error: This project requires some variables to be set, and cmake can not find them. Please set the following variables: KMETADATA_LIBRARIES", you need to install soprano from kdesupport and to rebuild kdelibs
  • if you get the error "‘XserverRegion’ does not name a type" make sure you have libxcomposite headers installed (libxcomposite-dev in ubuntu)
  • if you get the error "CMake Error: This project requires some variables to be set, and cmake can not find them. Please set the following variables: QT_QTOPENGL_LIBRARY (ADVANCED) ", try editing CMakeCache.txt and setting QT_QTOPENGL_LIBRARY:FILEPATH=/home/kde-devel/qt-copy/lib/libQtOpenGL.so
  • if you get messages as "KDE4_INSTALL_HANDBOOK() is deprecated. Remove it please. Now all is done in KDE4_CREATE_HANDBOOK." then, either find the files containing the offending line and comment it out manually, or run the following script in ~/kde/src/KDE/kdebase: macros_corrector.sh. It will just REMOVE the line that has "kde4_create_handbook" in it from all the found files.
  • If you get an error (in ubuntu) concerning libxtst.so install the libxtst-dev package
  • If you get the message "kdebase/workspace/kcontrol/kxkb/x11helper.cpp:131: error: ‘KGlobal’ has not been declared", you might need to install libxklavier development packages.
  • If you get "/home/kde-devel/kde/lib/libkio.so: undefined reference to `Strigi::AnalysisResult::AnalysisResult(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long, Strigi::IndexWriter&, Strigi::StreamAnalyzer&)'" you probably have an outdated version of strigi installed by your distro.

Running KDE 4 programs

You can now run KDE 4 programs (e.g. kwrite) by typing:

ssh -X kde-devel@localhost
kwrite 

Troubleshooting

  • If you get
KUniqueApplication: Cannot find the D-Bus session server

check if you can access the display, e.g. type

xclock

and see if a clock appears on the screen.

  • If you get something like
Error: standard icon theme "oxygen" not found!

ASSERT: "!isEmpty()" in file /home/kde-devel/qt-copy/include/QtCore/../../src/corelib/tools/qlist.h, line 245
Aborted (core dumped)

You need to install kdebase - see above. It is enough to install the "runtime" directory from kdebase.

Generating local API documentation

Although the API documentation for KDE is available online at api.kde.org, it is sometimes useful to have it on your own disk, for example when you want to use KDevelop for browsing the documentation or when you are not able to be online all the time.

Be aware that generating the API documentation can take several hours and takes almost half a gigabyte of diskspace. The generation is handled by a script in kdelibs/doc/api, you need doxygen to be able to run it.

To build the API documentation for kdelibs, type the following:

cs KDE/kdelibs # 'cs' is a bash function, click here to learn more
$KDE_SRC/KDE/kdelibs/doc/api/doxygen.sh \
--doxdatadir=$KDE_SRC/KDE/kdelibs/doc/common .

Repeat for other modules as desired.

cd <module home>
$KDE_SRC/KDE/kdelibs/doc/api/doxygen.sh \
--doxdatadir=$KDE_SRC/KDE/kdelibs/doc/common .

Another, even easier method involves downloading this Doxyfile to your local system. Then simply change directory to where you want to create the documentation and run % doxygen /path/to/Doxyfile Then review the file doxygen.log to see the doxygen errors and warnings. You'll find the actual documentation in the apidocs subdirectory.

Staying up to date

In order to keep the kde4 installation up to date, each of the modules installed should be updated periodically. As Monday is the day for big changes in kdelibs, Tuesday may be the best day to do this. For each module checked out, run svn up and make.

For example: cs kdesupport # cs is not a typo svn up cb # cb is not a typo make -j2 VERBOSE=1 && make install

Note: it is not necessary to run cmakekde for updates.

Installing a subset of a module

Many modules in KDE contain a large number of programs which could take a long time to download and compile. In cases where you want to work only on a particular program or programs in a module, it is possible to download and compile particular folders. In some cases, certain folders are required for any build of the module. This is determined in the CMakeLists.txt file of the module. For example the kdegames CMakeLists.txt file lists:

add_subdirectory(libkdegames) add_subdirectory(libkmahjongg)

macro_optional_add_subdirectory(doc) macro_optional_add_subdirectory(lskat) macro_optional_add_subdirectory(katomic)

So, the libkdegames and libkmahjongg directories are required to build any of kdegames. The cmake directory will also usually be required. All the other directories (doc, katomic etc) are optional. They will be built if present on your machine. In this example, we build kmahjongg and kbattleship:

cs KDE svn co -N kdegames # The -N switch performs a non-recursive checkout cd kdegames svn up libkdegames # Get required directories svn up libkmahjongg svn up cmake svn up kbattleship # Get optional directories svn up kmahjongg cmakekde

General troubleshooting

What can happen over time, after some svn up commands, is that some of the tools used in the KDE build chain change their output format. For example, kcfg files are read by kconfig_compiler to produce configuration dialogs. CMake cannot detect those changes, and the compilation might fail. A workaround is to always force a re-generation of all such files:

find $KDE_SRC/KDE/kdebase -name "*.kcfg" | xargs touch

The same applies to ui files as produced by Qt designer.

Locked sessions

When installing KDE 4 as a user, one will not be able to unlock a locked session. To work around this issue you can either:

su chown root.root $KDEDIR/lib/kde4/libexec/kcheckpass

or

chmod 755 $KDEDIR/lib/kde4/libexec/kcheckpass

Also you have to add a "kde" service in /etc/pam.d/ folder

For example for RH/Fedora based distros:

#%PAM-1.0
auth       include      system-auth
account    include      system-auth
password   include      system-auth
session    include      system-auth

Success!

You are now ready to start building other svn modules in the same fashion as you built kdebase, running and testing KDE4 or writing your own patches and applications.

See the Set up KDE 4 for development tutorial for how to start KDE 4 applications and how to use KDevelop to work on them.