Replaced version macrodefinitions with constexpr variables

dev
Tomasz Kapuściński 2023-08-09 15:59:12 +02:00
parent 26598c4247
commit f9714c35f7
7 changed files with 40 additions and 19 deletions

View File

@ -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)

View File

@ -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());

View File

@ -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")

View File

@ -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");

View File

@ -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;

View File

@ -1,7 +1,13 @@
#pragma once
#define COLOBOT_FULLNAME "Colobot: Gold Edition @COLOBOT_VERSION_FULL@"
#define COLOBOT_VERSION_DISPLAY "@COLOBOT_VERSION_DISPLAY@"
#include <string_view>
#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@";
};

View File

@ -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);
}