Using peel with Meson
Many projects in the GLib and GNOME ecosystem are built with Meson. peel itself is built with Meson as well, and provides some integration to make it easier to use peel in Meson projects.
Start by looking up the peel dependency:
# meson.build
peel = dependency('peel')
The dependency can be installed system-wide, or provided by a subproject,
perhaps coming from a wrap file. Specifically, to make peel just work as a
wrap-based subproject, place the following into subprojects/peel.wrap:
[wrap-git]
url=https://gitlab.gnome.org/bugaevc/peel.git
revision=HEAD
depth=1
[provide]
program_names=peel-gen
Meson famously doesn’t allow build scripts to define custom functions1, which is why it’s not possible for peel to provide the same level of automation for Meson as it does for CMake, particularly around code generation.
So to generate the bindings, we have to find the peel-gen program and define
a custom target manually:
peel_gen = find_program('peel-gen')
peel_gtk = custom_target('peel-codegen',
command: [
peel_gen,
'--recursive',
'--out-dir', '@OUTDIR@',
'Gtk', '4.0',
],
output: 'peel',
)
output: 'peel' here refers to the fact that the peel-gen invocation
generates a peel/ directory.
You can then use the generated bindings as sources in your target, while
passing the peel dependency object as a dependency:
gtk = dependency('gtk4')
executable('example',
'example.cpp',
peel_gtk,
dependencies: [gtk, peel],
)
Note that including the generated bindings as sources into your target does not, by itself, cause your target to depend on the actual library you’re generating bindings for; you still need to do that yourself.
A complete example:
project('example', 'cpp')
gtk = dependency('gtk4')
peel = dependency('peel')
peel_gen = find_program('peel-gen')
peel_gtk = custom_target('peel-codegen',
command: [
peel_gen,
'--recursive',
'--out-dir', '@OUTDIR@',
'Gtk', '4.0',
],
output: 'peel',
)
executable('example',
'example.cpp',
peel_gtk,
dependencies: [gtk, peel],
)