From 9999f362e4a7dd02225911a9df2f8a6e66ec3162 Mon Sep 17 00:00:00 2001 From: Gliese852 Date: Sat, 13 Jan 2024 23:17:07 +0300 Subject: [PATCH] Hardcode the project version Since the build version is actually the date the build was run, if it is rebuilt on a different day it becomes erroneous. For example, since in any distribution the build into the image will most likely occur after the release, or even rebuild it regularly, the version will differ from the release one, which can be misleading. There is also a second part of the version - the commit hash, but if the stable version is (re)built from the source archive (which is correct), there is no git repo at all. So now it will be specified manually in CMakeLists, so that it unambiguously indicates the version of the game. Also made PROJECT_VERSION a cache variable, so that it is possible to arbitrarily specify the version via command line arguments. It will be useful for CI. Also add PROJECT_VERSION_INFO cache variable. This variable is empty by default. If it contains anything, it will be added to the commit hash in the version, for example: 20240105 (340f22cae extra-info) If the git repo is not available, only the string from the new variable will be in parentheses. --- CMakeLists.txt | 10 +++++++++- buildopts.h.cmakein | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7a4feefd17..974b9bf08d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,12 @@ project(pioneer LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_CXX_STANDARD 17) +set(PROJECT_VERSION 20230203-dev + CACHE STRING "Version identifier for current compiled build") + +set(PROJECT_VERSION_INFO "" + CACHE STRING "Additional version information (optional)") + # If both libGL.so and libOpenGL.so are found, default to the latter # (former is a legacy name). # Set OpenGL_GL_PREFERENCE=LEGACY to force it to use the former. @@ -118,7 +124,9 @@ if (GIT_FOUND AND EXISTS ${PROJECT_SOURCE_DIR}/.git) ) endif() -string(TIMESTAMP PROJECT_VERSION "%Y%m%d") +if(DEFINED PROJECT_VERSION_GIT) + string(JOIN " " PROJECT_VERSION_INFO ${PROJECT_VERSION_GIT} ${PROJECT_VERSION_INFO}) +endif() if (MINGW) # Enable PRIxYY macros on MinGW diff --git a/buildopts.h.cmakein b/buildopts.h.cmakein index 1a8eef2c49c..932ceea9cac 100644 --- a/buildopts.h.cmakein +++ b/buildopts.h.cmakein @@ -1,7 +1,7 @@ #ifndef BUILDOPTS_H #define BUILDOPTS_H -#define PIONEER_EXTRAVERSION "@PROJECT_VERSION_GIT@" +#define PIONEER_EXTRAVERSION "@PROJECT_VERSION_INFO@" #define PIONEER_VERSION "@PROJECT_VERSION@" #define PIONEER_DATA_DIR "@PIONEER_DATA_RUNTIME_DIR@" #define REMOTE_LUA_REPL_PORT @REMOTE_LUA_REPL_PORT@