From b817bcec6b5377fef0717d39348a173b7157a91b Mon Sep 17 00:00:00 2001
From: Kieran Bingham <kieran.bingham@ideasonboard.com>
Date: Fri, 18 Jan 2019 11:59:40 +0000
Subject: libcamera: Auto generate version information

Generate a version string, and provide a global string object which
allows applications to interrogate the current libcamera version
information.

The version header is automatically updated by meson on each build.
The string roughly follows the semver [0] conventions of
major.minor.patch-label as a value.

[0] https://semver.org/

A script (utils/gen-version.sh) is provided which is modelled upon the
processing from autoconf's git-version-gen. The gen-version.sh script
will look for tags in the form vX.Y as starting points for the version
string. While the repository does not have any matching tags, v0.0 will
be assumed, resulting in versions with both major and minor being set to
'0', and the patch count resulting from the number of patches in the
history to that point.

Finally, a uniquely identifying shortened hash is provided from git:

	v0.0.509+0ec0edf7

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 include/libcamera/meson.build  |  7 +++++++
 include/libcamera/version.h.in | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 include/libcamera/version.h.in

(limited to 'include')

diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
index 3067120a..6f81f111 100644
--- a/include/libcamera/meson.build
+++ b/include/libcamera/meson.build
@@ -16,6 +16,13 @@ libcamera_api = files([
     'timer.h',
 ])
 
+gen_version = join_paths(meson.source_root(), 'utils', 'gen-version.sh')
+
+version_h = vcs_tag(command : [gen_version, meson.current_source_dir()],
+                    input : 'version.h.in',
+                    output : 'version.h',
+                    fallback : 'v0.0')
+
 gen_header = files('gen-header.sh')
 
 libcamera_h = custom_target('gen-header',
diff --git a/include/libcamera/version.h.in b/include/libcamera/version.h.in
new file mode 100644
index 00000000..e49b3696
--- /dev/null
+++ b/include/libcamera/version.h.in
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * version.h - Library version information
+ *
+ * This file is auto-generated. Do not edit.
+ */
+#ifndef __LIBCAMERA_VERSION_H__
+#define __LIBCAMERA_VERSION_H__
+
+#include <string>
+
+#define LIBCAMERA_VERSION "@VCS_TAG@"
+
+namespace libcamera {
+
+extern const std::string version;
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_VERSION_H__ */
-- 
cgit v1.2.1