Meson is primarily a C/C++ build-system, arguably better than CMake or GNU Autotools in terms of UX.
These points are essential to both the programmer and the end user who builds the project.
-
A file
meson.buildmust exist at the top-level directory of the project. -
Meson doesn't allow “in-source builds”, meaning it requires a separate build directory. As customary, separate directories are to made for separate configurations—debug or release.
$ meson setup builddir $ meson compile -C builddir
-
Configuration step only needs to be performed once, the build-system thereafter automatically detects any changes in source code or DSL during the Build step.
-
Meson uses the Ninja backend by default, which can be changed through
--backendoption supplied in configuration step. But, using Ninja is a more feasible option than generating Makefiles which none has any idea of. -
Meson has major four build types, namely—
plain(no compiler options),debug,debugoptimized(usually-O2 -g),release; all can be specified through--buildtypeoption during configuration step.$ meson setup builddir --buildtype=release
-
Meson understands environment variables like
CCandCXX, which could be used to control the choice of compilers during configuration step, e.g. usingclanginstead ofgcc.$ CC=clang meson setup builddir
-
Meson will only install build targets explicitly tagged (see here) as installable. The default installation root is
/usr/local, which can be changed through--prefix.$ meson install -C builddir --prefix ~/.local
A Meson project is defined in meson.build (a Python-like DSL); the directory in which it exists becomes the root of the project. A project is first declared with the project() directive containing—name, version, languages used within the project. Each project is equipped with a set of build targets of types either—static, shared or executable; defined by static_library(), shared_library(), executable() directives respectively. Each build target generates build artifacts in the build directory.
# The bare minimum of a Meson project, consisting of a single source file `hello.c'
# whose name suggests that it prints `Hello, world!' on screen. When the project is
# built, it generates a build artifact named `hello' in the builddir.
project('hello-world', 'c', version : '1.0.0')
executable('hello', 'hello.c')To build and run the following steps are taken.
$ meson setup builddir
$ meson compile -C builddir
$ ./builddir/hello
Hello, world!