[libnma] build: add support for gcr-4



commit 0c2df25747a56cf919c17bf1707af808b4f29e5d
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Thu Jul 21 18:39:51 2022 +0200

    build: add support for gcr-4
    
    The gcr-3.90 development release finally ships with gtk3 and gtk4 support
    and has been imported into Fedora 37. Good.
    
    The new libraries available are: gcr-4-gtk3 and gcr-4-gtk4 for the GUI
    part, replacing gcr-3 as well as new version of gck: gck-2 superseding
    gck-1.
    
    https://gitlab.gnome.org/GNOME/libnma/-/merge_requests/35

 Makefile.am                   |   8 +--
 config.h.meson                |   2 +-
 configure.ac                  | 135 +++++++++++++++++++++---------------------
 meson.build                   |  58 +++++++++---------
 src/nma-cert-chooser-button.c |   4 +-
 5 files changed, 103 insertions(+), 104 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index eb8ca065..ceb42230 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -269,7 +269,7 @@ src_libnma_la_SOURCES = \
        $(libnma_h_priv_real) \
        $(libnma_c_real)
 
-if WITH_GCR
+if WITH_GCR_GTK3
 src_libnma_la_SOURCES += \
        $(libnma_h_priv_gcr) \
        $(libnma_c_gcr)
@@ -296,13 +296,13 @@ src_libnma_la_CFLAGS = \
        -Isrc \
        $(GTK3_CFLAGS) \
        $(LIBNM_CFLAGS) \
-       $(GCR_CFLAGS)
+       $(GCR_GTK3_CFLAGS)
 
 src_libnma_la_LIBADD = \
        src/utils/libutils-libnm.la \
        $(GTK3_LIBS) \
        $(LIBNM_LIBS) \
-       $(GCR_LIBS)
+       $(GCR_GTK3_LIBS)
 
 EXTRA_src_libnma_la_DEPENDENCIES = src/libnma.ver
 
@@ -322,7 +322,7 @@ src_NMA_1_0_gir_LIBS = src/libnma.la
 src_NMA_1_0_gir_FILES = \
        $(libnma_h_pub) \
        $(libnma_c_real)
-if WITH_GCR
+if WITH_GCR_GTK3
 src_NMA_1_0_gir_FILES += \
        $(libnma_c_gcr)
 endif
diff --git a/config.h.meson b/config.h.meson
index fe21f55b..b56cd0b3 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -39,7 +39,7 @@
 #mesondefine VERSION
 
 /* Define if Gcr is available */
-#mesondefine WITH_GCR
+#mesondefine WITH_GCR_GTK3
 
 /* Define if GTK4 Gcr is available */
 #mesondefine WITH_GCR_GTK4
diff --git a/configure.ac b/configure.ac
index 0059059a..512bf317 100644
--- a/configure.ac
+++ b/configure.ac
@@ -143,62 +143,70 @@ else
 fi
 AM_CONDITIONAL(WITH_LIBNMA_GTK4, test "$with_libnma_gtk4" != "no")
 
