[KDE Dot News]
 faq
 flatforty
 contribute
 subscribe
 configure
 search
 rdf

 main


  The Road to KDE 4: CMake, a New Build System for KDE
KDE Public Relations and Marketing Posted by Troy Unrau on Wednesday 21/Feb/2007, @10:52
from the now-with-even-more-exciting-compiler-scroll dept.
When a project with the size and scope of KDE gets to be as big as it is, sometimes changing a decision established almost a decade earlier is very difficult. KDE has relied on autotools to build most of the project since its inception, but for the last year, KDE 4 has been building with CMake, a newer build system that is rapidly becoming a heavyweight contender in the world of buildsystems. Read on for more...

This article focuses on CMake, which is not actually part of KDE, but is developed independently by Kitware and a team of open source developers. It is released under a BSD-style license. I can't really show much in the way of screenshots for a build system, but I will do my best to explain why CMake has been a welcome change to the KDE development process.

But before we talk about CMake, a little history lesson about KDE and autotools. KDE has used Qt since the beginning, and one of the nice features of Qt is the meta-object compiler (moc). Autotools had to be extended to support using moc as a pre-processor for most of KDE's header files. That was only the beginning though, as KDE developers wrote the ground-breaking DCOP communication protocol which also had the side effect of adding more types of files that had to be autogenerated during the build process. The developers added document compilers, tools that automatically handled translations, and tools that compiled configuration file classes from XML: Qt's User Interface compiler (for .ui files) was born and needed to be supported by the build system. They also needed to add a whole suite of new configure checks, options, etc. to support all of the features that KDE was using. The KDE build system was evolving into a very complex animal, and using autotools did not scale well.

By the KDE 3 series, there were only a select handful of elite build gurus who could understand the whole of KDE's build system. KDE developers had trouble even moving things from one folder to another without having to spend hours tweaking build files to get it to compile again. And in some cases, starting an independent KDE project meant shipping up to 500 KiB of autotools support files for even a simple 'hello world' type application.

Something obviously had to be done for KDE 4 to improve this situation, and at an Akademy 2005 meeting, it was decided to explore other build system options. Initially, SCons was prototyped for building KDE, but it was slow going, and after several months of work it still did not handle kdelibs well enough to dump autotools. One of the bigger problems with SCons was its lack of modularity.

So, as is often the case with KDE, he who codes, decides: Alexander Neundorf stepped in and did the initial port to CMake which went very smoothly, and he did so with the support of the CMake developers. It took only a few weeks to get much of KDE building smoothly using CMake, and autotools was finally dumped!

The CMake developers have been very supportive of KDE's transition. They even joined KDE's buildsystem mailing list to help out. This relationship has been beneficial to both projects. When KDE started to really stress the capabilities of the still-maturing CMake system, KDE developers started a dialogue with them suggesting improvements - and they were happy for the feedback. As a result, CMake has seen improvements that are beneficial to all projects using the buildsystem.

Our working relationship aside, CMake has greatly improved the process of building KDE. Projects using CMake take less time to get started, since there is less time spent fighting with the build system. One KDE developer says, "CMake doesn't make you want to shoot yourself with a nailgun when building your project anymore."

The way CMake works is by processing an easy to read file called 'CMakeLists.txt' which the developer adds to their source folder. When you run the 'cmake' command, it looks for this file, and based on its contents, it generates Makefiles (on UNIX), or using a command-line switch it can generate XCode project files so you can build Mac applications using OS X's XCode developer tools, or using yet another command, it can even generate MSVC projects from your sources. One of the best KDE-related features of CMake is that it can automatically generate KDevelop project files based on the same 'CMakeLists.txt' used to generate the Makefiles.

KDE's code (with a few exceptions) was already pretty portable, however it was nearly impossible to build KDE on systems like Windows, where autotools was not as well suited. Now much of KDE's improved platform support is thanks to the ease of building on these systems (And of course, Qt being available as GPL on these systems).

In KDE 3.x, building KDE using the recommended methods looked something like this:

% ./configure --prefix=/foo --enable-debug
% make
# make install

