Meson

Short description: Build automation system

Meson

Logo since 2019

Meson configuring dav1d

Developer(s)| Jussi Pakkanen
Initial release| 2 March 2013; 11 years ago (2013-03-02)
Written in| Python
Operating system| Cross-platform
Type| Software development tools
License| Apache License 2.0

Meson (/ˈmɛ.sɒn/)[1] is a software tool for automating the building (compiling) of software. The overall goal for Meson is to promote programmer productivity.[2] Meson is free and open-source software written in Python, under the Apache License 2.0.[3]

## Contents

* 1 Interoperability
* 2 Language
* 3 Speed and correctness
* 4 Features
* 4.1 Subprojects
* 4.2 Cross compilation
* 5 Adopters
* 6 See also
* 7 References
* 8 External links

## Interoperability

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,[4] 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.[5] The project uses ninja as the primary backend buildsystem, but can also use Microsoft Visual Studio or Xcode backends.

## 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;[6] for example, muon[7] is a C implementation and Meson++[8] 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.[6] 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.[9] In particular, unlike Make, the list type does not split strings on whitespace.[6] Thus, whitespace and other characters in filenames and program arguments are handled cleanly.

| Meson | CMake | Make

|
|
|

Datatypes | Yes | No | No
List datatype | Yes | semicolon delimited string | whitespace delimited string
Dictionary datatype | since 0.47.0 | No | No
File globbing | No | Yes | Yes
Extensible via custom functions | No | Yes | Yes
Can read output of arbitrary commands (at configure time) | run_command | Yes | Yes
Can run arbitrary commands at build time as recipes of custom targets | Yes | Yes | Yes

## Speed and correctness

As with any typical buildsystem, correct incremental builds is 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.[6] 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.[10]

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 (partial rebuild against input change) | Yes (unless there are bugs) | If not globbing source files | Recursive Make (an idiomatic pattern) is broken in this respect[11]
The target that runs tests depends on the tests being built (e.g. `test` depends on `all`) | Yes | No, and `add_dependencies(test all)` is forbidden, because the `test` target is reserved.[12] | Trivial to add
Ccache | Automatic | Trivial to add | Trivial to add
Distcc | Trivial to add | Trivial to add | Trivial to add
Symbol table aware relinking | Yes | Do it yourself | Do it yourself
Precompiled headers | Optional | CMake ≥ 3.16[13][1] | Do it yourself

## 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 | No | No | `make dist`
Set correct library installation directory on x86_64 Unix | Automatic | Not standardized | `./configure --libdir=/usr/lib64`

### Subprojects

Meson can automatically find and use external dependencies via pkg-config, CMake, and project-specific lookups,[14] 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.[15] 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.[16]

Meson supports Meson and CMake subprojects. A Meson build file may also refer to the WrapDB service.[15]

Comparison of dependency resolution use cases in different build systems

use case | Meson | CMake | Cargo

|
|
|

Finding installed dependencies | pkg-config, CMake packages | CMake module, pkg-config | ?
Downloading dependencies automatically | subproject | FetchContent[17] | Cargo dependency
Finding installed dependencies, with download fallback | pkg-config + subproject | CMake module/pkg-config + `FetchContent` | ?
pkg-config file generator | Yes | No | No
Facilitate use as an auto-downloadable dependency | Can be used as a Meson subproject | No | With registration to crates.io

### 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.[18]

## Adopters

GNOME has made it a goal to port its projects to Meson.[19] As of late 2017, GNOME Shell itself exclusively requires Meson after abandoning Autotools,[20] and central components like GTK+, Clutter-GTK, GLib and GStreamer can be built with Meson.[19]

Many freedesktop.org projects have switched to Meson. Systemd relies on Meson since dropping Autotools in version 234,[21] and also X.Org[22] and Mesa[23] were ported to Meson.

Meson's support for Fortran and Cython was improved to help various scientific projects in their switch from setuptools to Meson, for example SciPy.[24] Meson can also be used as a PEP517 backend to build Python wheels, via the meson-python package.[25]

