commit e5218f1fa593a6cee6ceecc616b55c2411c4b92f
parent 554e7bf9dc136cfb0372db96e3a6391534ee35ea
Author: Paul Walker <paul@pwjw.com>
Date: Thu, 22 Dec 2022 13:46:45 -0500
Respond to review
Diffstat:
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -3,11 +3,11 @@ enable_testing()
# Extract the version from header file
file(READ "include/clap/version.h" clap_version_header)
-string(REGEX MATCH "CLAP_VERSION_MAJOR_DIGIT ([0-9]+)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_MAJOR_DIGITS ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_MAJOR ${CMAKE_MATCH_1})
-string(REGEX MATCH "CLAP_VERSION_MINOR_DIGIT ([0-9]+)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_MINOR_DIGITS ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_MINOR ${CMAKE_MATCH_1})
-string(REGEX MATCH "CLAP_VERSION_REVISION_DIGIT ([0-9]+)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_REVISION_DIGITS ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_REVISION ${CMAKE_MATCH_1})
message(STATUS "CLAP version: ${CLAP_VERSION_MAJOR}.${CLAP_VERSION_MINOR}.${CLAP_VERSION_REVISION}")
diff --git a/ChangeLog.md b/ChangeLog.md
@@ -8,6 +8,8 @@
* Remove UTF-8 BOM from a few files
* [plugin-template.c](src/plugin-template.c): add state impl and some comments
* [audio-ports-activation.h](include/clap/ext/draft/audio-ports-activation.h): improved documentation
+* [version.h](include/clap/version.h): create `CLAP_VERSION_NUMBER` which can be used for preprocessor version checks
+ and separate `CLAP_VERSION_MAJOR` (a uint32_t cast of the major version) from `CLAP_VERSION_MAJOR_DIGITS` (the actual digit)
# Changes in 1.1.4
diff --git a/include/clap/version.h b/include/clap/version.h
@@ -20,15 +20,20 @@ typedef struct clap_version {
}
#endif
-#define CLAP_VERSION_MAJOR_DIGIT 1
-#define CLAP_VERSION_MINOR_DIGIT 1
-#define CLAP_VERSION_REVISION_DIGIT 5
-#define CLAP_VERSION_MAJOR ((uint32_t)CLAP_VERSION_MAJOR_DIGIT)
-#define CLAP_VERSION_MINOR ((uint32_t)CLAP_VERSION_MINOR_DIGIT)
-#define CLAP_VERSION_REVISION ((uint32_t)CLAP_VERSION_REVISION_DIGIT)
+#define CLAP_VERSION_MAJOR_DIGITS 1
+#define CLAP_VERSION_MINOR_DIGITS 1
+#define CLAP_VERSION_REVISION_DIGITS 5
+
+#define CLAP_VERSION_MAJOR ((uint32_t)CLAP_VERSION_MAJOR_DIGITS)
+#define CLAP_VERSION_MINOR ((uint32_t)CLAP_VERSION_MINOR_DIGITS)
+#define CLAP_VERSION_REVISION ((uint32_t)CLAP_VERSION_REVISION_DIGITS)
+
#define CLAP_VERSION_INIT \
{ CLAP_VERSION_MAJOR, CLAP_VERSION_MINOR, CLAP_VERSION_REVISION }
-#define CLAP_VERSION_NUMBER (CLAP_VERSION_MAJOR_DIGIT << 16) + (CLAP_VERSION_MINOR_DIGIT << 8) + CLAP_VERSION_REVISION_DIGIT
+
+// CLAP_VERSION_NUMBER can be used as a preprocessor directive comparator, for
+// instance `#if CLAP_VERSION_NUMBER >= 0x010105` will be clap versions at or after 1.1.5
+#define CLAP_VERSION_NUMBER ((CLAP_VERSION_MAJOR_DIGITS << 16) + (CLAP_VERSION_MINOR_DIGIT << 8) + CLAP_VERSION_REVISION_DIGIT)
static const CLAP_CONSTEXPR clap_version_t CLAP_VERSION = CLAP_VERSION_INIT;
@@ -37,3 +42,12 @@ clap_version_is_compatible(const clap_version_t v) {
// versions 0.x.y were used during development stage and aren't compatible
return v.major >= 1;
}
+
+
+#if defined(__cplusplus) && __cplusplus >= 201703L
+// Static assert some version constraints
+static_assert(CLAP_VERSION_MAJOR_DIGITS < 256 && CLAP_VERSION_MAJOR_DIGITS >= 1);
+static_assert(CLAP_VERSION_MINOR_DIGITS < 256 && CLAP_VERSION_REVISION >= 1);
+static_assert(CLAP_VERSION_REVISION_DIGITS < 256 && CLAP_VERSION_REVISION_DIGITS >= 0);
+#endif
+