As you can tell, this is pretty standard autotools-style building, except that the scripts which controlled the build process are pretty hard to understand.

With CMake, there are some syntax changes (which may actually be less obvious than the old, familiar configure switches), but the commands are mostly the same.

% cmake -DCMAKE_INSTALL_PREFIX=/foo \
    -DCMAKE_BUILD_TYPE=debugfull .
% make
# make install

This syntax does not look like a huge improvement, but looks can be deceiving.

CMake searches for dependencies several times faster than the './configure' process did. CMake builds KDE 4's kdelibs about 40% faster than autotools build KDE 3.5.6's kdelibs, mostly due to a lack of libtool in the toolchain for CMake. The CMake toolchain (for UNIX) looks something like: cmake + make, whereas the autotools chain for KDE 3.5.6 looked something like: automake + autoconf + libtool + make + sh + perl + m4.

I'm going to rely on some of my own personal experiences here to help explain how much easier CMake is to use: Aaron Seigo asked for some help to port some of kdesktop's components into krunner so that kdesktop could finally be killed off in the KDE 4 tree. This is the sort of task that I would not have attempted to tackle in the KDE 3.x tree, not because the code was any harder, but because the build system was so difficult to deal with. In all likelihood, I would not have volunteered for such a task for KDE 3, but with KDE 4 and CMake, after moving the code around and doing some class renaming and such, I smoothly inserted the ported code into the build system, modifying only two or three lines of krunner's CMake build files. It built after a few minutes, and linked and installed. I was so impressed that I've kept contributing porting help. In KDE 3, I probably would have been stumped by the build system (not the actual KDE code) and given up, not bothering to commit my code to KDE SVN.

This only goes to show that the build gurus of KDE can worry a lot less these days, as anyone can get their projects up and running. Your milage may vary, but many developers have expressed similar feelings when dealing with the 'CMakeLists.txt' syntax vs. 'autotools'. However, almost all of the KDE developers would now be considered CMake newbies. The CMake developers have been personally involved in ensuring that KDE's transition is as smooth as possible.

The switch to CMake isn't the first time KDE has changed one of the technologies central to its development. When KDE was younger, we used CVS to control access to the sources. Maintenance of the CVS server was not scaling well as KDE was growing, amassing enormous amounts of code dating back to its original commits. Subversion (SVN) offerred a promising new revision control system that was a better fit for what KDE needed to accomplish, and was easier on our servers. At the time, however, no project the size of KDE had migrated to SVN, and it was a real test for the Subversion software. But KDE and SVN have been a pretty good fit, and since KDE migrated, many other projects have since followed in its footsteps.

KDE's use of CMake has helped to raise the public profile of the buildsystem, much like how the switch to Subversion helped their profile. Other projects have been switching to CMake too, including (but not limited to): Scribus, Rosegarden (switched from SCons), PlPlot, ChickenScheme, and more. There is also work being done to support building KDE 3.x programs using CMake (KPilot for KDE 3 can build using CMake, for example). Projects looking for an easier way to build whilst adding support for more platforms should give CMake a try. Adding a 'CMakeLists.txt' file to your sources does not interfere with your project's existing build system and can give you a good overview of what CMake can do for you. And, like KDE, if there's something it cannot handle, the CMake team is very open to improvements.

Some links that may be useful for those interested in more information:

I promise to have some eyecandy next week folks, until then...



<  |  >

 

  Related Links
 ·   Articles on KDE Public Relations and Marketing
 ·   Also by Troy Unrau
 ·   Contact author

Thread Threshold:

The Fine Print: The following comments are owned by whomever posted them.
( Reply )

