[libgweather/ebassi/gtk4] build: Add option to disable introspection



commit 6d5f9b7e54dac65cdc4fcab328ef2e27aedb15d6
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Oct 12 12:44:19 2021 +0100

    build: Add option to disable introspection
    
    When building libgweather as a subproject or as a Flatpak module we may
    want to disable generating the introspection data if we know we're only
    ever going to consume the C API.
    
    Disabling introspection will disable the documentation and the VAPI file
    generation as a side effect.

 doc/meson.build         |  2 +-
 libgweather/meson.build | 53 +++++++++++++++++++++++++++++++------------------
 meson.build             | 10 ++--------
 meson_options.txt       |  2 ++
 4 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/doc/meson.build b/doc/meson.build
index 6a98ba80..7e18715b 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -1,4 +1,4 @@
-if get_option('gtk_doc')
+if get_option('gtk_doc') and get_option('introspection')
   dependency('gi-docgen', version: '>= 2021.6',
     fallback: ['gi-docgen', 'dummy_dep'],
   )
diff --git a/libgweather/meson.build b/libgweather/meson.build
index 68518676..a534bfd6 100644
--- a/libgweather/meson.build
+++ b/libgweather/meson.build
@@ -176,24 +176,39 @@ lib_libgweather = shared_library('gweather-3',
   install: true,
 )
 
-gweather_gir = gnome.generate_gir(lib_libgweather,
-  sources: introspection_sources,
-  dependencies: deps_libgweather,
-  nsversion: '3.0',
-  namespace: 'GWeather',
-  includes: ['GObject-2.0', 'Gtk-3.0'],
-  symbol_prefix: 'gweather',
-  identifier_prefix: 'GWeather',
-  export_packages: 'gweather-3.0',
-  header: 'libgweather/gweather.h',
-  extra_args: [
-    '--warn-all',
-    '--quiet',
-    '-DGWEATHER_COMPILATION',
-  ],
-  fatal_warnings: get_option('werror'),
-  install: true,
-)
+g_ir_scanner = find_program('g-ir-scanner', required: get_option('introspection'))
+build_gir = get_option('introspection') and g_ir_scanner.found() and not meson.is_cross_build()
+
+enable_vala = get_option('enable_vala')
+vapigen = find_program('vapigen', required: enable_vala == 'true')
+if enable_vala == 'auto' or enable_vala == 'true'
+  build_vapi = vapigen.found() and get_option('introspection')
+else
+  build_vapi = false
+endif
+
+if build_gir
+  gweather_gir = gnome.generate_gir(lib_libgweather,
+    sources: introspection_sources,
+    dependencies: deps_libgweather,
+    nsversion: '3.0',
+    namespace: 'GWeather',
+    includes: ['GObject-2.0', 'Gtk-3.0'],
+    symbol_prefix: 'gweather',
+    identifier_prefix: 'GWeather',
+    export_packages: 'gweather-3.0',
+    header: 'libgweather/gweather.h',
+    extra_args: [
+      '--warn-all',
+      '--quiet',
+      '-DGWEATHER_COMPILATION',
+    ],
+    fatal_warnings: get_option('werror'),
+    install: true,
+  )
+else
+  gweather_gir = []
+endif
 
 libgweather_dep = declare_dependency(
   sources: [gweather_enum_types[1], gweather_gir],
@@ -204,7 +219,7 @@ libgweather_dep = declare_dependency(
   ],
 )
 
-if enable_vala
+if build_vapi and build_gir
   gnome.generate_vapi('gweather-3.0',
     sources: gweather_gir[0],
     packages: ['gobject-2.0', 'gtk+-3.0'],
diff --git a/meson.build b/meson.build
index eca7b9d2..136dcdc4 100644
--- a/meson.build
+++ b/meson.build
@@ -65,13 +65,6 @@ else
   endif
 endif
 
-enable_vala = get_option('enable_vala')
-if enable_vala == 'auto'
-  enable_vala = find_program('vapigen', required: false).found()
-else
-  enable_vala = enable_vala != 'false'
-endif
-
 gen_locations_variant = find_program('build-aux/meson/gen_locations_variant.py')
 
 subdir('data')
@@ -114,7 +107,8 @@ summary({
     'Debug': get_option('debug'),
     'Optimization': get_option('optimization'),
     'Glade catalog': enable_glade_catalog,
-    'Generate VAPI': enable_vala,
+    'Introspection': build_gir,
+    'Generate VAPI': build_vapi,
     'API reference': get_option('gtk_doc'),
   },
   section: 'Build',
diff --git a/meson_options.txt b/meson_options.txt
index 19b2c6a7..5385be0b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -8,3 +8,5 @@ option('enable_vala', type: 'combo', choices : ['true', 'false', 'auto'], value
        description: 'Install vala bindings')
 option('gtk_doc', type: 'boolean', value: false,
        description: 'Whether to generate the API reference')
+option('introspection', type: 'boolean', value: true,
+       description: 'Whether to generate introspection data')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]