LinuxCommandLibrary

meson

Configure software build systems

TLDR

Generate a C project with a given name and version

$ meson init [[-l|--language]] c [[-n|--name]] [myproject] --version [0.1]
copy

Configure the builddir with default values
$ meson setup [build_dir]
copy

Build the project
$ meson compile -C [path/to/build_dir]
copy

Run all tests in the project
$ meson test
copy

Display help
$ meson [[-h|--help]]
copy

Display version
$ meson [[-v|--version]]
copy

SYNOPSIS

meson [global-options] <command> [command-options]
meson [global-options] <builddir> [sourcedir] [setup-options]
meson --version | --help

PARAMETERS

--help
    Displays a help message and exits. Can be used as meson --help for global options or meson --help for subcommand-specific help.

--version
    Shows the Meson version number and exits.

--builddir
    Specifies the path to the build directory. If not provided for commands like compile or test, Meson looks for a build.ninja file in the current directory or a standard sub-directory like build/.

--backend
    Selects the build backend to use for generating build files (e.g., ninja, vs for Visual Studio). Ninja is the default and recommended backend.

--cross-file
    Path to a file describing the cross-compilation environment and settings.

--native-file
    Path to a file describing the native build environment and settings (useful for specifying dependencies or toolchains).

--fatal-meson-warnings
    Treats any warnings emitted by Meson itself as fatal errors, causing the build configuration to fail.

--warn-error
    Instructs the compiler/linker to treat warnings as errors, causing compilation to fail on warnings (applies to supported backends).

-D
    Sets a project option for the build. This is typically used during the setup phase (e.g., -Ddebug=true or -Dprefix=/usr).

--wipe
    Used with the setup command. Wipes the existing build directory entirely before reconfiguring the project from scratch.

--reconfigure
    Used with the setup command. Reconfigures an existing build directory without wiping it, applying any new options or changes.

DESCRIPTION

Meson is an open-source build system designed for high performance and ease of use. It aims to make building software projects straightforward and enjoyable, supporting a wide range of programming languages and platforms including C, C++, Rust, Python, and Java. Meson works by generating build files for various backends, with Ninja being its primary and recommended choice due to its exceptional speed. It focuses on expressiveness, safety, and correctness, using a simple, declarative build definition language. Key features include automatic dependency detection, robust cross-compilation support, automatic dependency fetching (subprojects), and built-in testing capabilities. Meson is widely adopted in modern open-source projects for its efficiency, maintainability, and ability to streamline the development workflow from configuration to installation.

CAVEATS

Meson requires a separate build backend like Ninja to perform actual compilation; Meson itself is primarily a build system generator. While its build definition language is designed for simplicity, new users might find the transition from imperative build systems challenging. Effective cross-compilation requires well-defined cross-files that accurately describe the target environment and toolchain, which can be complex to set up initially.

SUBCOMMANDS

Meson operates through a system of subcommands, each performing a specific task. For example, meson setup configures the build directory, meson compile builds the project, meson test runs tests, and meson install installs the built project. Each subcommand has its own set of specific options, which can be viewed using meson --help.

BUILD DIRECTORY SEPARATION

A core design principle of Meson is the strict separation of source and build directories. All generated files, object files, and compiled executables are placed in a dedicated build directory, leaving the source tree pristine. This approach facilitates managing multiple build configurations (e.g., debug, release, or different targets) from the same source codebase without interference.

HISTORY

Meson was initially created by Jussi Pakkanen and first released in 2013. It emerged as a modern alternative to traditional build systems like Autotools and CMake, aiming to address their perceived complexity, slowness, and difficulty in cross-platform development. Its design philosophy emphasizes speed, ease of use, and strong support for modern development practices. Meson quickly gained traction, particularly within the GNOME project and other open-source communities, due to its efficient incremental builds (leveraging Ninja), declarative syntax, and robust cross-compilation capabilities. Its development is active, continuously improving its features and expanding language and platform support.

SEE ALSO

ninja(1), cmake(1), make(1), autotools(1)

Copied to clipboard