CMake – A build tool that just works

I've been using CMake 2.6 for quite some time now, and the more I do, the more I like it. Just a few days ago, I started with porting some project to Linux, and it took me literally a few minutes until I had the build going and started fixing portability problems in the code.

Basically, what CMake does (besides causing constant problems with my spelling checker who thinks it should be written Cmake) is to generate build files. It supports a variety of platforms and build tools. On Windows for example, you can generate build files for Visual Studio from version 6 to 9, including x64 versions, and nmake files (plus some other types). This is really helpful if you have for example an application that has to work on Win32 and Win64, as you don't have to maintain two sets for the configuration. Moreover, you keep the option of porting it to Linux open.

And this is the killer-feature: It really works! Even if you started on Windows, your project will work (unless you used non-portable stuff) directly on Linux. No matter how complicated the dependencies are, whether you have pre- & post-build steps, if it is valid for CMake and works on one platform, it'll also work on another. You can't take this for granted: Previously, I've been using SCons, which usually required quite some work even to support several compilers on one platform, which was a major pain.

There are still some caveats you should keep in mind:

  • Linux is case sensitive, Windows not. Make sure you spell the filenames right, or you'll get errors (you will get errors during #including later, too ;) ).
  • Beware that Linux comes usually with far more libraries than Windows, which will be found directly using the various Find* module scripts. I've been searching for Boost, and instead of finding my custom 1.36 install, it found (by default) the system installation which was 1.34.1.
  • Checking for the architecture on Linux requires to look at CMAKE_SYSTEM_PROCESSOR as there is no CMAKE_GCC_64. A simple IF("{CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") should do the trick.


Comments powered by Disqus