Wednesday, September 27, 2006

CMake and Autotools

I'm very grateful that somebody (Joe Cooley) contributed Autoconf and Automake files for the PBC library that I maintain. The GNU Autotools are almost essential because many people expect its presence and are used to compiling packages on Unix by typing ./configure followed by make. For the same reason, the Autotools give the project a more mature appearance. And they really do allow painless compilation on many systems.

But there is a dark side to using the GNU build system. The PBC source packages increased by several hundred kilobytes. I notice this extra weight because I often use wireless networks. Additionally, build times are at least twice as slow. On one run, it took 37 seconds to compile PBC, compared to 13 seconds with the original handwritten Makefile. And that's not counting the 13 seconds for ./configure and the 4 seconds for ./setup.

Furthermore, one has to be fluent in m4 and various configuration file formats, and understand how the toolchain works to create and maintain the build system. I was never motivated enough to learn all this, and I haven't changed. Any modifications I make to the Autoconf and Automake files are based on what I see there already, or a brief Google search.

It seems some people were sufficiently dissatisfied with the Autotools that they offered a substantial sum to anyone who wrote a better build tool. The winning project was SCons, which I experimented with last time I needed a build tool with more features than make.

But now a different tool has caught my attention, ever since I read this article. The KDE project ran into trouble with the Autotools, and began searching for alternatives. Like me, they found SCons promising, but after further investigation decided to switch to CMake.

Porting KDE to different platforms is highly nontrivial, so I reasoned that if CMake worked for such a substantial project, odds are good that it would work for my tiny library. I'm following by example I guess, and it certainly isn't the first time. I use git because it works for managing the Linux kernel source, and I use C because it works for countless important parts of the system (including of course the kernel), and for many well-respected programmers across several generations.

While researching CMake I found more arguments for switching: autoconf/automake is insane, glowing reviews of CMake (in the comments section), another endorsement and an interview with a CMake author.

I had a CMakeLists.txt file up and running fairly quickly, as the syntax is quite simple. Running times are much better: CMake took a couple of seconds to generate a Makefile, which in turn only took a second longer than my handwritten one to compile PBC. I was also pleased by the clean and colourful output.

Unfortunately, CMake is not installed on many systems. And it must be relatively untested. How does it compare to the Autotools on less mainstream platforms? And what about the more obscure tasks that the Autotools excel at? For example, is it difficult to get CMake to cross-compile a project?

For now, I'll have to maintain two sets of build configuration files in parallel, but I hope one day CMake will be equally well-known and widespread so I can jettison the autoconf/automake baggage.

No comments: