Logo Caption: | Logo since 2019 |
Developer: | Jussi Pakkanen |
Programming Language: | Python |
Operating System: | Cross-platform |
Genre: | Software development tools |
License: | Apache License 2.0 |
Meson [1] is a software tool for automating the building (compiling) of software. Meson adopts a convention over configuration approach, promoting standard development tools and practice instead of providing unlimited flexibility to the user. Meson is free and open-source software written in Python, under the Apache License 2.0.[2]
Being written in Python, Meson runs 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,[3] and has a mechanism for handling dependencies called Wrap.
Meson supports GNU Compiler Collection, Clang, Microsoft Visual C++ and other compilers, including non-traditional compilers such as Emscripten and Cython.[4] The project uses ninja as the primary backend buildsystem, but can also use Microsoft Visual Studio or Xcode backends.
The syntax of Meson's build description files (the Meson language) borrows from Python, but is not Python: It is designed such that it can be reimplemented in any other language; for example, muon[5] is a C implementation, and Meson++[6] is a C++ implementation. 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.
Feature | Meson | CMake | Make | |
---|---|---|---|---|
Datatypes | ||||
List datatype | ||||
Dictionary datatype | ||||
File globbing | ||||
Extensible via custom functions | ||||
Can read output of arbitrary commands (at configure time) | ||||
Can run arbitrary commands at build time as recipes of custom targets |
As with any typical buildsystem, correct incremental builds are the most significant speed feature (because all incremental progress is discarded whenever the user is forced to do a clean build).
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 whether 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 require configuration. Debug builds are without optimization by default.
speed feature | Meson | CMake | Make | |
---|---|---|---|---|
Prohibits stale builds (partial rebuild against input change) | (unless there are bugs) | |||
The target that runs tests depends on the tests being built (e.g. test depends on all ) | , and add_dependencies(test all) is forbidden, because the test target is reserved. | |||
Symbol-table-aware relinking | ||||
Precompiled headers |
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 | ||||
Set correct library installation directory on x86_64 Unix | ./configure --libdir=/usr/lib64 |
Meson can automatically find and use external dependencies via pkg-config, CMake, and project-specific lookups,[7] but this only finds installed dependencies, which Meson can not do anything about.Alternatively, or as a fallback, a dependency can be provided as a subproject – a Meson project within another, either contained or as a download link, possibly with patches. This lets Meson resolve dependency hell for the convenience of casual users who want to compile the project, but may contribute to software bloat if a common installed dependency could have been used instead. The mode favored by Linux packagers is therefore fallback.
Meson supports Meson and CMake subprojects. A Meson build file may also refer to the WrapDB service.
use case | Meson | CMake | Cargo | |
---|---|---|---|---|
Finding installed dependencies | pkg-config, CMake packages | CMake module, pkg-config | ||
Downloading dependencies automatically | subproject | FetchContent[8] | Cargo dependency | |
Finding installed dependencies, with download fallback | pkg-config + subproject | CMake module/pkg-config + | ||
pkg-config file generator | ||||
Facilitate use as an auto-downloadable dependency |
Cross compilation requires extra configuration, which Meson supports in the form of a separate cross file, which can be external to the Meson project.
GNOME has made it a goal to port its projects to Meson.[9] As of late 2017, GNOME Shell itself exclusively requires Meson after abandoning Autotools,[10] and central components like GTK+, Clutter-GTK, GLib and GStreamer can be built with Meson.[9]
Many freedesktop.org projects have switched to Meson. Systemd relies on Meson since dropping Autotools in version 234,[11] and also X.Org[12] and Mesa[13] were ported to Meson.
Meson's support for Fortran and Cython was improved to help various scientific projects in their switch from to Meson, for example SciPy.[14] Meson can also be used as a PEP517 backend to build Python wheels, via the package.[15]
Other notable projects using Meson include QEMU and PostgreSQL; the Meson homepage lists further projects using Meson.[16]