From a40e6361ba7172e0a3f3b16e2d286db9928e94e2 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 26 Jan 2023 17:28:42 +0100 Subject: Added build version identification to title screen Since this uses configure_file it might have problems sometimes when trying to detect updated value. It will be better to move it to use custom target instead. --- CMakeLists.txt | 3 +++ cmake/modules/GitRevParse.cmake | 14 ++++++++++++++ kurator/CMakeLists.txt | 5 +++++ kurator/src/Title.cpp | 3 +++ kurator/src/version.cpp.conf | 8 ++++++++ kurator/src/version.h | 10 ++++++++++ version.txt.conf | 1 + 7 files changed, 44 insertions(+) create mode 100644 cmake/modules/GitRevParse.cmake create mode 100644 kurator/src/version.cpp.conf create mode 100644 kurator/src/version.h create mode 100644 version.txt.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 145635f..fe35ab7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,12 @@ find_package(EnTT 3 REQUIRED) find_package(nlohmann_json 3 REQUIRED) find_package(raylib 4 REQUIRED) include(AddResources) +include(GitRevParse) +git_rev_parse(KURATOR_VERSION) add_subdirectory(campaign) add_subdirectory(contrib) add_subdirectory(kurator) add_subdirectory(sim) add_subdirectory(stats) add_subdirectory(universe) +configure_file(version.txt.conf "${CMAKE_CURRENT_BINARY_DIR}/version.txt" @ONLY) diff --git a/cmake/modules/GitRevParse.cmake b/cmake/modules/GitRevParse.cmake new file mode 100644 index 0000000..9005d65 --- /dev/null +++ b/cmake/modules/GitRevParse.cmake @@ -0,0 +1,14 @@ +function(git_rev_parse VAR) + 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 + ) + if(NOT PARSE_RESULT) + set(${VAR} ${PARSE_OUTPUT} PARENT_SCOPE) + else() + set(${VAR} "Unknown" PARENT_SCOPE) + endif() +endfunction() diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 2fd6c55..7add534 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -27,6 +27,11 @@ target_link_libraries( PRIVATE stats PRIVATE universe ) +configure_file(src/version.cpp.conf "${CMAKE_CURRENT_BINARY_DIR}/version.cpp" @ONLY) +target_sources( + ${PROJECT_NAME} + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/version.cpp" +) add_resources( kurator_resources FILES resources/skybox.png diff --git a/kurator/src/Title.cpp b/kurator/src/Title.cpp index 2801799..e5d2e2f 100644 --- a/kurator/src/Title.cpp +++ b/kurator/src/Title.cpp @@ -8,6 +8,7 @@ #include "SceneBuilder.h" #include "Session.h" +#include "version.h" namespace kurator @@ -45,6 +46,8 @@ Title::draw() const const int width = GetScreenWidth(); const int title = MeasureText(text, 20); DrawText(text, (width - title) / 2, 100, 20, GRAY); + const int height = GetScreenHeight(); + DrawText(VERSION, 10, height - 15, 10, DARKGRAY); } diff --git a/kurator/src/version.cpp.conf b/kurator/src/version.cpp.conf new file mode 100644 index 0000000..a6d0aa0 --- /dev/null +++ b/kurator/src/version.cpp.conf @@ -0,0 +1,8 @@ +namespace kurator +{ + + +const char* VERSION {"@KURATOR_VERSION@"}; + + +} // namespace kurator diff --git a/kurator/src/version.h b/kurator/src/version.h new file mode 100644 index 0000000..cf58629 --- /dev/null +++ b/kurator/src/version.h @@ -0,0 +1,10 @@ +#pragma once + +namespace kurator +{ + + +extern const char* VERSION; + + +} // namespace kurator diff --git a/version.txt.conf b/version.txt.conf new file mode 100644 index 0000000..926d433 --- /dev/null +++ b/version.txt.conf @@ -0,0 +1 @@ +@KURATOR_VERSION@ -- cgit v1.1