diff --git a/CMakeLists.txt b/CMakeLists.txt index d51adffa..4300f73c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,7 +148,9 @@ endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) # Include cmake directory with some additional scripts -set(CMAKE_MODULE_PATH "${colobot_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +list(PREPEND CMAKE_MODULE_PATH + ${PROJECT_SOURCE_DIR}/cmake +) # Compiler detection if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -233,7 +235,7 @@ option(DEV_BUILD "Enable development build (enables some debugging tools, local # Official build - changes text on the crash screen # PLEASE DO NOT USE ON UNOFFICIAL BUILDS. Thanks. -option(OFFICIAL_COLOBOT_BUILD "Official build (changes crash screen text)" OFF) +option(COLOBOT_OFFICIAL_BUILD "Official build (changes crash screen text)" OFF) # Hardcode relative paths instead of absolute paths option(USE_RELATIVE_PATHS "Generate relative paths from absolute paths" OFF) diff --git a/colobot/src/main.cpp b/colobot/src/main.cpp index 4dfef6f1..0b03c635 100644 --- a/colobot/src/main.cpp +++ b/colobot/src/main.cpp @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) LocalFree(wargv); #endif - logger.Info("%s starting\n", COLOBOT_FULLNAME); + logger.Info("%s starting\n", Version::FULL_NAME); CSignalHandlers::Init(systemUtils.get()); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de93ac80..548027cb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,12 @@ endif() add_subdirectory(graphics/opengl33/shaders) +if(COLOBOT_OFFICIAL_BUILD) + set(OFFICIAL_COLOBOT_BUILD "true") +else() + set(OFFICIAL_COLOBOT_BUILD "false") +endif() + # Configure file configure_file(common/config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/common/config.h") configure_file(common/version.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/common/version.h") diff --git a/src/app/app.cpp b/src/app/app.cpp index 77efa8a5..d861aac7 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -305,7 +305,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) case OPT_HELP: { GetLogger()->Message("\n"); - GetLogger()->Message("%s\n", COLOBOT_FULLNAME); + GetLogger()->Message("%s\n", Version::FULL_NAME); GetLogger()->Message("\n"); GetLogger()->Message("List of available options and environment variables:\n"); GetLogger()->Message(" -help this help\n"); diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index bc1768d1..4e79d30a 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -132,16 +132,23 @@ void CSignalHandlers::ReportError(const std::string& errorMessage) msg << "This is usually caused by a bug. Please report this on http://github.com/colobot/colobot/issues" << std::endl; msg << "including information on what you were doing before this happened and all the information below." << std::endl; msg << "==============================" << std::endl; - #if BUILD_NUMBER == 0 - #ifdef OFFICIAL_COLOBOT_BUILD - msg << "You are running official " << COLOBOT_VERSION_DISPLAY << " build." << std::endl; - #else - // COLOBOT_VERSION_DISPLAY doesn't update if you don't run CMake after "git pull" - msg << "You seem to be running a custom compilation of version " << COLOBOT_VERSION_DISPLAY << ", but please verify that." << std::endl; - #endif - #else - msg << "You are running version " << COLOBOT_VERSION_DISPLAY << " from CI build #" << BUILD_NUMBER << std::endl; - #endif + + if constexpr (Version::BUILD_NUMBER == 0) + { + if constexpr (Version::OFFICIAL_BUILD) + { + msg << "You are running official " << Version::VERSION_DISPLAY << " build." << std::endl; + } + else + { + msg << "You seem to be running a custom compilation of version " << Version::VERSION_DISPLAY << ", but please verify that." << std::endl; + } + } + else + { + msg << "You are running version " << Version::VERSION_DISPLAY << " from CI build #" << Version::BUILD_NUMBER << std::endl; + } + msg << std::endl; bool canSave = false; CRobotMain* robotMain = nullptr; diff --git a/src/common/version.h.cmake b/src/common/version.h.cmake index ca377e4f..06c355e7 100644 --- a/src/common/version.h.cmake +++ b/src/common/version.h.cmake @@ -1,7 +1,13 @@ #pragma once -#define COLOBOT_FULLNAME "Colobot: Gold Edition @COLOBOT_VERSION_FULL@" -#define COLOBOT_VERSION_DISPLAY "@COLOBOT_VERSION_DISPLAY@" +#include -#define BUILD_NUMBER @BUILD_NUMBER@ -#cmakedefine OFFICIAL_COLOBOT_BUILD +namespace Version +{ + static inline constexpr bool OFFICIAL_BUILD = @OFFICIAL_COLOBOT_BUILD@; + static inline constexpr int BUILD_NUMBER = @BUILD_NUMBER@; + + static inline constexpr std::string_view FULL_NAME = "Colobot: Gold Edition @COLOBOT_VERSION_FULL@"; + static inline constexpr std::string_view VERSION = "@CMAKE_PROJECT_VERSION@"; + static inline constexpr std::string_view VERSION_DISPLAY = "@COLOBOT_VERSION_DISPLAY@"; +}; diff --git a/src/ui/screen/screen.cpp b/src/ui/screen/screen.cpp index 59a093db..bf816ce3 100644 --- a/src/ui/screen/screen.cpp +++ b/src/ui/screen/screen.cpp @@ -70,7 +70,7 @@ void CScreen::CreateVersionDisplay() pos.y = 9.0f/480.0f; ddim.x = 90.0f/640.0f; ddim.y = 10.0f/480.0f; - CLabel* pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, COLOBOT_VERSION_DISPLAY); + CLabel* pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, std::string(Version::VERSION_DISPLAY)); pl->SetFontType(Gfx::FONT_STUDIO); pl->SetFontSize(9.0f); }