Meson (software)
{{Short description|Build automation tool}}
{{Use dmy dates|date=January 2021}}
{{Infobox software
| logo = Meson (software) logo 2019.svg
| logo caption = Logo since 2019
| screenshot = Meson 0.58.0 screenshot.png
| developer = Jussi Pakkanen
| caption = Meson configuring dav1d
| released = {{Start date and age|2013|03|02|df=y}}
| latest release version = {{wikidata|property|edit|reference|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}
| latest preview version =
| latest preview date =
| programming language = Python
| operating system = Cross-platform
| genre = Software development tools
| license = Apache License 2.0
}}
Meson ({{IPAc-en|ˈ|m|ɛ|.|s|ɒ|n}}){{cite web|title=Making build systems not suck (linux.conf.au video)| website=YouTube | date=16 January 2015 |url=https://www.youtube.com/watch?v=KPi0AuVpxLI&t=2004}} is a software build automation tool for building a codebase. Meson adopts a convention over configuration approach to minimize the data required to configure the most common operations. Meson is free and open-source software under the Apache License 2.0.{{cite web|title=mesonbuild/meson: The Meson Build System|url=https://github.com/mesonbuild/meson|website=GitHub|accessdate=13 April 2016}}
Meson is written in Python and runs on Unix-like (including Linux and macOS), Windows and other operating systems. It supports building C, C++, C#, CUDA, Objective-C, D, Fortran, Java, Rust, and Vala.{{cite web |url=https://mesonbuild.com/Reference-manual_functions.html#project|title=Reference manual}} It handles dependencies via a mechanism named Wrap. It supports GNU Compiler Collection (gcc), Clang, Visual C++ and other compilers, including non-traditional compilers such as Emscripten and Cython.{{cite web |url=https://mesonbuild.com/Reference-tables.html#compiler-ids|title=Compiler IDs}} The project uses ninja as the primary backend buildsystem, but can also use Visual Studio or Xcode backends.
Meson's support for Fortran and Cython was improved to help various scientific projects in their switch from {{mono|setuptools}} to Meson, for example SciPy.{{cite web |title=How to build SciPy with Meson|url=https://scipy.github.io/devdocs/dev/contributor/meson.html}} Meson can be used as a PEP517 backend to build Python wheels, via the {{mono|meson-python}} package.{{cite web |title=meson-python package on PyPI|url=https://pypi.org/project/meson-python/}}
Language
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{{Cite web |title=muon.build |url=https://muon.build/ |access-date=2023-01-27}} is a C implementation, and Meson++{{Cite web |last=Baker |first=Dylan |title=dcbaker/meson-plus-plus |website=GitHub |date=2021-05-28 |url=https://github.com/dcbaker/meson-plus-plus |access-date=2021-05-28}} 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.
Speed and correctness
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.{{cite web |title=Feature Autodetection |url=https://mesonbuild.com/Feature-autodetection.html}} 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.{{cite web |title=Precompiled headers |url=https://mesonbuild.com/Precompiled-headers.html}} Debug builds are without optimization by default.
{{More citations needed section|date=March 2024}}
{{Original research section|date=March 2024}}
Features
A stated goal of Meson is to facilitate modern development practices. As such, Meson knows how to do unity builds,{{cite web |title=Unity builds |url=https://mesonbuild.com/Unity-builds.html}} build with test coverage{{cite web |title=Unit-tests |url=https://mesonbuild.com/Unit-tests.html#coverage}} etc. without the programmer having to write support for this.
= Subprojects =
Meson can automatically find and use external dependencies installed on the user's system via pkg-config, CMake, and project-specific lookups.{{Cite web|url=https://mesonbuild.com/Dependencies.html#dependencies-with-custom-lookup-functionality|title=Dependencies with custom lookup functionality — Meson documentation}}
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.
= 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.
= Installation directory setup =
Setting the library installation directory on x86_64 Unix is handled automatically by Meson, but not by other tools such as Autotools.{{clarify|date=February 2025}}
Adopters
{{Main|Category:Software that uses Meson}}
GNOME has made it a goal to port its projects to Meson.{{cite web |url=https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting |title=GNOME Goal: Port modules to use Meson build system}} As of late 2017, GNOME Shell itself exclusively requires Meson after abandoning Autotools,{{cite web |url=https://www.phoronix.com/scan.php?page=news_item&px=GNOME-3.26-Beta |title=GNOME 3.26 Beta Debuts: More Meson Porting, Wayland Action}} and central components like GTK+, Clutter-GTK, GLib and GStreamer can be built with Meson.
Many freedesktop.org projects have switched to Meson. Systemd relies on Meson since dropping Autotools in version 234,{{cite web |url=https://github.com/systemd/systemd/pull/6266 |title=Drop support for autotools| website=GitHub }} and also X.Org{{cite web |url=https://www.phoronix.com/scan.php?page=news_item&px=Mesa-X-Server-Lands |title=Meson Support Has Landed In The X.Org Server
}} and Mesa{{cite web |url=https://www.phoronix.com/scan.php?page=news_item&px=Mesa-Closer-To-Kill-Autotools |title=Mesa Developers Move Closer To Dropping Autotools Build System In Favor Of Meson}} were ported to Meson.
Feature comparison
Feature comparison with CMake and Make.
class="wikitable" | |||
Feature | Meson | CMake | Make |
---|---|---|---|
Datatypes | {{Yes}} | {{No}} | {{No}} |
List datatype | {{Yes}} | {{Maybe|semicolon-delimited string}} | {{Maybe|whitespace-delimited string}} |
Dictionary datatype | {{Yes|since 0.47.0}} | {{No}} | {{No}} |
File globbing | {{No}} | {{Yes}} | {{Maybe|non-standard extension on some variants}} |
Extensible via custom functions | {{No}} | {{Yes}} | {{No}} |
Can read output of arbitrary commands (at configure time) | {{Yes|{{mono|run_command}}}} | {{Yes}} | {{Yes}} |
Can run arbitrary commands at build time as recipes of custom targets | {{Yes}} | {{Yes}} | {{Yes}} |
Prohibits stale builds (partial rebuild against input change) | {{Yes}} (unless there are bugs){{Contradictory inline|date=March 2024}} | {{Maybe|If not globbing source files}}{{citation needed|date=March 2024}} | {{Failure|Recursive Make (an idiomatic pattern) is broken in this respect}} |
The target that runs tests depends on the tests being built (e.g. test depends on all ) | {{Yes}}{{citation needed|date=March 2024}} | {{No}}, and add_dependencies(test all) is forbidden, because the test target is reserved. | {{Optional|Trivial to add}}{{citation needed|date=March 2024}} |
Ccache | {{Yes|Automatic}} | {{Optional|Trivial to add}}{{citation needed|date=March 2024}} | {{Optional|Trivial to add}}{{citation needed|date=March 2024}} |
Distcc | {{Optional|Trivial to add}}{{citation needed|date=March 2024}} | {{Optional|Trivial to add}}{{citation needed|date=March 2024}} | {{Optional|Trivial to add}}{{citation needed|date=March 2024}} |
Symbol-table-aware relinking | {{Yes}}{{citation needed|date=March 2024}} | {{Rarely|Do it yourself}}{{citation needed|date=March 2024}} | {{Rarely|Do it yourself}}{{citation needed|date=March 2024}} |
Precompiled headers | {{Optional}} | {{Yes2|CMake ≥ 3.16}} | {{Rarely|Do it yourself}}{{citation needed|date=March 2024}} |
Finding installed dependencies | pkg-config, CMake packages | CMake module, pkg-config | {{sdash}} |
Downloading dependencies automatically | subproject | FetchContent{{Cite web|url=https://cmake.org/cmake/help/v3.15/module/FetchContent.html|title = FetchContent — CMake 3.15.7 Documentation}} | {{sdash}} |
Finding installed dependencies, with download fallback | pkg-config + subproject | CMake module/pkg-config + {{code|FetchContent}} | {{sdash}} |
pkg-config file generator | {{Yes}} | {{No}} | {{sdash}} |
Facilitate use as an auto-downloadable dependency | {{Yes|Can be used as a Meson subproject}} | {{No}} | {{sdash}} |
See also
{{Portal|Free and open-source software}}
- {{section link|List of build automation software|Build script generation}}
References
{{Reflist|30em|refs=
{{cite web|url=http://mesonbuild.com/Syntax.html|title=Meson Syntax}}
{{cite web|url=http://mesonbuild.com/FAQ.html|title=Meson Frequently Asked Questions}}
{{cite web|url=http://mesonbuild.com/Cross-compilation.html|title=Cross compilation}}
{{cite web|url=https://www.microsoft.com/en-us/research/wp-content/uploads/2016/03/hadrian.pdf|title=Non-recursive Make Considered Harmful| website=Microsoft |quote=Recursive Make is considered harmful for very good reasons (Miller 1998); it is not possible to accurately track dependencies when the build system is constructed of separate components that invoke each other.}}
}}