Add version macros

Added macros:

  * SECRET_VERSION_MAJOR
  * SECRET_VERSION_MINOR
  * SECRET_VERSION_MICRO
  * SECRET_CHECK_VERSION

These macros are widely defined in GLib based library. For example,
GLib, GTK, poppler GLib and so on define them.

These macros are useful to detect libsecret version on build type and
from GObject Introspection based bindings.
This commit is contained in:
Sutou Kouhei 2019-05-31 16:39:02 +09:00 committed by Daiki Ueno
parent 31685e0608
commit c00283ebd0
8 changed files with 108 additions and 2 deletions

1
.gitignore vendored
View File

@ -73,6 +73,7 @@ stamp*
/libsecret/*-dbus-generated.[ch] /libsecret/*-dbus-generated.[ch]
/libsecret/secret-enum-types.[ch] /libsecret/secret-enum-types.[ch]
/libsecret/secret-version.h
/libsecret/tests/test-* /libsecret/tests/test-*
/libsecret/tests/*.metadata /libsecret/tests/*.metadata
!/libsecret/tests/test-*.c !/libsecret/tests/test-*.c

View File

@ -1,9 +1,18 @@
AC_PREREQ(2.63) AC_PREREQ(2.63)
AC_INIT([libsecret],[0.18.8], m4_define([libsecret_major_version], 0)
m4_define([libsecret_minor_version], 18)
m4_define([libsecret_micro_version], 8)
m4_define([libsecret_version],
[libsecret_major_version.libsecret_minor_version.libsecret_micro_version])
AC_INIT([libsecret],[libsecret_version],
[https://gitlab.gnome.org/GNOME/libsecret/issues/], [https://gitlab.gnome.org/GNOME/libsecret/issues/],
[libsecret]) [libsecret])
AC_SUBST(SECRET_MAJOR_VERSION, libsecret_major_version)
AC_SUBST(SECRET_MINOR_VERSION, libsecret_minor_version)
AC_SUBST(SECRET_MICRO_VERSION, libsecret_micro_version)
dnl **************************************************************************** dnl ****************************************************************************
dnl Dependency versions dnl Dependency versions
@ -281,6 +290,7 @@ AC_CONFIG_FILES([
po/Makefile po/Makefile
libsecret/libsecret.pc libsecret/libsecret.pc
libsecret/libsecret-unstable.pc libsecret/libsecret-unstable.pc
libsecret/secret-version.h
]) ])
AC_OUTPUT AC_OUTPUT

View File

@ -31,6 +31,7 @@
<xi:include href="xml/secret-prompt.xml"/> <xi:include href="xml/secret-prompt.xml"/>
<xi:include href="xml/secret-error.xml"/> <xi:include href="xml/secret-error.xml"/>
<xi:include href="xml/secret-paths.xml"/> <xi:include href="xml/secret-paths.xml"/>
<xi:include href="xml/secret-version.xml"/>
</part> </part>
<xi:include href="libsecret-using.sgml"/> <xi:include href="libsecret-using.sgml"/>

View File

@ -337,3 +337,11 @@ secret_attributes_buildv
<SECTION> <SECTION>
<FILE>SecretGenPrompt</FILE> <FILE>SecretGenPrompt</FILE>
</SECTION> </SECTION>
<SECTION>
<FILE>secret-version</FILE>
SECRET_CHECK_VERSION
SECRET_MAJOR_VERSION
SECRET_MICRO_VERSION
SECRET_MINOR_VERSION
</SECTION>

View File

@ -22,6 +22,7 @@ libsecret_HEADS = \
inc_HEADERS = \ inc_HEADERS = \
$(libsecret_HEADS) \ $(libsecret_HEADS) \
libsecret/secret-enum-types.h \ libsecret/secret-enum-types.h \
libsecret/secret-version.h \
$(NULL) $(NULL)
libsecret_BUILT_ENUMS = \ libsecret_BUILT_ENUMS = \
@ -31,6 +32,7 @@ libsecret_BUILT_ENUMS = \
libsecret_BUILT = \ libsecret_BUILT = \
secret-dbus-generated.c secret-dbus-generated.h \ secret-dbus-generated.c secret-dbus-generated.h \
$(libsecret_BUILT_ENUMS) \ $(libsecret_BUILT_ENUMS) \
libsecret/secret-version.h \
$(NULL) $(NULL)
libsecret_PUBLIC = \ libsecret_PUBLIC = \
@ -121,7 +123,11 @@ Secret_@SECRET_MAJOR@_gir_EXPORT_PACKAGES = libsecret-@SECRET_MAJOR@
Secret_@SECRET_MAJOR@_gir_INCLUDES = GObject-2.0 Gio-2.0 Secret_@SECRET_MAJOR@_gir_INCLUDES = GObject-2.0 Gio-2.0
Secret_@SECRET_MAJOR@_gir_LIBS = libsecret-@SECRET_MAJOR@.la Secret_@SECRET_MAJOR@_gir_LIBS = libsecret-@SECRET_MAJOR@.la
Secret_@SECRET_MAJOR@_gir_CFLAGS = -I$(srcdir) -I$(builddir) -DSECRET_COMPILATION Secret_@SECRET_MAJOR@_gir_CFLAGS = -I$(srcdir) -I$(builddir) -DSECRET_COMPILATION
Secret_@SECRET_MAJOR@_gir_FILES = $(libsecret_PUBLIC) $(libsecret_BUILT_ENUMS) Secret_@SECRET_MAJOR@_gir_FILES = \
$(libsecret_PUBLIC) \
$(libsecret_BUILT_ENUMS) \
libsecret/secret-version.h \
$(NULL)
Secret_@SECRET_MAJOR@_gir_SCANNERFLAGS = --c-include "libsecret/secret.h" Secret_@SECRET_MAJOR@_gir_SCANNERFLAGS = --c-include "libsecret/secret.h"
gir_DATA += Secret-@SECRET_MAJOR@.gir gir_DATA += Secret-@SECRET_MAJOR@.gir

View File

@ -31,6 +31,19 @@ libsecret_headers = [
'secret-value.h', 'secret-value.h',
] ]
version_numbers = meson.project_version().split('.')
version_major = version_numbers[0].to_int()
version_minor = version_numbers[1].to_int()
version_micro = version_numbers[2].to_int()
version_h_conf = configuration_data()
version_h_conf.set('SECRET_MAJOR_VERSION', version_major)
version_h_conf.set('SECRET_MINOR_VERSION', version_minor)
version_h_conf.set('SECRET_MICRO_VERSION', version_micro)
version_h = configure_file(input: 'secret-version.h.in',
output: 'secret-version.h',
configuration: version_h_conf)
libsecret_headers += version_h
_dbus_generated = gnome.gdbus_codegen('secret-dbus-generated', _dbus_generated = gnome.gdbus_codegen('secret-dbus-generated',
sources: 'org.freedesktop.Secrets.xml', sources: 'org.freedesktop.Secrets.xml',
interface_prefix: 'org.freedesktop.Secret.', interface_prefix: 'org.freedesktop.Secret.',
@ -101,6 +114,7 @@ libsecret_gir_sources = [
'secret-value.c', 'secret-value.c',
'secret-value.h', 'secret-value.h',
] ]
libsecret_gir_sources += version_h
libsecret_gir_sources += _enums_generated libsecret_gir_sources += _enums_generated
libsecret_gir = gnome.generate_gir(libsecret, libsecret_gir = gnome.generate_gir(libsecret,

View File

@ -0,0 +1,65 @@
/* libsecret - GLib wrapper for Secret Service
*
* Copyright 2019 Sutou Kouhei <kou@clear-code.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the licence or (at
* your option) any later version.
*
* See the included COPYING file for more information.
*
* Author: Sutou Kouhei <kou@clear-code.com>
*/
#if !defined (__SECRET_INSIDE_HEADER__) && !defined (SECRET_COMPILATION)
#error "Only <libsecret/secret.h> can be included directly."
#endif
#pragma __once__
/**
* SECTION:secret-version
* @short_description: Variables and macros to check the libsecret version
* @title: Version Information
*
* Stability: Stable
*/
/**
* SECRET_MAJOR_VERSION:
*
* The major version of libsecret.
*/
#define SECRET_MAJOR_VERSION (@SECRET_MAJOR_VERSION@)
/**
* SECRET_MINOR_VERSION:
*
* The minor version of libsecret.
*/
#define SECRET_MINOR_VERSION (@SECRET_MINOR_VERSION@)
/**
* SECRET_MICRO_VERSION:
*
* The micro version of libsecret.
*/
#define SECRET_MICRO_VERSION (@SECRET_MICRO_VERSION@)
/**
* SECRET_CHECK_VERSION:
* @major: major version to be satisfied
* @minor: minor version to be satisfied
* @micro: micro version to be satisfied
*
* Returns: %TRUE if using libsecret is newer than or equal to the
* given version
*/
#define SECRET_CHECK_VERSION(major, minor, micro) \
(SECRET_MAJOR_VERSION > (major) || \
(SECRET_MAJOR_VERSION == (major) && \
SECRET_MINOR_VERSION > (minor)) || \
(SECRET_MAJOR_VERSION == (major) && \
SECRET_MINOR_VERSION == (minor) && \
SECRET_MICRO_VERSION >= (micro)))

View File

@ -30,6 +30,7 @@
#include <libsecret/secret-service.h> #include <libsecret/secret-service.h>
#include <libsecret/secret-types.h> #include <libsecret/secret-types.h>
#include <libsecret/secret-value.h> #include <libsecret/secret-value.h>
#include <libsecret/secret-version.h>
/* SECRET_WITH_UNSTABLE is defined in the secret-unstable.pc pkg-config file */ /* SECRET_WITH_UNSTABLE is defined in the secret-unstable.pc pkg-config file */
#if defined(SECRET_WITH_UNSTABLE) || defined(SECRET_API_SUBJECT_TO_CHANGE) #if defined(SECRET_WITH_UNSTABLE) || defined(SECRET_API_SUBJECT_TO_CHANGE)