Use meson
For the first time in a long time I felt happy about a piece of software: it’s meson the build system. I wrote about my adventures with CMake but in the end I was never really happy with it. Be it its arcane syntax, intransparent build process or lack of following standards common in the nix world. I used it but grudgingly because I could not let my colleagues be burdened with Autotools.
I read about meson about the time it was first announced but did not dare to dive into it because of lack of maturity and long-term perspective. However, learning that a lot of GNOME and systemd related software is moving from Autootools to meson, I changed my mind and read the great manual in order to convert some of our bigger C projects over from CMake. And what a joy it was!
First the build language: it’s clear, simple and deliberately not Turing-complete. Unlike what a lot of folks imply when they hear that meson is written in Python, the language itself is a separate domain specific language. Many features of this language do not feel like an afterthought but very helpful to describe build artifacts and build related information. For example string and list processing such as
foo = ' '.join([bar, 'baz'])
feels a lot more robust than CMake’s
SET(foo "${bar} baz")
Having a real boolean type reduces the amount of guesswork in situations with conditionals considerably. Having a Turing-incomplete language with an object-oriented approach seems verbose, I had the reverse feeling that I was writing less but more explicit code. A good thing in my opinion.
The best part on Linux is that meson does not try to depart too much from the
conventional ./configure && make && make install
dance. meson
works exactly
like configure
except for the fact that it enforces out-of-source builds. In
this step, meson uses pkgconfig
in a first class way to find a library’s
compile and link flags unlike CMake which for years suggested to use the
included modules. In the other direction, meson has first-class support for
pkgconfig
file generation, with CMake having you to abuse configure_file()
and still get it wrong. There other tool-specific modules such as the gnome
module that let you finish your job in a few lines instead of constructing new
build targets with fragile command construction.
The configuration times for me with meson are almost ten times shorter than CMake but this probably varies from project to project. The build times are equally long if you opt-in to use CMake with Ninja, the default build tool of meson. meson’s build output is a bit nicer because it does not spam the console if there are no warnings or errors during the build.
For now I found only one thing that would have to let me go back to CMake once in a while: meson requires Python 3.4 and newer. This is not the case on a few machines I still have to work on, but time will let these phase out too.