openSUSE:Packaging Meson
Meson build system
Meson is a modern build system focused on speed and ease of use. It is commonly used in conjunction with the Ninja backend.
Packaging software using Meson in openSUSE follows similar conventions as other build systems, with a few Meson-specific considerations.
Build Dependencies
You must add
BuildRequires: meson
RPM macros
The Meson Build system is shipped in openSUSE and provides rpm macros in /usr/lib/rpm/macros.d/macros.meson
.
%meson
- Defines
CFLAGS
,LDFLAGS
, etc. and calls%__meson
with appropriate parameters (--libdir=%{_libdir}
and such). You can pass-Doption=value
to this macro in order to set options for the buildsystem. %meson_build
- Calls
meson compiles
with the right-C
and-j
arguments. %meson_install
- An alias for
DESTDIR=%{buildroot} meson install -C ...
%meson_test
- An alias for
meson test -C ...
%__meson
- Direct use of this macro is not encouraged! Path of the
meson
executable.
Subprojects
If your project includes Meson subprojects that are not replaceable (cannot link with system provided libraries) you should:
+ Ask upstream to allow linking to system libraries + If not applicable, manually manage wraps.
Add the required projects to your SourceX
section:
... Source0: <PROJECT_SOURCE_TARBALL> Source1: <WRAP_1_SOURCE_TARBALL> ...
In your `.spec` file, refer to the subproject archive using a `SourceX` tag and extract it in the `%prep` phase like this:
%prep ... # Extract symfpu mkdir -p subprojects/<SUBPROJECT_NAME> tar -C subprojects/<SUBPROJECT_NAME> --strip-components=1 -x -f %{SOURCE1}
Then, modify the %build section to make meson apply patches before building:
%build meson subprojects packagefiles --apply ...
Example RPM spec
Name: example
Version: 2.31.1
Release: 0
Summary: Example summary
License: CHANGE-ME
URL: https://example.com
Source: %{name}-{version}.tar.gz
BuildRequires: meson
BuildRequires: gcc
%package devel
Summary: Development libraries and header files for %{name}
Requires: %{name} = %{version}
%description devel
%{summary}.
%prep
%autosetup
%build
%meson
%meson_build
%install
%meson_install
%check
%meson_test
%files
%{_libdir}/lib%{name}.so.*
%files devel
%{_libdir}/lib%{name}.so
%{_includedir}/%{name}.h