diff --git a/.gitignore b/.gitignore index 93164748..ca87a68c 100644 --- a/.gitignore +++ b/.gitignore @@ -404,5 +404,7 @@ FodyWeavers.xsd cmake-build-* # Linux stuff -build -builds +build[s] + +# Ignore autogenerated git-hash.txt file, generated for packaging purposes +git-hash.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 60efd9ff..e275d687 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ endif() project(Descent3 LANGUAGES C CXX - VERSION 1.5.500 + VERSION 1.5.0 ) option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF) @@ -42,6 +42,23 @@ if(BUILD_TESTING) add_subdirectory(tests) endif() +add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/Descent3/d3_version.h ALL + COMMAND ${CMAKE_COMMAND} + -D SOURCE_DIR=${PROJECT_SOURCE_DIR} + -D TARGET_DIR=${PROJECT_BINARY_DIR} + -D PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} + -D PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR} + -D PROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH} + -P ${PROJECT_SOURCE_DIR}/cmake/CheckGit.cmake + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) + +# rebuild version.hpp every time +add_custom_target(get_git_hash ALL + DEPENDS ${PROJECT_BINARY_DIR}/Descent3/d3_version.h +) + if(UNIX) set(D3_GAMEDIR "~/Descent3/") diff --git a/Descent3/CMakeLists.txt b/Descent3/CMakeLists.txt index f7158650..8f2a3133 100644 --- a/Descent3/CMakeLists.txt +++ b/Descent3/CMakeLists.txt @@ -16,7 +16,6 @@ set(HEADERS BriefingParse.h bsp.h buddymenu.h - buildno.h cinematics.h cockpit.h config.h @@ -301,6 +300,8 @@ target_link_libraries(Descent3 fix grtext manage mem misc model module movie stream_audio music networking physics renderer rtperformance sndlib ui unzip vecmat md5 ${PLATFORM_LIBS}) +target_include_directories(Descent3 PRIVATE ${PROJECT_BINARY_DIR}/lib) +add_dependencies(Descent3 get_git_hash) if(UNIX) add_dependencies(Descent3 HogLinuxFull) diff --git a/Descent3/buildno.h b/Descent3/buildno.h deleted file mode 100644 index b40bb182..00000000 --- a/Descent3/buildno.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -// Descent 3 release build number definition. This file is generated by code, so don't edit it!!!! - -#define D3_RELEASE_BUILD_NO 604 \ No newline at end of file diff --git a/Descent3/lnxmain.cpp b/Descent3/lnxmain.cpp index efe31f48..fa5bae25 100644 --- a/Descent3/lnxmain.cpp +++ b/Descent3/lnxmain.cpp @@ -539,14 +539,14 @@ int main(int argc, char *argv[]) { GatherArgs(argv); - snprintf(game_version_buffer, sizeof(game_version_buffer), "%d.%d.%d%s%s", D3_MAJORVER, D3_MINORVER, D3_BUILD, - LOKI_VERSION, GAME_VERS_EXT); + snprintf(game_version_buffer, sizeof(game_version_buffer), "%d.%d.%d%s %s", D3_MAJORVER, D3_MINORVER, D3_BUILD, + D3_GIT_HASH, GAME_VERS_EXT); loki_setgamename("descent3" GAME_NAME_EXT, game_version_buffer, "Descent 3"); snprintf(game_version_buffer, sizeof(game_version_buffer), "\n\n" - "Descent 3 %s %s v%d.%d.%d%s\n" + "Descent 3 %s %s v%d.%d.%d %s\n" "Copyright (C) 1999 Outrage Entertainment, Inc.\n", #if defined(__APPLE__) && defined(__MACH__) @@ -562,7 +562,7 @@ int main(int argc, char *argv[]) { #else "Client", #endif - D3_MAJORVER, D3_MINORVER, D3_BUILD, LOKI_VERSION); + D3_MAJORVER, D3_MINORVER, D3_BUILD, D3_GIT_HASH); game_version += 2; // skip those first newlines for loki_initialize. diff --git a/Descent3/mmItem.cpp b/Descent3/mmItem.cpp index 5af1a386..09ddb63d 100644 --- a/Descent3/mmItem.cpp +++ b/Descent3/mmItem.cpp @@ -438,31 +438,19 @@ void mmInterface::CopyrightText() { } else if (Program_version.version_type == RELEASE_VERSION) { strcat(type, "Ver"); } -#ifndef RELEASE - int x = Max_window_w - 128, y = Max_window_h - 29; // was -128 and -16 -#else + int x = Max_window_w - 164, y = Max_window_h - 29; // was -128 and -16 -#endif + // attempt to print text nicely. grtext_SetFont(BRIEFING_FONT); grtext_SetAlpha(192); grtext_SetColor(GR_RGB(255, 32, 32)); -#if ((!defined(RELEASE)) || defined(DEMO)) - grtext_Printf(x, y, Program_version.build ? "%s %d.%d.%d" : "%s v%d.%d", type, Program_version.major, - Program_version.minor, Program_version.build); -#else - grtext_Printf(x, y, Program_version.build ? "%s %d.%d.%d Build %d" : "%s v%d.%d", type, Program_version.major, - Program_version.minor, Program_version.build, D3_RELEASE_BUILD_NO); -#endif - // grtext_CenteredPrintf(0, Max_window_h-16, "(c) 1998 Outrage Entertainment, Inc."); - grtext_SetFlags(GRTEXTFLAG_SATURATE); - - for (i = 0; i < 1; i++) { - grtext_Printf(x, y, Program_version.build ? "%s %d.%d.%d" : "%s v%d.%d", type, Program_version.major, - Program_version.minor, Program_version.build); - // grtext_CenteredPrintf(0, Max_window_h-16, "(c) 1998 Outrage Entertainment, Inc."); - } + grtext_Printf(x, y, "%s %d.%d.%d %s", type, Program_version.major, + Program_version.minor, Program_version.build, D3_GIT_HASH); + grtext_SetFlags(GRTEXTFLAG_SHADOW); + grtext_Printf(x, y, "%s %d.%d.%d %s", type, Program_version.major, + Program_version.minor, Program_version.build, D3_GIT_HASH); grtext_Flush(); } diff --git a/Descent3/program.h b/Descent3/program.h index aa9e5481..a31ef2e3 100644 --- a/Descent3/program.h +++ b/Descent3/program.h @@ -156,14 +156,9 @@ #ifndef PROGRAM_H #define PROGRAM_H +#include "d3_version.h" #include "pstypes.h" -#include "buildno.h" - -#define D3_MAJORVER 0x1 // DESCENT 3 VERSION NUMBER -#define D3_MINORVER 0x5 -#define D3_BUILD 0x0 - #define DEVELOPMENT_VERSION 0x1 // without editor: with debug, no beta #define RELEASE_VERSION 0x2 // final release candidate: no debug, beta, editor diff --git a/cmake/CheckGit.cmake b/cmake/CheckGit.cmake new file mode 100644 index 00000000..090d18ed --- /dev/null +++ b/cmake/CheckGit.cmake @@ -0,0 +1,26 @@ +# In case Git is not available, default is empty string +set(GIT_HASH "") + +find_package(Git QUIET) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --always --dirty + OUTPUT_VARIABLE D3_GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + file(WRITE ${SOURCE_DIR}/git-hash.txt ${D3_GIT_HASH}) +else() + # Try to read pregenerated file with commit hash on it (archive version of repository) + if(EXISTS ${SOURCE_DIR}/git-hash.txt) + file(READ ${SOURCE_DIR}/git-hash.txt D3_GIT_HASH) + endif() +endif() + +message(STATUS "Git hash is ${D3_GIT_HASH}") + +configure_file( + ${SOURCE_DIR}/lib/d3_version.h.in + ${TARGET_DIR}/lib/d3_version.h + @ONLY +) diff --git a/lib/d3_version.h.in b/lib/d3_version.h.in new file mode 100644 index 00000000..93355b9d --- /dev/null +++ b/lib/d3_version.h.in @@ -0,0 +1,27 @@ +/* + * Descent 3 + * Copyright (C) 2024 Descent Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +/* This file is autogenerated from lib/d3_version.h.in */ + +#define D3_MAJORVER @PROJECT_VERSION_MAJOR@ +#define D3_MINORVER @PROJECT_VERSION_MINOR@ +#define D3_BUILD @PROJECT_VERSION_PATCH@ + +#define D3_GIT_HASH "@D3_GIT_HASH@" diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt index 7b993853..380b9ffa 100644 --- a/win32/CMakeLists.txt +++ b/win32/CMakeLists.txt @@ -9,3 +9,5 @@ set(CPPS wintask.cpp) add_library(win32 STATIC ${HEADERS} ${CPPS}) +add_dependencies(win32 get_git_hash) +target_include_directories(win32 PRIVATE ${PROJECT_BINARY_DIR}/lib) diff --git a/win32/windebug.cpp b/win32/windebug.cpp index 317df728..cf06b90d 100644 --- a/win32/windebug.cpp +++ b/win32/windebug.cpp @@ -188,6 +188,7 @@ * $NoKeywords: $ */ +#include "d3_version.h" #include "Debug.h" #include "mono.h" @@ -1183,10 +1184,6 @@ const int NumCodeBytes = 16; // Number of code bytes to record. const int MaxStackDump = 2048; // Maximum number of DWORDS in stack dumps. const int StackColumns = 8; // Number of columns in stack dump. -#if (defined(RELEASE) && (!defined(DEMO)) && (!defined(GAMEGAUGE))) -#include "buildno.h" -#endif - extern int no_debug_dialog; int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS data, const char *Message) { @@ -1239,7 +1236,7 @@ int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS data, const char *Message) { WriteFile(LogFile, callstack, lstrlen(callstack), &NumBytes, 0); #if (defined(RELEASE) && (!defined(DEMO)) && (!defined(GAMEGAUGE))) - wsprintf(callstack, "Descent 3 Release build %d\r\n", D3_RELEASE_BUILD_NO); + wsprintf(callstack, "Descent 3 Release build %s\r\n", D3_GIT_HASH); WriteFile(LogFile, callstack, lstrlen(callstack), &NumBytes, 0); #endif RecordSystemInformation(LogFile);