Meson (software)
Meson is a software tool for automating the building of software. The overall goal for Meson is to promote programmer productivity. Meson is free and open-source software written in Python, under the Apache License 2.0.
Interoperability
Being written in Python, Meson runs natively on Unix-like operating systems, including macOS, as well as Microsoft Windows and on other operating systems.Meson supports the C, C++, CUDA, D, Objective-C, Fortran, Java, C#, Rust and Vala languages, and has a mechanism for handling dependencies called Wrap.
Meson supports GNU Compiler Collection, Clang, Microsoft Visual Studio and others.
Usage
Meson is like CMake in that it does not build software directly, but rather sets up a backend build system such as ninja and Cargo on Linux, MSBuild on Windows or Xcode on macOS. The user then invokes the backend buildsystem. Because only out-of-tree builds are supported, it requires the user to create a build directory for this backend buildsystem and its outputs. The basic usage difference is that CMake defaults to make as a backend instead of ninja, but cmake -G Ninja behaves like Meson in this regard.Language
The syntax of Meson's build description files borrows from Python, but is not Python: It is designed such that it can be reimplemented in any other language – the dependency on Python is an implementation detail.The Meson language is intentionally not Turing complete, and can therefore not express an arbitrary program. Instead, arbitrary build steps beyond compiling supported languages can be represented as custom targets.
The Meson language is strongly typed, such that builtin types like library, executable, string, and lists thereof, are non-interchangeable. In particular, unlike Make, the list type does not split strings on whitespace. Thus, whitespace and other characters in filenames and program arguments are handled cleanly.
Meson | CMake | Make | |
Datatypes | |||
List datatype | |||
File globbing | |||
Extensible via custom functions | |||
Can read output of arbitrary commands | |||
Can run arbitrary commands at build time as recipes of custom targets |
Speed and correctness
As with any typical buildsystem, correct incremental builds is the most significant speed feature.Unlike bare Make, the separate configure step ensures that changes to arguments, environment variables and command output are not partially applied in subsequent builds, which would lead to a stale build.
Like Ninja, Meson does not support globbing of source files. By requiring all source files to be listed in the build definition files, the build definition file timestamps are sufficient to determine if the set of source files has changed, thereby ensuring that removed source files are detected. CMake supports globbing, but recommends against it for the same reason.
Meson uses ccache automatically if installed. It also detects changes to symbol tables of shared libraries to skip relinking executables against the library when there are no ABI changes. Precompiled headers are supported, but requires configuration. Debug builds are without optimization by default.
speed feature | Meson | CMake | Make |
Prohibits stale builds | |||
Ccache | |||
Distcc | |||
Symbol table aware relinking | |||
Precompiled headers | CMake ≥ 3.16 |
Features
A stated goal of Meson is to facilitate modern development practices. As such, Meson knows how to do unity builds, build with test coverage, link time optimization etc without the programmer having to write support for this.Meson | CMake | Autotools | |
Generate a configure script | make dist | ||
Set correct library installation directory on x86_64 Unix | ./configure --libdir=/usr/lib64 |
Subprojects
Like CMake, Meson primarily uses pkg-config to find dependencies that are external to the project. This is not a solution to dependency hell, as the job of satisfying missing dependencies is on the user. Alternatively, the dependency can be internalized as a subproject – a Meson project within another – either contained or as a link. This has the drawback of contributing to software bloat in the case of common dependencies. The compromise favored by Linux packagers is to use the subproject as a fallback for the external dependency.Meson supports Meson and CMake subprojects. A Meson build file may also refer to the WrapDB service.
;Comparison of dependency resolution use cases in different build systems:
use case | Meson | CMake | Cargo |
Finding installed dependencies | pkg-config | CMake module, pkg-config | |
Downloading dependencies automatically | subproject | ExternalProject | |
Finding installed dependencies, with download fallback | pkg-config + subproject | CMake module/pkg-config + ExternalProject | |
pkg-config file generator | |||
Facilitate use as an auto-downloadable dependency |
;Notes
Cross compilation
Cross compilation requires extra configuration, which Meson supports in the form of a separate cross file, which can be external to the Meson project.Adopters
has made it a goal to port its projects to Meson. As of late 2017, GNOME Shell itself exclusively requires Meson after abandoning Autotools, and central components like GTK+, Clutter-GTK, GLib and GStreamer can be built with Meson.Systemd relies on Meson since dropping Autotools in version 234.
Also X.Org and Mesa were ported to Meson.
The Meson homepage lists further projects using Meson.