-dnl GCR API is declared subject to change, do an extensive check of the prototypes
-AC_DEFUN([CHECK_GCR_API], [
+# Probe if a particular variant of GCR is good enough for us
+AC_DEFUN([CHECK_GCR], [
+    PKG_CHECK_MODULES([$1], [$2], [
+       [$1]_CFLAGS="$[$1]_CFLAGS -DGCR_API_SUBJECT_TO_CHANGE -DGCK_API_SUBJECT_TO_CHANGE"
+
+        dnl GCR API is declared subject to change, do an extensive check of the prototypes
         CFLAGS_SAVED="$CFLAGS"
-        CFLAGS="$CFLAGS $2"
+        CFLAGS="$CFLAGS $[$1]_CFLAGS"
         AC_MSG_CHECKING([for $1 usefulness])
         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
-                          #include <gcr/gcr.h>
-                          #include <gck/gck.h>
-
-                          const GckAttribute *gck_attributes_find (GckAttributes *attrs, gulong attr_type);
-                          gboolean gck_attributes_find_string (GckAttributes *attrs, gulong attr_type, gchar 
**value);
-                          gboolean gck_attributes_find_ulong (GckAttributes *attrs, gulong attr_type, gulong 
*value);
-                          GckAttributes *gck_attributes_new_empty (gulong first_type, ...);
-                          void gck_attributes_unref (gpointer attrs);
-                          void gck_builder_add_all (GckBuilder *builder, GckAttributes *attrs);
-                          void gck_builder_add_only (GckBuilder *builder, GckAttributes *attrs, gulong 
only_type, ...);
-                          GckAttributes *gck_builder_end (GckBuilder *builder);
-                          GckBuilder *gck_builder_new (GckBuilderFlags flags);
-                          void gck_enumerator_next_async (GckEnumerator *self, gint max_objects, 
GCancellable *cancellable,
-                                                          GAsyncReadyCallback callback, gpointer user_data);
-                          GList *gck_enumerator_next_finish (GckEnumerator *self, GAsyncResult *result, 
GError **error);
-                          void gck_list_unref_free (GList *reflist);
-                          GList *gck_modules_get_slots (GList *modules, gboolean token_present);
-                          void gck_modules_initialize_registered_async (GCancellable *cancellable, 
GAsyncReadyCallback callback,
-                                                                        gpointer user_data);
-                          GList *gck_modules_initialize_registered_finish (GAsyncResult *result, GError 
**error);
-                          void gck_object_get_async (GckObject *self, const gulong *attr_types, guint 
n_attr_types,
-                                                     GCancellable *cancellable, GAsyncReadyCallback 
callback, gpointer user_data);
-                          GckAttributes *gck_object_get_finish (GckObject *self, GAsyncResult *result, 
GError **error);
-                          void gck_session_login_async (GckSession *self, gulong user_type, const guchar 
*pin,
-                                                        gsize n_pin, GCancellable *cancellable,
-                                                        GAsyncReadyCallback callback, gpointer user_data);
-                          gboolean gck_session_login_finish (GckSession *self, GAsyncResult *result, GError 
**error);
-                          GckSlotInfo *gck_slot_get_info (GckSlot *self);
-                          GckTokenInfo *gck_slot_get_token_info (GckSlot *self);
-                          #if GCR_CHECK_VERSION(3,90,0)
-                          void gck_slot_open_session_async (GckSlot *self, GckSessionOptions options, 
GTlsInteraction *interaction,
-                                                            GCancellable *cancellable, GAsyncReadyCallback 
callback,
+              #include <gcr/gcr.h>
+              #include <gck/gck.h>
+
+              const GckAttribute *gck_attributes_find (GckAttributes *attrs, gulong attr_type);
+              gboolean gck_attributes_find_string (GckAttributes *attrs, gulong attr_type, gchar **value);
+              gboolean gck_attributes_find_ulong (GckAttributes *attrs, gulong attr_type, gulong *value);
+              GckAttributes *gck_attributes_new_empty (gulong first_type, ...);
+              void gck_attributes_unref (gpointer attrs);
+              void gck_builder_add_all (GckBuilder *builder, GckAttributes *attrs);
+              void gck_builder_add_only (GckBuilder *builder, GckAttributes *attrs, gulong only_type, ...);
+              GckAttributes *gck_builder_end (GckBuilder *builder);
+              GckBuilder *gck_builder_new (GckBuilderFlags flags);
+              void gck_enumerator_next_async (GckEnumerator *self, gint max_objects, GCancellable 
*cancellable,
+                                              GAsyncReadyCallback callback, gpointer user_data);
+              GList *gck_enumerator_next_finish (GckEnumerator *self, GAsyncResult *result, GError **error);
+              void gck_list_unref_free (GList *reflist);
+              GList *gck_modules_get_slots (GList *modules, gboolean token_present);
+              void gck_modules_initialize_registered_async (GCancellable *cancellable, GAsyncReadyCallback 
callback,
                                                             gpointer user_data);
-                          gchar *gck_uri_data_build (GckUriData *uri_data, GckUriFlags flags);
-                          GckUriData *gck_uri_data_parse (const gchar *string, GckUriFlags flags, GError 
**error);
-                          #else
-                          void gck_slot_open_session_async (GckSlot *self, GckSessionOptions options, 
GCancellable *cancellable,
-                                                            GAsyncReadyCallback callback, gpointer 
user_data);
-                          gchar *gck_uri_build (GckUriData *uri_data, GckUriFlags flags);
-                          GckUriData *gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error);
-                          #endif
-                          GckSession *gck_slot_open_session_finish (GckSlot *self, GAsyncResult *result, 
GError **error);
-                          void gck_token_info_free (GckTokenInfo *token_info);
-                          void gck_uri_data_free (GckUriData *uri_data);
-                          gchar *gcr_certificate_get_issuer_name (GcrCertificate *self);
-                          gchar *gcr_certificate_get_subject_name (GcrCertificate *self);
-                          GcrCertificate *gcr_simple_certificate_new (const guchar *data, gsize n_data);
-                          ])], [$3], [$4])
-        AC_MSG_RESULT(${have_gcr})
+              GList *gck_modules_initialize_registered_finish (GAsyncResult *result, GError **error);
+              void gck_object_get_async (GckObject *self, const gulong *attr_types, guint n_attr_types,
+                                         GCancellable *cancellable, GAsyncReadyCallback callback, gpointer 
user_data);
+              GckAttributes *gck_object_get_finish (GckObject *self, GAsyncResult *result, GError **error);
+              void gck_session_login_async (GckSession *self, gulong user_type, const guchar *pin,
+                                            gsize n_pin, GCancellable *cancellable,
+                                            GAsyncReadyCallback callback, gpointer user_data);
+              gboolean gck_session_login_finish (GckSession *self, GAsyncResult *result, GError **error);
+              GckSlotInfo *gck_slot_get_info (GckSlot *self);
+              GckTokenInfo *gck_slot_get_token_info (GckSlot *self);
+              #if GCR_CHECK_VERSION(3,90,0)
+              void gck_slot_open_session_async (GckSlot *self, GckSessionOptions options, GTlsInteraction 
*interaction,
+                                                GCancellable *cancellable, GAsyncReadyCallback callback,
+                                                gpointer user_data);
+              gchar *gck_uri_data_build (GckUriData *uri_data, GckUriFlags flags);
+              GckUriData *gck_uri_data_parse (const gchar *string, GckUriFlags flags, GError **error);
+              #else
+              void gck_slot_open_session_async (GckSlot *self, GckSessionOptions options, GCancellable 
*cancellable,
+                                                GAsyncReadyCallback callback, gpointer user_data);
+              gchar *gck_uri_build (GckUriData *uri_data, GckUriFlags flags);
+              GckUriData *gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error);
+              #endif
+              GckSession *gck_slot_open_session_finish (GckSlot *self, GAsyncResult *result, GError **error);
+              void gck_token_info_free (GckTokenInfo *token_info);
+              void gck_uri_data_free (GckUriData *uri_data);
+              gchar *gcr_certificate_get_issuer_name (GcrCertificate *self);
+              gchar *gcr_certificate_get_subject_name (GcrCertificate *self);
+              GcrCertificate *gcr_simple_certificate_new (const guchar *data, gsize n_data);
+              ])],
+              AC_MSG_RESULT(good)
+              [$3],
+              AC_MSG_RESULT(bad)
+              [$4])
         CFLAGS="$CFLAGS_SAVED"