Over 40 comments listed. Printing out index only.
Great article
by Paul Eggleton on Wednesday 21/Feb/2007, @11:12
Another stellar article. Thanks Troy!
[ Reply To This | View ]
Nice article!
by Totya on Wednesday 21/Feb/2007, @11:53
I was so preoccupied when I read this. I really enjoyed. Thanks for the nice article Troy!
[ Reply To This | View ]
nice article, but...
by KDE User on Wednesday 21/Feb/2007, @12:03
Some screenshots of the new build system would have been really nice. :-P
[ Reply To This | View ]
Thanks
by Rafael Fernández López on Wednesday 21/Feb/2007, @12:30
Great article Troy. Thanks again for your excellent articles.
[ Reply To This | View ]
Great Article, and a question
by Ben on Wednesday 21/Feb/2007, @12:46
Great Article as useuall.

And I was just wondering if there is any plan for a road to kde4 about Kmail?
[ Reply To This | View ]
CMakeLists.txt?
by Richard Dale on Wednesday 21/Feb/2007, @13:02
Excellent article, sorry to be pedantic but isn't it CMakeLists.txt?
[ Reply To This | View ]
CMAKE flags
by Alistair John Strachan on Wednesday 21/Feb/2007, @13:49
I personally think the:

% cmake -DCMAKE_INSTALL_PREFIX=/foo \
-DCMAKE_BUILD_TYPE=debugfull .
% make
# make install

Syntax is clumsy. It's just not how other UNIX tools work. Double dash for words and single dash for letters works for stacks of other GNU utilities, so why not cmake?

Please, at least the final release of KDE4, consider wrapping cmake with something that supports the legacy syntax. "prefix" is much easier to remember than "DCMAKE_INSTALL_PREFIX".

Just my 2p.
[ Reply To This | View ]
There are auto-updates?
by David on Wednesday 21/Feb/2007, @13:57
Hi all,

I'm quite new to KDE and I wanted to know if there are auto-updates. I mean, if I use KDE 4.01, and then appears KDE 4.02, will it be notified and my system updated? If such feature exists, does it work for all KDE apps?

Sorry for my ignorance, but this is an important topic for me.
[ Reply To This | View ]
Richard Dale on CMake
by Troy Unrau on Wednesday 21/Feb/2007, @15:18
Just thought I'd add the following link, which points to a blog post by Richard Dale about some of his experiences using CMake to build some other non-KDE projects. It's a good read, if you don't mind the technical details :)

http://www.kdedevelopers.org/node/2685
[ Reply To This | View ]
Perfect!
by Rodrigo F Toso on Wednesday 21/Feb/2007, @20:16
This is an amazing job! Thank you for the time... This article is just perfect!
Again, thank you.
Regards,
[ Reply To This | View ]
offtopic
by anonymous-from-linux.org.ru on Wednesday 21/Feb/2007, @22:59
i usualy do push-ups while my project compiles.
[ Reply To This | View ]
SCons vs CMake
by Ben on Thursday 22/Feb/2007, @08:10
I've now used both for developing smallish projects and I can see that they are very similar in capabilities now. They both have easy syntax (relative to automake), a bunch of tools for doing different build tasks, and sane dependency specification. However, it seems like CMake is a bit more inflexible if you want to add a custom build task (like running unittests automatically) into the build process because scons is a dsl vs. cmake which is a custom language.

Likewise, scons has little/no support for configuration and reconfiguring the build process for the users machine which is a big negitive. waf tried to address this but I guess it was too little, too late.

So I guess it's a bit of a toss up. CMake is ok for kde4 need's but I really hope that the kde community reexamines either scons or rake (or another dsl build system) for kde5.

Cheers
Ben
[ Reply To This | View ]
Portability
by Ben on Thursday 22/Feb/2007, @10:03
This seems like it's just another attempt to make kde look more interesting for devs on Windows and OSX really. I personally don't get all the craze of kde being able to run on Windows or OSX. QT4 is basically only advertised as being a cross platform toolkit which brings kde to Windows.
How about concentrating about the main (and most important) platform? The "free software" platform. I don't hear much of that lately.
[ Reply To This | View ]
KDE4 et al
by Ian on Thursday 22/Feb/2007, @11:44
Is there a www.kde4.org (someone has already got that) type site where all the information about KDE4 is disseminated?
There is a momentum building throughout for information about it but at the moment you need to be "in the know" of what the constituent parts are going to be in order to find out information. The ideas are fantastic when read about in their isolated silos but it would be good to see them all together showin in a framework of a single site/link from www.kde.org. People love roadmaps and technology maps.
A lot of the names like Plasma, Okular, Decibel don't really tell you what they are about - (sometimes you can guess), how they fit into the total structure, if they depend one each other etc. They all sort of sound like something a marketing driod has thought up, at least with the "K" prefix, you had an idea it was KDE related. (i expect this has all been hashed out already).
I could go on but I've a train to catch....

