[libgit2-glib/check-version] Add macro GGIT_CHECK_VERSION




commit 07914f47741a4c871d970b8e92beada256414b7f
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Sat Jul 16 09:19:01 2022 +0200

    Add macro GGIT_CHECK_VERSION
    
    Allow to check libgit2-glib version

 libgit2-glib/ggit-version.h.in | 76 ++++++++++++++++++++++++++++++++++++++++++
 libgit2-glib/meson.build       | 15 +++++++++
 2 files changed, 91 insertions(+)
---
diff --git a/libgit2-glib/ggit-version.h.in b/libgit2-glib/ggit-version.h.in
new file mode 100644
index 0000000..4b25185
--- /dev/null
+++ b/libgit2-glib/ggit-version.h.in
@@ -0,0 +1,76 @@
+#ifndef GGIT_VERSION_H
+#define GGIT_VERSION_H
+
+/**
+ * GGIT_VERSION
+ *
+ * libgit2-glib version.
+ */
+#define GGIT_VERSION (@VERSION@)
+
+/**
+ * GGIT_VERSION_S:
+ *
+ * libgit2-glib version, encoded as a string, useful for printing and
+ * concatenation.
+ */
+#define GGIT_VERSION_S "@VERSION@"
+
+/**
+ * GGIT_MAJOR_VERSION:
+ *
+ * libgit2-glib major version component (e.g. 1 if %GGIT_VERSION is 1.2.3)
+ */
+#define GGIT_MAJOR_VERSION (@MAJOR_VERSION@)
+
+/**
+ * GGIT_MINOR_VERSION:
+ *
+ * libgit2-glib minor version component (e.g. 2 if %GGIT_VERSION is 1.2.3)
+ */
+#define GGIT_MINOR_VERSION (@MINOR_VERSION@)
+
+/**
+ * GGIT_MICRO_VERSION:
+ *
+ * libgit2-glib micro version component (e.g. 3 if %GGIT_VERSION is 1.2.3)
+ */
+#define GGIT_MINOR_VERSION (@MICRO_VERSION@)
+
+#define GGIT_ENCODE_VERSION(major,minor,micro) \
+        ((major) << 24 | (minor) << 16 | (micro) << 8)
+
+/**
+ * GGIT_VERSION_HEX:
+ *
+ * libgit2-glib version, encoded as an hexadecimal number, useful for
+ * integer comparisons.
+ */
+#define GGIT_VERSION_HEX \
+        (GGIT_ENCODE_VERSION (GGIT_MAJOR_VERSION, GGIT_MINOR_VERSION, 0))
+
+/**
+ * GGIT_BUILD_TYPE:
+ *
+ * The build type of the installed build.
+ */
+#define GGIT_BUILD_TYPE @BUILD_TYPE@
+
+/**
+ * GGIT_CHECK_VERSION:
+ * @major: required major version
+ * @minor: required minor version
+ * @micro: required micro version
+ *
+ * Compile-time version checking. Evaluates to %TRUE if the version
+ * of libgit2-glib is greater than the required one.
+ *
+ */
+#define GGIT_CHECK_VERSION(major,minor,micro)   \
+        (GGIT_MAJOR_VERSION > (major) || \
+         (GGIT_MAJOR_VERSION == (major) && GGIT_MINOR_VERSION > (minor)) || \
+         (GGIT_MAJOR_VERSION == (major) && GGIT_MINOR_VERSION == (minor) && \
+          GGIT_MICRO_VERSION >= (micro)) \
+        )
+
+#endif /* GGIT_VERSION_H */
diff --git a/libgit2-glib/meson.build b/libgit2-glib/meson.build
index 49af6c1..94bc4f0 100644
--- a/libgit2-glib/meson.build
+++ b/libgit2-glib/meson.build
@@ -1,3 +1,17 @@
+version_data = configuration_data()
+version_data.set('MAJOR_VERSION', libgit2_glib_major_version)
+version_data.set('MINOR_VERSION', libgit2_glib_minor_version)
+version_data.set('MICRO_VERSION', libgit2_glib_micro_version)
+version_data.set('VERSION', libgit2_glib_version)
+version_data.set_quoted('BUILD_TYPE', libgit2_glib_buildtype)
+
+ggit_version_h = configure_file(
+          input: 'ggit-version.h.in',
+         output: 'ggit-version.h',
+    install_dir: libgit2_glib_includedir / libgit2_glib_include_subdir,
+        install: true,
+  configuration: version_data)
+
 headers = [
   'ggit-annotated-commit.h',
   'ggit-blame.h',
@@ -66,6 +80,7 @@ headers = [
   'ggit-tree-builder.h',
   'ggit-tree-entry.h',
   'ggit-types.h',
+  ggit_version_h,
 ]
 
 private_headers = [


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