+    ], [$4])
 ])
 
 dnl GCR for PKCS#11 enabled certificate chooser
@@ -206,22 +214,19 @@ AC_ARG_WITH(gcr, AS_HELP_STRING([--with-gcr], [Enable advanced certificate choos
 if (test "${with_gcr}" == "no"); then
     have_gcr=no
 else
-    PKG_CHECK_MODULES(GCR,
-                      [gcr-3 >= 3.14, gck-1 >= 3.14],
-                      [GCR_CFLAGS="$GCR_CFLAGS -DGCR_API_SUBJECT_TO_CHANGE -DGCK_API_SUBJECT_TO_CHANGE"
-                       CHECK_GCR_API(GCR, $GCR_CFLAGS, have_gcr=yes, have_gcr=no)],
-                      [have_gcr=no])
+    CHECK_GCR(GCR_GTK3, [gcr-4-gtk3 >= 3.90], have_gcr=yes,
+        [CHECK_GCR(GCR_GTK3, [gcr-3 >= 3.14, gck-1 >= 3.14], have_gcr=yes, have_gcr=no)])
 fi
 
 if (test "${have_gcr}" == "yes"); then
-     AC_DEFINE(WITH_GCR, 1, [Define if Gcr is available])
+     AC_DEFINE(WITH_GCR_GTK3, 1, [Define if Gcr is available for Gtk3])
 else
     if (test "${with_gcr}" == "yes"); then
         AC_MSG_ERROR([gcr support was requested, but the gcr library is not available.])
     fi
-    AC_DEFINE(WITH_GCR, 0, [Define if Gcr is available])
+    AC_DEFINE(WITH_GCR_GTK3, 0, [Define if Gcr is available for Gtk3])
 fi
-AM_CONDITIONAL(WITH_GCR, test "${have_gcr}" == "yes")
+AM_CONDITIONAL(WITH_GCR_GTK3, test "${have_gcr}" == "yes")
 
 dnl GCR for PKCS#11 enabled certificate chooser with Gtk4
 AC_ARG_WITH(gcr_gtk4, AS_HELP_STRING([--with-gcr-gtk4], [Enable EXPERIMENTAL advanced certificate chooser 
for Gtk4 (default: auto)]))
@@ -229,11 +234,7 @@ if (test "$with_libnma_gtk4" = "yes"); then
     if (test "${with_gcr_gtk4}" = "no"); then
         have_gcr_gtk4=no
     else
-        PKG_CHECK_MODULES(GCR_GTK4,
-                          [gcr-gtk4-3 >= 3.90, gck-1 >= 3.90],
-                          [GCR_GTK4_CFLAGS="$GCR_GTK4_CFLAGS -DGCR_API_SUBJECT_TO_CHANGE 
-DGCK_API_SUBJECT_TO_CHANGE"
-                           CHECK_GCR_API(GCR_GTK4, $GCR_GTK4_CFLAGS, have_gcr_gtk4=yes, have_gcr_gtk4=no)],
-                          [have_gcr_gtk4=no])
+        CHECK_GCR(GCR_GTK4, [gcr-4-gtk4 >= 3.90], have_gcr_gtk4=yes, have_gcr_gtk4=no)
     fi
 else
     if (test "${with_gcr_gtk4}" = "yes"); then
@@ -243,12 +244,12 @@ else
 fi
 
 if (test "${have_gcr_gtk4}" = "yes"); then
-     AC_DEFINE(WITH_GCR_GTK4, 1, [Define if Gcr is available])
+     AC_DEFINE(WITH_GCR_GTK4, 1, [Define if Gcr is available for Gtk4])
 else
     if (test "${with_gcr_gtk4}" = "yes"); then
-        AC_MSG_ERROR([gcr support was requested, but the gcr library is not available.])
+        AC_MSG_ERROR([gcr-gtk4 support was requested, but the gcr-gtk4 library is not available.])
     fi
-    AC_DEFINE(WITH_GCR_GTK4, 0, [Define if Gcr is available])
+    AC_DEFINE(WITH_GCR_GTK4, 0, [Define if Gcr is available for Gtk4])
 fi
 AM_CONDITIONAL(WITH_GCR_GTK4, test "${have_gcr_gtk4}" = "yes")
 
diff --git a/meson.build b/meson.build
index 7e86cf7f..2131a519 100644
--- a/meson.build
+++ b/meson.build
@@ -243,50 +243,48 @@ gcr_api_check_src = '''
   GcrCertificate *gcr_simple_certificate_new (const guchar *data, gsize n_data);
 '''
 
+gcr_cflags = [
+  '-DGCR_API_SUBJECT_TO_CHANGE',
+  '-DGCK_API_SUBJECT_TO_CHANGE'
+]
+
 # GCR for PKCS#11 enabled certificate chooser
 enable_gcr = get_option('gcr')
 if enable_gcr
-  deps = [
-    dependency('gcr-3', version: '>= 3.14'),
-    dependency('gck-1', version: '>= 3.14')
-  ]
-
-  cflags = [
-    '-DGCR_API_SUBJECT_TO_CHANGE',
-    '-DGCK_API_SUBJECT_TO_CHANGE'
+  gcr4_gtk3_deps = dependency('gcr-4-gtk3', version: '>= 3.90', required: false)
+  gcr3_deps = [
+    dependency('gcr-3', version: '>= 3.14', required: false),
+    dependency('gck-1', version: '>= 3.14', required: false)
   ]
 
-  # GCR API is declared subject to change, do an extensive check of the prototypes
-  assert(cc.compiles(gcr_api_check_src, dependencies: deps), 'gcr support was requested, but the gcr library 
is not available. Use -Dgcr=false to build without it.')
-
-  gcr_dep = declare_dependency(
-    dependencies: deps,
-    compile_args: cflags
-  )
+  if cc.compiles(gcr_api_check_src, dependencies: gcr4_gtk3_deps)
+    gcr_dep = declare_dependency(
+      dependencies: gcr4_gtk3_deps,
+      compile_args: gcr_cflags
+    )
+  else
+    assert(cc.compiles(gcr_api_check_src, dependencies: gcr3_deps),
+      'gcr support was requested, but the gcr library is not available. Use -Dgcr=false to build without 
it.')
+    gcr_dep = declare_dependency(
+      dependencies: gcr3_deps,
+      compile_args: gcr_cflags
+    )
+  endif
 endif
-config_h.set10('WITH_GCR', enable_gcr)
+config_h.set10('WITH_GCR_GTK3', enable_gcr)
 
 # GCR for PKCS#11 enabled certificate chooser for libnma-gtk4
 enable_gcr_gtk4 = get_option('gcr_gtk4')
 if enable_gcr_gtk4
   assert(enable_libnma_gtk4, 'gcr-gtk4 support was requested, but the libnma-gtk4 build was not enabled.')
 
-  deps = [
-    dependency('gcr-gtk4-3', version: '>= 3.90'),
-    dependency('gck-1', version: '>= 3.90')
-  ]
-
-  cflags = [
-    '-DGCR_API_SUBJECT_TO_CHANGE',
-    '-DGCK_API_SUBJECT_TO_CHANGE'
-  ]
-
-  # GCR API is declared subject to change, do an extensive check of the prototypes
-  assert(cc.compiles(gcr_api_check_src, dependencies: deps), 'gcr-gtk4 support was requested with 
-Dgcr_gtk4=true, but the gcr-gtk4 library is not available.')
+  gcr4_gtk4_deps = dependency('gcr-4-gtk4', version: '>= 3.90', required: false)
+  assert(cc.compiles(gcr_api_check_src, dependencies: gcr4_gtk4_deps),
+    'gcr-gtk4 support was requested with -Dgcr_gtk4=true, but the gcr-gtk4 library is not available.')
 
   gcr_gtk4_dep = declare_dependency(
-    dependencies: deps,
-    compile_args: cflags
+    dependencies: gcr4_gtk4_deps,
+    compile_args: gcr_cflags
   )
 endif
 config_h.set10('WITH_GCR_GTK4', enable_gcr_gtk4)
diff --git a/src/nma-cert-chooser-button.c b/src/nma-cert-chooser-button.c
index 2ea670c7..53fc3272 100644
--- a/src/nma-cert-chooser-button.c
+++ b/src/nma-cert-chooser-button.c
@@ -12,7 +12,7 @@
 #include "nma-cert-chooser-button.h"
 #include "utils.h"
 
-#if GTK_CHECK_VERSION(4,0,0) ? WITH_GCR_GTK4 : WITH_GCR
+#if GTK_CHECK_VERSION(4,0,0) ? WITH_GCR_GTK4 : WITH_GCR_GTK3
 #include "nma-pkcs11-cert-chooser-dialog.h"
 #include <gck/gck.h>
 #include <gcr/gcr.h>   // FIXME: Only here to detect GCK version
@@ -69,7 +69,7 @@ enum {
 static void
 update_title (NMACertChooserButton *button);
 
-#if GTK_CHECK_VERSION(4,0,0) ? WITH_GCR_GTK4 : WITH_GCR
+#if GTK_CHECK_VERSION(4,0,0) ? WITH_GCR_GTK4 : WITH_GCR_GTK3
 static gboolean
 is_this_a_slot_nobody_loves (GckSlot *slot)
 {


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