Other notable projects using Meson include QEMU and PostgreSQL; the Meson homepage lists further projects using Meson.[26]

## See also

* Cmake
* make
* List of build automation software § Build script generation

## References

1. ↑ 1.0 1.1 "Making build systems not suck (linux.conf.au video)". https://www.youtube.com/watch?v=KPi0AuVpxLI&t=2004.
2. ↑ "High productivity build system". https://build.opensuse.org/package/show/openSUSE:Factory/meson. "Meson aims to optimize programmer productivity by providing simple, out-of-the-box support for modern software development tools and practices, such as unit tests, coverage reports, Valgrind, CCache and the like."
3. ↑ "mesonbuild/meson: The Meson Build System". https://github.com/mesonbuild/meson. Retrieved 13 April 2016.
4. ↑ "Reference manual". https://mesonbuild.com/Reference-manual_functions.html#project.
5. ↑ "Compiler IDs". https://mesonbuild.com/Reference-tables.html#compiler-ids.
6. ↑ 6.0 6.1 6.2 6.3 "Meson Frequently Asked Questions". http://mesonbuild.com/FAQ.html.
7. ↑ muon.build, https://muon.build/, retrieved 2023-01-27
8. ↑ Baker, Dylan (2021-05-28), dcbaker/meson-plus-plus, https://github.com/dcbaker/meson-plus-plus, retrieved 2021-05-28
9. ↑ "Meson Syntax". http://mesonbuild.com/Syntax.html.
10. ↑ "CMake FILE command". https://cmake.org/cmake/help/v3.2/command/file.html. "Note: We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed, the generated build system cannot know when to ask CMake to regenerate."
11. ↑ "Non-recursive Make Considered Harmful". https://www.microsoft.com/en-us/research/wp-content/uploads/2016/03/hadrian.pdf. "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."
12. ↑ "Make test does not depend on make all". 2016-06-23. https://gitlab.kitware.com/cmake/cmake/-/issues/8774. Retrieved 3 September 2020.
13. ↑ "CMake support for precompiled headers". https://gitlab.kitware.com/cmake/cmake/issues/1260. Retrieved 13 March 2018.
14. ↑ "Dependencies with custom lookup functionality — Meson documentation". https://mesonbuild.com/Dependencies.html#dependencies-with-custom-lookup-functionality.
15. ↑ 15.0 15.1 "Wrap dependency system manual". http://mesonbuild.com/Wrap-dependency-system-manual.html.
16. ↑ "Meson and 3rd party dependencies. Only one correct way". https://blogs.gnome.org/ignatenko/2015/05/21/meson-and-3rd-party-dependencies-only-one-correct-way/.
17. ↑ "FetchContent — CMake 3.15.7 Documentation". https://cmake.org/cmake/help/v3.15/module/FetchContent.html.
18. ↑ "Cross compilation". http://mesonbuild.com/Cross-compilation.html.
19. ↑ 19.0 19.1 "GNOME Goal: Port modules to use Meson build system". https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting.
20. ↑ "GNOME 3.26 Beta Debuts: More Meson Porting, Wayland Action". https://www.phoronix.com/scan.php?page=news_item&px=GNOME-3.26-Beta.
21. ↑ "Drop support for autotools". https://github.com/systemd/systemd/pull/6266.
22. ↑ "Meson Support Has Landed In The X.Org Server". https://www.phoronix.com/scan.php?page=news_item&px=Mesa-X-Server-Lands.
23. ↑ "Mesa Developers Move Closer To Dropping Autotools Build System In Favor Of Meson". https://www.phoronix.com/scan.php?page=news_item&px=Mesa-Closer-To-Kill-Autotools.
24. ↑ "How to build SciPy with Meson". https://scipy.github.io/devdocs/dev/contributor/meson.html.
25. ↑ "meson-python package on PyPI". https://pypi.org/project/meson-python/.
26. ↑ "List of projects using Meson". https://mesonbuild.com/Users.html.

## External links

0.00

(0 votes)

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Meson&oldid=3456803"