Thanks to all the developers for a great DE and the apps to match.
[ Reply To This | View ]
Awesome
by taj on Thursday 22/Feb/2007, @18:11
This whole series of articles has been fantastic to read. Thanks Troy!
[ Reply To This | View ]
very pitty
by Gleb on Thursday 22/Feb/2007, @23:21
Pity, "scons" was abandoned in favour of an antiquated and non-intuitive "cmake" system. Very pitty. Just laxly?
[ Reply To This | View ]
Why not use qmake ?
by Rainer on Friday 23/Feb/2007, @00:12
In our project http://pvbrowser.org we use qmake for building our (Qt-)applications.

Why didn't you use it to build KDE ?
You could have extendet it if you needed more custom build steps.
In the past i have added custom build steps for corba idl and oracles embedded SQL for example.

The advantage would be,
that you use the original build system trolltech is using anyway.
And qmake is very simple and clear.
And it is portable also.

PS: We always felt uncomfortable with autotools also. And have trown it away a long time ago.
[ Reply To This | View ]
Could a company have made this transition?
by Norman on Friday 23/Feb/2007, @00:22
Hi,

Don't bother about the eye candy I prefer thought candy and this article is full of it. It deserves a much wider audience than the Linux community. Why? Because it describes a process that leads many commercial companies to go bust or get in big trouble. It describes how power can be exercised without (it appears) power broking. No doubt there are implications for the democratic process itself but I won't try to expand on that.
[ Reply To This | View ]
The Road to KDE4
by Darkelve on Friday 23/Feb/2007, @01:24
I'm writing a tutorial for new Linux users and I have a question about KDE 3.5.x: if the Kwin window manager handles the drawing of window decorations, window contents, etc. , then does Kicker handle the drawing of all the components and parts of kicker? And for the desktop (wallpaper etc.) that would be Kdesktop? What about KDE4?

Then I have a request for the upcoming "Oxygen" article:

can you explain a bit how Oxygen will try to overcome the problems which exist with the current icon/iconset approach:

- When switching between iconsets, it is possible that you 'loose' some icons because alternatives do not exist in the iconset you are switching too. Mostly you'll get a really bland/ugly icon instead

- In KDE's "icon overview" screen, will it be possible to group the icons per theme? Now they are all mixed up and this may give problems when looking for an extra icon for an application, and you want to know if the icon is part of the current iconset you are using

- Are there some kind of icon 'preferences', so that e.g. you can make another icon the default instead of the current default icon. For example, I set the folders in /home/ to use a grey folder icon. But every time I or a program creates a new icon, as well in several Konqueror views, I get a blue icon. Will it be easier to set preferences of this kind in KDE4?
[ Reply To This | View ]
Typo...
by James on Friday 23/Feb/2007, @04:00
milage should be mileage.

Good article! I haven't used KDE in a while, but it is nice to get an overview of the build tools change. Thanks!
[ Reply To This | View ]
The Fine Print: The previous comments are owned by whomever posted them.
( Reply )

  "There are some gaps in my recollection of the past, I always assumed that was sleep." -- Rob Kaper
KDE®, "K Desktop Environment", "KDE Dot News", "got the dot?" and the KDE Logo® are trademarks or registered trademarks of KDE e.V. in the European Union, the United States and other countries. All other trademarks and copyrights on this page are owned by their respective owners. Comments are owned by the poster. The rest: Copyright © 2000-2008 KDE e.V. for The KDE Project. For further information or comments on this site, please contact the Webmaster.
[ home | post article | flat forty | subscribe | search | rdf ]