Meson: Should you use it?
Coming from the world of janky Makefiles held together by years of accumulated cruft that nobody dares look at for too long, Meson is a breath of fresh air. The declarative syntax makes it easier to understand the structure of the build.
The question then is: if you are starting a greenfield project today, should you use Meson, CMake, or something else?
Meson is just enough
Compared to CMake, with its million variables and many ways of doing things, Meson is just enough. It imposes a structure and provides conveniences to work within that structure.
Take coverage, for example: in CMake, adding coverage usually involves copying the CodeCoverage.cmake file from a repository, discovering that it is somehow 400 lines of code, and deciding that there is something more urgent to do.
In Meson, it’s as simple as passing -Db_coverage=true to the build.
In the time it takes to find the first scary code-coverage CMake module on GitHub, you can have it running in Meson. The downside is that if you do not like the way Meson does coverage, your only recourse is a pull request on the Meson repository. The CMake module, by contrast, is endlessly customisable and can be bent to whatever unholy workflow you need.
This is true for many things. Meson makes it easy to do things the Meson way.
Meson is sometimes half-baked
Meson features are sometimes implemented in interesting ways.
For example, Meson will automatically create a clang-format target if there is a .clang-format file in the root of the top-level project. However, that target reformatted everything in the repository, including the contents of subprojects/ (the sources for dependencies installed as wraps). This was eventually fixed with a .clang-format-ignore file that lists paths that clang-format should ignore.
The clang-tidy integration was implemented the same way. It initially scanned every single C-like file in the repository, including files that were never built. A subsequent release changed the behaviour to only consider files that participate in targets.
The cycle repeats: the Meson developers push out a new feature and iterate on it over the next year to make it usable. Because of this, the behaviour of the feature can change dramatically from one release to the next.
The clang-tidy issue, for example, cost a few hours of debugging to understand why the set of warnings generated by clang-tidy on my development machine and in CI were different.
Meson is sometimes inconsistent
Consistency is key to muscle memory. If I run make, I know that the flag to select the directory to run in is always -C.
In Meson, different commands require the build directory to be passed differently. A few commands take it as a positional argument:
meson setup BUILDDIR
meson configure BUILDDIR
meson introspect BUILDDIR
A few others take it as a parameter:
meson compile -C BUILDDIR
meson test -C BUILDDIR
This is a small papercut, but one that cuts me with frustrating regularity and illustrates my experience with Meson: it’s a nice tool, but it sometimes drives me nuts.
Is Meson enough?
CMake has grown into a beast. Everything can be done in three different ways, and to learn how to do anything you need to wade through 15 years of blog posts documenting the evolution of the modern way.
Meson has one (sometimes quirky) way of doing things. If you need something that Meson does not do, then your best bet is to call out to a script to do it.
For small to medium-sized standalone projects, this is not much of an issue. Where CMake pushed you towards a cmake/ folder full of overly complicated scripts, Meson forces you to keep things simple.
This requires a bit of an adjustment.
In a corporate environment or a complex codebase, those CMake modules exist to simplify the build, provide common defaults, automate repetitive setup, etc. This will not be possible with vanilla Meson. You are left with two options:
In short, for small to medium-sized projects, it’s a no-brainer. It’s simpler than anything else I’ve used. For larger projects, you may be better served by something more complex. Where the line between required complexity and yak shaving lies is a whole other can of worms.