From bd8ea14907ab75c1ed77e38889fbd027d6c5aed7 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 13 Feb 2022 16:14:39 +0100 Subject: Starshatter versions are now generated based on information from git --- Stars45/CMakeLists.txt | 4 ++++ Stars45/Main.cpp | 3 +-- Stars45/MenuDlg.cpp | 3 +-- Stars45/NetAdminServer.cpp | 3 +-- Stars45/NetBrokerClient.cpp | 2 +- Stars45/NetLobbyClient.cpp | 3 +-- Stars45/NetLobbyServer.cpp | 3 +-- Stars45/NetServerConfig.cpp | 2 +- Stars45/StarServer.cpp | 3 +-- Stars45/VersionInfo.cpp.conf | 9 +++++++++ Stars45/VersionInfo.h | 7 +++++++ cmake/modules/GitDescribe.cmake | 28 ++++++++++++++++++++++++++++ 12 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 Stars45/VersionInfo.cpp.conf create mode 100644 Stars45/VersionInfo.h create mode 100644 cmake/modules/GitDescribe.cmake diff --git a/Stars45/CMakeLists.txt b/Stars45/CMakeLists.txt index 9703810..025df81 100644 --- a/Stars45/CMakeLists.txt +++ b/Stars45/CMakeLists.txt @@ -1,4 +1,5 @@ project(Stars45) +include(GitDescribe) add_executable( Stars45 WIN32 ActiveWindow.cpp @@ -294,6 +295,9 @@ target_compile_definitions( Stars45 PRIVATE _ALLOW_KEYWORD_MACROS ) +git_describe(VERSION) +configure_file(VersionInfo.cpp.conf ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.cpp @ONLY) +target_sources(Stars45 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.cpp) set_target_properties(Stars45 PROPERTIES OUTPUT_NAME Starshatter) if(MSVC) target_include_directories( diff --git a/Stars45/Main.cpp b/Stars45/Main.cpp index b428738..f4f4943 100644 --- a/Stars45/Main.cpp +++ b/Stars45/Main.cpp @@ -27,6 +27,7 @@ #include "FormatUtil.h" #include "ParseUtil.h" #include "Random.h" +#include "VersionInfo.h" // +--------------------------------------------------------------------+ // WinMain @@ -36,8 +37,6 @@ extern FILE* ErrLog; extern int VD3D_describe_things; int dump_missions = 0; -const char* versionInfo = "5.1.87 EX"; - static void PrintLogHeader() { Text sTime = FormatTimeString(); diff --git a/Stars45/MenuDlg.cpp b/Stars45/MenuDlg.cpp index c48b2f8..04b1cb0 100644 --- a/Stars45/MenuDlg.cpp +++ b/Stars45/MenuDlg.cpp @@ -26,6 +26,7 @@ #include "Keyboard.h" #include "Mouse.h" #include "ParseUtil.h" +#include "VersionInfo.h" // +--------------------------------------------------------------------+ // DECLARE MAPPING FUNCTIONS: @@ -44,8 +45,6 @@ DEF_MAP_CLIENT(MenuDlg, OnQuit); DEF_MAP_CLIENT(MenuDlg, OnButtonEnter); DEF_MAP_CLIENT(MenuDlg, OnButtonExit); -extern const char* versionInfo; - // +--------------------------------------------------------------------+ MenuDlg::MenuDlg(Screen* s, FormDef& def, MenuScreen* mgr) diff --git a/Stars45/NetAdminServer.cpp b/Stars45/NetAdminServer.cpp index a3c3f34..4ea6c9b 100644 --- a/Stars45/NetAdminServer.cpp +++ b/Stars45/NetAdminServer.cpp @@ -28,8 +28,7 @@ #include "DataLoader.h" #include "FormatUtil.h" #include "MachineInfo.h" - -extern const char* versionInfo; +#include "VersionInfo.h" // +-------------------------------------------------------------------+ // +-------------------------------------------------------------------+ diff --git a/Stars45/NetBrokerClient.cpp b/Stars45/NetBrokerClient.cpp index 2a31076..f991137 100644 --- a/Stars45/NetBrokerClient.cpp +++ b/Stars45/NetBrokerClient.cpp @@ -20,8 +20,8 @@ #include "NetLayer.h" #include "Game.h" +#include "VersionInfo.h" -extern const char* versionInfo; const char* HOSTNAME = "www.starshatter.com"; const WORD HTTPPORT = 80; diff --git a/Stars45/NetLobbyClient.cpp b/Stars45/NetLobbyClient.cpp index 488114b..bec2d42 100644 --- a/Stars45/NetLobbyClient.cpp +++ b/Stars45/NetLobbyClient.cpp @@ -28,8 +28,7 @@ #include "NetMsg.h" #include "NetLayer.h" #include "FormatUtil.h" - -extern const char* versionInfo; +#include "VersionInfo.h" // +-------------------------------------------------------------------+ diff --git a/Stars45/NetLobbyServer.cpp b/Stars45/NetLobbyServer.cpp index 6dc7849..f3085d7 100644 --- a/Stars45/NetLobbyServer.cpp +++ b/Stars45/NetLobbyServer.cpp @@ -43,8 +43,7 @@ #include "MachineInfo.h" #include "Game.h" #include "FormatUtil.h" - -extern const char* versionInfo; +#include "VersionInfo.h" // +-------------------------------------------------------------------+ diff --git a/Stars45/NetServerConfig.cpp b/Stars45/NetServerConfig.cpp index ad2205b..4e89333 100644 --- a/Stars45/NetServerConfig.cpp +++ b/Stars45/NetServerConfig.cpp @@ -26,11 +26,11 @@ #include "DataLoader.h" #include "ParseUtil.h" #include "resource.h" +#include "VersionInfo.h" // +--------------------------------------------------------------------+ NetServerConfig* NetServerConfig::instance = 0; -extern const char* versionInfo; // +--------------------------------------------------------------------+ diff --git a/Stars45/StarServer.cpp b/Stars45/StarServer.cpp index 2d67de1..c99e499 100644 --- a/Stars45/StarServer.cpp +++ b/Stars45/StarServer.cpp @@ -51,6 +51,7 @@ #include "DataLoader.h" #include "ParseUtil.h" #include "resource.h" +#include "VersionInfo.h" // +--------------------------------------------------------------------+ @@ -60,8 +61,6 @@ static Mission* current_mission = 0; static double time_til_change = 0; static bool exit_latch = true; -extern const char* versionInfo; - // +--------------------------------------------------------------------+ StarServer::StarServer() diff --git a/Stars45/VersionInfo.cpp.conf b/Stars45/VersionInfo.cpp.conf new file mode 100644 index 0000000..adaad2c --- /dev/null +++ b/Stars45/VersionInfo.cpp.conf @@ -0,0 +1,9 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. + */ + +#include "VersionInfo.h" + +const char* versionInfo = "@VERSION@"; diff --git a/Stars45/VersionInfo.h b/Stars45/VersionInfo.h new file mode 100644 index 0000000..9b61dd4 --- /dev/null +++ b/Stars45/VersionInfo.h @@ -0,0 +1,7 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. + */ + +extern const char* versionInfo; diff --git a/cmake/modules/GitDescribe.cmake b/cmake/modules/GitDescribe.cmake new file mode 100644 index 0000000..043f8c0 --- /dev/null +++ b/cmake/modules/GitDescribe.cmake @@ -0,0 +1,28 @@ +function(git_describe VAR) + set(VAR ${ARGV0}) + execute_process( + COMMAND git describe --tags HEAD + WORK_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE DESCRIBE_RESULT + OUTPUT_VARIABLE DESCRIBE_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "describe" " " ${DESCRIBE_RESULT} " " ${DESCRIBE_OUTPUT}) + if(NOT DESCRIBE_RESULT) + set(${VAR} ${DESCRIBE_OUTPUT} PARENT_SCOPE) + else() + execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE PARSE_RESULT + OUTPUT_VARIABLE PARSE_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "rev-parse" " " ${PARSE_RESULT} " " ${PARSE_OUTPUT}) + if(NOT PARSE_RESULT) + set(${VAR} "Unknown-g${PARSE_OUTPUT}" PARENT_SCOPE) + else() + set(${VAR} "Unknown" PARENT_SCOPE) + endif() + endif() +endfunction() -- cgit v1.1