Meson

User-friendly build system which provides a DSL allowing the user to describe the structure of the build. Additional support is provided for modern tooling/best practices, e.g. unit testing, coverage reporting, precompiled headers, etc. These features are included out of the box.

Meson builds (like other build systems) are divided into two steps, a configure and a build step. The configure step performs all the steps neccesary to configure the build before generating the build system. The build step then executes the system, generating build targets (e.g. executables and shared/static libs).

The appropriatly named source directory is where the source code is stored, and the build directory is where the output is written. This varies from other systems which has both source and build targets in the same directory, an in-source build. The out-of-source build is enfored by meson, and it is impossible to do an in-source build with meson.

Templates

Meson provides basic setup for different projects, with meson init. E.g. to create build definitions for a project titled hello:

mkdir hello
cd hello
meson init --language=c --name=hello --version=0.1

Then to compile

meson setup builddir
meson compile -C builddir

See meson init --help for settings and options.

Configuration

The top directory contains a file titled meson.build, and can be s

Installing

From package manager

brew install meson ninja

Quick start

Make a new directory to hold the project

mkdir hello_world
cd hello_world

Meson can create the pfokect skeleton and compile it, with the result being in the build subdirectory

meson init --name hello_world --build

The result can run from the build directory

build/hello_world

Compiling meson project

All artifacts from meson are stored in the build directory, and does not allow you to build source code inside the source tree. This has the benefit of allowing multiple build trees with different configs, and keeping your vcs clean.

The build command will always be the same, meson compile. Changes to source and build system files are detected, and meson will handle it.


Links to this note