Skip to content

Commit

Permalink
Distinguish builds with commit rather than build date
Browse files Browse the repository at this point in the history
  • Loading branch information
rollerozxa committed Oct 16, 2024
1 parent 9ff71b6 commit 8ecccc1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

add_custom_target(GenerateGitVersion
COMMAND ${CMAKE_COMMAND}
-D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
-D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
-P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateGitVersion.cmake"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")


# Find core dependencies
# ----------------------
Expand Down Expand Up @@ -89,7 +96,8 @@ include_directories(
${FREETYPE_INCLUDE_DIRS}
${JPEG_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS})
${ZLIB_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR})

file(GLOB SRCS
src/tms/core/*.c
Expand Down Expand Up @@ -237,6 +245,7 @@ else()
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
endif()

add_dependencies(${PROJECT_NAME} GenerateGitVersion)

# Compiler flags
# --------------
Expand Down
14 changes: 14 additions & 0 deletions cmake/Modules/GenerateGitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

set(VERSION_GITHASH "(none)")

execute_process(COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}"
OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(VERSION_GITHASH)
set(VERSION_GITHASH "${VERSION_GITHASH}")
endif()

configure_file(
${GENERATE_VERSION_SOURCE_DIR}/src/src/version_info_git.hh.in
${GENERATE_VERSION_BINARY_DIR}/version_info_git.hh)
4 changes: 2 additions & 2 deletions src/src/menu-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
switch (button_id) {
case BTN_VERSION:
char msg[1024];
snprintf(msg, 1023, "Principia %s built at " __DATE__ " " __TIME__ ".",
principia_version_string());
snprintf(msg, 1023, "Principia %s commit %s",
principia_version_string(), principia_version_hash());

ui::message(msg);
break;
Expand Down
5 changes: 5 additions & 0 deletions src/src/version.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "version_info.hh"
#include "version_info_git.hh"

int principia_version_code() {
return PRINCIPIA_VERSION_CODE;
Expand All @@ -7,3 +8,7 @@ int principia_version_code() {
const char* principia_version_string() {
return PRINCIPIA_VERSION_STRING;
}

const char* principia_version_hash() {
return PRINCIPIA_VERSION_HASH;
}
1 change: 1 addition & 0 deletions src/src/version.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

int principia_version_code();
const char* principia_version_string();
const char* principia_version_hash();
5 changes: 5 additions & 0 deletions src/src/version_info_git.hh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

// Filled in by CMake

#define PRINCIPIA_VERSION_HASH "@VERSION_GITHASH@"
2 changes: 1 addition & 1 deletion src/tms/backend/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void print_log_header() {
"| |_) | | | | | | | (__| | |_) | | (_| |\n"
"| .__/|_| |_|_| |_|\\___|_| .__/|_|\\__,_|\n"
"|_| |_| \n"
"Version %d, built " __DATE__ " " __TIME__ "\n", principia_version_code());
"Version %s, commit %s\n", principia_version_string(), principia_version_hash());
}

int main(int argc, char **argv)
Expand Down

0 comments on commit 8ecccc1

Please sign in to comment.