From 02edc4e8d4b34adc44c536b37caeaebdf453990f Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Mon, 5 Aug 2019 18:55:38 +0200 Subject: [PATCH] Add GObject Introspection support to babl This is needed for GIMP to also have proper GIR support for its plugins. Extra thanks go to Emmanuele Bassi for the identity filter. --- babl/identfilter.py | 37 +++++++++++++++++++++++++++++++++++++ babl/meson.build | 18 ++++++++++++++++++ meson.build | 1 + meson_options.txt | 1 + 4 files changed, 57 insertions(+) create mode 100644 babl/identfilter.py diff --git a/babl/identfilter.py b/babl/identfilter.py new file mode 100644 index 0000000..e592de4 --- /dev/null +++ b/babl/identfilter.py @@ -0,0 +1,37 @@ +# Copyright 2014 Emmanuele Bassi +# +# SPDX-License-Identifier: MIT +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import sys +import re + +def rename_babl_object(text): + # We need this to rename the Babl type into BablObject + # Otherwise the type clashes with the namespace + if text == 'Babl': + return 'BablObject' + + # Leave the rest unharmed + return text + +if __name__ == '__main__': + in_text = sys.stdin.read() + sys.stdout.write(rename_babl_object(in_text)) diff --git a/babl/meson.build b/babl/meson.build index c57bc93..3d86860 100644 --- a/babl/meson.build +++ b/babl/meson.build @@ -133,3 +133,21 @@ babl = library( version: so_version, install: true, ) + +if get_option('enable-gir') + # identity filter, so GIR doesn't choke on the Babl type + # (since it has the same name as the Babl namespace) + identfilter_py = join_paths(meson.current_source_dir(), 'identfilter.py') + + babl_gir = gnome.generate_gir(babl, + sources: babl_headers, + extra_args: [ + '--identifier-filter-cmd=@0@ @1@'.format(python.path(), identfilter_py), + '-DBABL_IS_BEING_COMPILED', + ], + namespace: 'Babl', + nsversion: '1', + header: 'babl.h', + install: true, + ) +endif diff --git a/meson.build b/meson.build index d0a1f9f..e2a2064 100644 --- a/meson.build +++ b/meson.build @@ -25,6 +25,7 @@ conf = configuration_data() pkgconfig = import('pkgconfig') i18n = import('i18n') gnome = import('gnome') +python = import('python') cc = meson.get_compiler('c') prefix = get_option('prefix') diff --git a/meson_options.txt b/meson_options.txt index f4a7ced..eca27be 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -5,5 +5,6 @@ option('enable-sse3', type: 'boolean', value: true, description: 'enable SSE3 option('enable-sse4_1', type: 'boolean', value: true, description: 'enable SSE4.1 support') option('enable-avx2', type: 'boolean', value: true, description: 'enable AVX2 support') option('enable-f16c', type: 'boolean', value: true, description: 'enable hardware half-float support') +option('enable-gir', type: 'boolean', value: true, description: 'enable GObject-Introspection (GIR)') option('with-docs', type: 'boolean', value: true, description: 'build website') option('with-lcms', type: 'boolean', value: true, description: 'build with lcms') -- 2.30.2