Much like Autotools and CMake, Meson is a build system. But it is meant to be both fast and as user friendly as possible. GNOME’s goal is to port modules to use the Meson build system.
MesonPackage base class comes with the following phases:
meson- generate ninja files
build- build the project
install- install the project
By default, these phases run:
$ mkdir spack-build $ cd spack-build $ meson .. --prefix=/path/to/installation/prefix $ ninja $ ninja test # optional $ ninja install
Any of these phases can be overridden in your package as necessary.
There is also a
check method that looks for a
in the build file. If a
test target exists and the user runs:
$ spack install --test=root <meson-package>
Spack will run
ninja test after the build phase.
Packages that use the Meson build system can be identified by the
presence of a
meson.build file. This file declares things
like build instructions and dependencies.
One thing to look for is the
meson_version key that gets passed
project('gtk+', 'c', version: '3.94.0', default_options: [ 'buildtype=debugoptimized', 'warning_level=1', # We only need c99, but glib needs GNU-specific features # https://github.com/mesonbuild/meson/issues/2289 'c_std=gnu99', ], meson_version: '>= 0.43.0', license: 'LGPLv2.1+')
This means that Meson 0.43.0 is the earliest release that will work.
You should specify this in a
Build system dependencies¶
At the bare minimum, packages that use the Meson build system need
`ninja` dependencies. Since this is always the case,
MesonPackage base class already contains:
depends_on('meson', type='build') depends_on('ninja', type='build')
If you need to specify a particular version requirement, you can override this in your package:
depends_on('firstname.lastname@example.org:', type='build') depends_on('ninja', type='build')
Finding meson flags¶
To get a list of valid flags that can be passed to
meson, run the
following command in the directory that contains
$ meson setup --help
Passing arguments to meson¶
If you need to pass any arguments to the
meson call, you can
meson_args method like so:
def meson_args(self): return ['--default-library=both']
This method can be used to pass flags as well as variables.