From 4a871138376db934fd4bf9aeb0359148b8ea1277 Mon Sep 17 00:00:00 2001
From: Mart Raudsepp <leio@gentoo.org>
Date: Sun, 12 Jul 2020 12:38:19 +0300
Subject: [PATCH 4/6] build: Make printers panel (cups) optional

As a side-effect smbclient is also optional, as it's only required
by the printers panel.
---
 meson.build             | 13 ++++++++++---
 meson_options.txt       |  1 +
 panels/meson.build      |  5 ++++-
 shell/cc-panel-loader.c |  4 ++++
 tests/meson.build       |  4 +++-
 5 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index db6a7d97e..818bd67e2 100644
--- a/meson.build
+++ b/meson.build
@@ -153,9 +153,11 @@ common_deps = [
 ]
 
 # Check for CUPS 1.4 or newer
-cups_dep = dependency('cups', version : '>= 1.4', required: false)
-assert(cups_dep.found(), 'CUPS 1.4 or newer not found')
+cups_dep = dependency('cups', version : '>= 1.4', required: get_option('cups'))
+enable_cups = cups_dep.found()
+have_cups_httpconnect2 = false
 
+if enable_cups
 # https://bugzilla.gnome.org/show_bug.cgi?id=696766
 cups_cflags = []
 if cups_dep.version().version_compare('>= 1.6')
@@ -172,8 +174,13 @@ foreach header: check_headers
   assert(cc.has_header(header[1], args: cups_cflags), 'CUPS headers not found: ' + header[1])
 endforeach
 
+have_cups_httpconnect2 = cc.has_function('httpConnect2', dependencies: cups_dep)
+endif
+
+config_h.set('BUILD_PRINTERS', enable_cups,
+             description: 'Define to 1 to build the Printers panel')
 config_h.set10('HAVE_CUPS_HTTPCONNECT2',
-               cc.has_function('httpConnect2', dependencies: cups_dep),
+               have_cups_httpconnect2,
                description: 'Define if httpConnect2() is available in CUPS')
 
 # Optional dependency for the user accounts panel
diff --git a/meson_options.txt b/meson_options.txt
index 90f9045c2..c656f4cff 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,5 +1,6 @@
 option('bluetooth', type: 'boolean', value: true, description: 'build with Bluetooth support')
 option('cheese', type: 'boolean', value: true, description: 'build with cheese webcam support')
+option('cups', type: 'feature', value: 'auto', description: 'build with CUPS support (printer panel)')
 option('documentation', type: 'boolean', value: false, description: 'build documentation')
 option('goa', type: 'feature', value: 'auto', description: 'build with gnome-online-accounts support')
 option('ibus', type: 'boolean', value: true, description: 'build with IBus support')
diff --git a/panels/meson.build b/panels/meson.build
index e04f5e2c9..c10ef5128 100644
--- a/panels/meson.build
+++ b/panels/meson.build
@@ -17,7 +17,6 @@ panels = [
   'multitasking',
   'notifications',
   'power',
-  'printers',
   'region',
   'removable-media',
   'sharing',
@@ -28,6 +27,10 @@ panels = [
   'user-accounts',
 ]
 
+if enable_cups
+  panels += ['printers']
+endif
+
 if enable_network_manager
   panels += ['network', 'wwan']
 endif
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index 4819f98ad..d540acceb 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -53,7 +53,9 @@ extern GType cc_notifications_panel_get_type (void);
 extern GType cc_goa_panel_get_type (void);
 #endif /* BUILD_GOA */
 extern GType cc_power_panel_get_type (void);
+#ifdef BUILD_PRINTERS
 extern GType cc_printers_panel_get_type (void);
+#endif /* BUILD_PRINTERS */
 extern GType cc_region_panel_get_type (void);
 extern GType cc_removable_media_panel_get_type (void);
 extern GType cc_search_panel_get_type (void);
@@ -126,7 +128,9 @@ static CcPanelLoaderVtable default_panels[] =
   PANEL_TYPE("online-accounts",  cc_goa_panel_get_type,                  NULL),
 #endif
   PANEL_TYPE("power",            cc_power_panel_get_type,                NULL),
+#ifdef BUILD_PRINTERS
   PANEL_TYPE("printers",         cc_printers_panel_get_type,             NULL),
+#endif
   PANEL_TYPE("region",           cc_region_panel_get_type,               NULL),
   PANEL_TYPE("removable-media",  cc_removable_media_panel_get_type,      NULL),
   PANEL_TYPE("search",           cc_search_panel_get_type,               NULL),
-- 
2.32.0

