From bbc666a1d239f6d5bba66df3fdd10a7eb261dc03 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Tue, 6 Apr 2021 17:57:31 +0200 Subject: meson: added variants, changed defaults for the build system (#22715) - Use debugoptimized as default build type, just like RelWithDebInfo for cmake - Do not strip by default, and add a default_library variant which conveniently support both shared and static --- lib/spack/docs/build_systems/mesonpackage.rst | 6 +++++- lib/spack/spack/build_systems/meson.py | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/spack/docs/build_systems/mesonpackage.rst b/lib/spack/docs/build_systems/mesonpackage.rst index 652a10db92..a7dd7a76fb 100644 --- a/lib/spack/docs/build_systems/mesonpackage.rst +++ b/lib/spack/docs/build_systems/mesonpackage.rst @@ -121,11 +121,15 @@ override the ``meson_args`` method like so: .. code-block:: python def meson_args(self): - return ['--default-library=both'] + return ['--warnlevel=3'] This method can be used to pass flags as well as variables. +Note that the ``MesonPackage`` base class already defines variants for +``buildtype``, ``default_library`` and ``strip``, which are mapped to default +Meson arguments, meaning that you don't have to specify these. + ^^^^^^^^^^^^^^^^^^^^^^ External documentation ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/lib/spack/spack/build_systems/meson.py b/lib/spack/spack/build_systems/meson.py index 33ed756786..8f9972ba2e 100644 --- a/lib/spack/spack/build_systems/meson.py +++ b/lib/spack/spack/build_systems/meson.py @@ -52,9 +52,13 @@ class MesonPackage(PackageBase): build_time_test_callbacks = ['check'] - variant('buildtype', default='release', + variant('buildtype', default='debugoptimized', description='Meson build type', values=('plain', 'debug', 'debugoptimized', 'release', 'minsize')) + variant('default_library', default='shared', + description=' Default library type', + values=('shared', 'static', 'both')) + variant('strip', default=False, description='Strip targets on install') depends_on('meson', type='build') depends_on('ninja', type='build') @@ -96,6 +100,13 @@ class MesonPackage(PackageBase): except KeyError: build_type = 'release' + strip = 'true' if '+strip' in pkg.spec else 'false' + + try: + default_library = pkg.spec.variants['default_library'].value + except KeyError: + default_library = 'shared' + args = [ '--prefix={0}'.format(pkg.prefix), # If we do not specify libdir explicitly, Meson chooses something @@ -103,8 +114,9 @@ class MesonPackage(PackageBase): # find libraries and pkg-config files. # See https://github.com/mesonbuild/meson/issues/2197 '--libdir={0}'.format(pkg.prefix.lib), - '--buildtype={0}'.format(build_type), - '--strip', + '-Dbuildtype={0}'.format(build_type), + '-Dstrip={0}'.format(strip), + '-Ddefault_library={0}'.format(default_library) ] return args @@ -131,6 +143,7 @@ class MesonPackage(PackageBase): * ``--libdir`` * ``--buildtype`` * ``--strip`` + * ``--default_library`` which will be set automatically. -- cgit v1.2.3-70-g09d2