From c1924cf87c0f4c74ad768af174424bc559244182 Mon Sep 17 00:00:00 2001
From: Adrien Plazas <kekun.plazas@laposte.net>
Date: Thu, 10 Jan 2019 14:04:12 +0100
Subject: [PATCH] meson: Make introspection and the Glade catalog features

This avoids having to disable them when their dependencies aren't
available and it will allow to disable them properly when libhandy will
be allowed to be built as a static library in the next commit.
---
 examples/sm.puri.Handy.Example.json |  4 ++--
 glade/meson.build                   |  3 +--
 meson.build                         | 11 +++++++++--
 meson_options.txt                   |  4 ++--
 src/meson.build                     |  2 +-
 5 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/examples/sm.puri.Handy.Example.json b/examples/sm.puri.Handy.Example.json
index 0d1fabd4..c535dccb 100644
--- a/examples/sm.puri.Handy.Example.json
+++ b/examples/sm.puri.Handy.Example.json
@@ -24,8 +24,8 @@
       "builddir": true,
       "build-options": "examples",
       "config-opts": [
-        "-Dglade_catalog=false",
-        "-Dintrospection=false",
+        "-Dglade_catalog=disabled",
+        "-Dintrospection=disabled",
         "-Dtests=false",
         "-Dvapi=false"
       ],
diff --git a/glade/meson.build b/glade/meson.build
index b5d690bc..5351d7b5 100644
--- a/glade/meson.build
+++ b/glade/meson.build
@@ -1,7 +1,6 @@
-if get_option('glade_catalog')
+if glade_catalog
 
 glade_xml = 'libhandy.xml'
-gladeui_dep = dependency('gladeui-2.0')
 module_dir = gladeui_dep.get_pkgconfig_variable('moduledir')
 dtd = join_paths(meson.current_source_dir(), 'glade-catalog.dtd')
 glade_catalogdir = gladeui_dep.get_pkgconfig_variable('catalogdir')
diff --git a/meson.build b/meson.build
index 1edc8ec1..fc1c9424 100644
--- a/meson.build
+++ b/meson.build
@@ -118,6 +118,13 @@ else
   vapidir = join_paths(get_option('datadir'), 'vala', 'vapi')
 endif
 
+glade_catalog_feature = get_option('glade_catalog')
+gladeui_dep = dependency('gladeui-2.0', required : glade_catalog_feature)
+glade_catalog = gladeui_dep.found()
+
+introspection_feature = get_option('introspection')
+introspection = introspection_feature.enabled() or introspection_feature.auto()
+
 gnome = import('gnome')
 
 subdir('src')
@@ -143,9 +150,9 @@ summary = [
   '             Tests: @0@'.format(get_option('tests')),
   '          Examples: @0@'.format(get_option('examples')),
   '     Documentation: @0@'.format(get_option('gtk_doc')),
-  '     Introspection: @0@'.format(get_option('introspection')),
+  '     Introspection: @0@'.format(introspection),
   '              Vapi: @0@'.format(get_option('vapi')),
-  '     Glade Catalog: @0@'.format(get_option('glade_catalog')),
+  '     Glade Catalog: @0@'.format(glade_catalog),
  '------',
   ''
 ]
diff --git a/meson_options.txt b/meson_options.txt
index 712771d2..f0e09813 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,7 +1,7 @@
 # Performance and debugging related options
 option('profiling', type: 'boolean', value: false)
 
-option('introspection', type: 'boolean', value: true)
+option('introspection', type: 'feature', value: 'auto')
 option('vapi', type: 'boolean', value: true)
 
 # Subproject
@@ -21,5 +21,5 @@ option('examples',
        type: 'boolean', value: true,
        description: 'Whether to compile unit tests')
 
-option('glade_catalog', type: 'boolean', value: true,
+option('glade_catalog', type: 'feature', value: 'auto',
        description: 'Install a glade catalog file')
diff --git a/src/meson.build b/src/meson.build
index 1ec9ad43..d9d1c313 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -156,7 +156,7 @@ libhandy_dep = declare_dependency(
   include_directories: include_directories('.'),
 )
 
-if get_option('introspection')
+if introspection
 
    libhandy_gir = gnome.generate_gir(libhandy,
                  sources: libhandy_generated_headers + libhandy_public_headers + libhandy_public_sources,
-- 
GitLab