Compute fallback version string at compile time

This commit is contained in:
ISSOtm
2021-03-09 23:59:34 +01:00
parent 35367282e4
commit e141da1d94
2 changed files with 9 additions and 9 deletions

View File

@@ -9,9 +9,9 @@
#ifndef EXTERN_VERSION_H #ifndef EXTERN_VERSION_H
#define EXTERN_VERSION_H #define EXTERN_VERSION_H
#define PACKAGE_VERSION_MAJOR (0) #define PACKAGE_VERSION_MAJOR 0
#define PACKAGE_VERSION_MINOR (4) #define PACKAGE_VERSION_MINOR 4
#define PACKAGE_VERSION_PATCH (2) #define PACKAGE_VERSION_PATCH 2
const char *get_package_version_string(void); const char *get_package_version_string(void);

View File

@@ -9,17 +9,17 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "helpers.h"
#include "version.h" #include "version.h"
const char *get_package_version_string(void) const char *get_package_version_string(void)
{ {
static char s[50]; // The following conditional should be simplified by the compiler.
/* The following conditional should be simplified by the compiler. */
if (strlen(BUILD_VERSION_STRING) == 0) { if (strlen(BUILD_VERSION_STRING) == 0) {
snprintf(s, sizeof(s), "v%d.%d.%d", PACKAGE_VERSION_MAJOR, // Fallback if version string can't be obtained from Git
PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCH); return "v" EXPAND_AND_STR(PACKAGE_VERSION_MAJOR)
return s; "." EXPAND_AND_STR(PACKAGE_VERSION_MINOR)
"." EXPAND_AND_STR(PACKAGE_VERSION_PATCH);
} else { } else {
return BUILD_VERSION_STRING; return BUILD_VERSION_STRING;
} }