commit 554e7bf9dc136cfb0372db96e3a6391534ee35ea
parent 1c0810906970bcf4ef687c7d28599a45ce754a04
Author: Paul Walker <paul@pwjw.com>
Date: Thu, 22 Dec 2022 11:17:57 -0500
Change VERSION macros to allow compares
1. Add a CLAP_VERSION_x_DIGIT which is just 1, 2, 3
2. Make CLAP_VERSION_x be the uint cast of that
3. Add a CLAP_VERSION_NUMBER which is MAJOR << 16 + MINOR << 8 + REV so you can
do a #if CLAP_VERSION_NUMBER <= 0x010105
4. Update CMakeLists to use DIGIT definitions
Diffstat:
2 files changed, 10 insertions(+), 6 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 \\(\\(uint32_t\\)([0-9]+)\\)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_MAJOR_DIGIT ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_MAJOR ${CMAKE_MATCH_1})
-string(REGEX MATCH "CLAP_VERSION_MINOR \\(\\(uint32_t\\)([0-9]+)\\)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_MINOR_DIGIT ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_MINOR ${CMAKE_MATCH_1})
-string(REGEX MATCH "CLAP_VERSION_REVISION \\(\\(uint32_t\\)([0-9]+)\\)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_REVISION_DIGIT ([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/include/clap/version.h b/include/clap/version.h
@@ -20,11 +20,15 @@ typedef struct clap_version {
}
#endif
-#define CLAP_VERSION_MAJOR ((uint32_t)1)
-#define CLAP_VERSION_MINOR ((uint32_t)1)
-#define CLAP_VERSION_REVISION ((uint32_t)5)
+#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_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
static const CLAP_CONSTEXPR clap_version_t CLAP_VERSION = CLAP_VERSION_INIT;