Add commit hash in a header generated by CMake

This commit is contained in:
irisz64
2026-01-13 15:08:44 +01:00
parent 6d5389c7ab
commit 4b3974967f
4 changed files with 46 additions and 3 deletions

3
.gitignore vendored
View File

@@ -24,4 +24,5 @@ CMakeSettings.json
compile_commands.json
*.diagsession
tests/
.DS_Store
.DS_Store
resources/version.hpp

View File

@@ -24,6 +24,33 @@ if(${CMAKE_BUILD_TYPE} MATCHES Release OR ${CMAKE_BUILD_TYPE} MATCHES RelWithDeb
endif()
endif()
find_program(GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE _git_hash
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT "${KAIZEN_GIT_COMMIT_HASH}" STREQUAL "${_git_hash}")
file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/resources/version.hpp)
set(KAIZEN_GIT_COMMIT_HASH "${_git_hash}" CACHE STRING "" FORCE)
endif()
else()
# Otherwise, ensure KAIZEN_GIT_COMMIT_HASH is defined
if (DEFINED KAIZEN_GIT_COMMIT_HASH)
set(_git_hash "${KAIZEN_GIT_COMMIT_HASH}" CACHE STRING "" FORCE)
file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/resources/version.hpp)
message("Git not found, but git commit hash was defined as ${KAIZEN_GIT_COMMIT_HASH}")
else()
message(FATAL_ERROR "Git not found, please define KAIZEN_GIT_COMMIT_HASH manually.")
endif()
endif()
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/version.hpp.in ${CMAKE_CURRENT_LIST_DIR}/resources/version.hpp)
include_directories(
src/frontend/Settings
src/frontend
@@ -63,6 +90,11 @@ option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." OFF)
option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." OFF)
option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." OFF)
option(BUILD_SHARED_LIBS OFF)
set(BUILD_FOR_OFFICIAL_RELEASE OFF)
if(NOT ${BUILD_FOR_OFFICIAL_RELEASE})
add_compile_definitions(KAIZEN_USE_HASH)
endif()
include(CheckCCompilerFlag)

2
cmake/version.hpp.in Normal file
View File

@@ -0,0 +1,2 @@
#pragma once
#define KAIZEN_GIT_COMMIT_HASH "${_git_hash}"

View File

@@ -1,12 +1,20 @@
#pragma once
#include <bitset>
#include <types.hpp>
#include <ErrorData.hpp>
#define FORCE_INLINE inline __attribute__((always_inline))
constexpr u32 N64_CPU_FREQ = 93750000;
constexpr u16 KAIZEN_VERSION = 0x010;
#ifdef KAIZEN_USE_HASH
#include <resources/version.hpp>
#define KAIZEN_VERSION_STR KAIZEN_GIT_COMMIT_HASH
#else
#define KAIZEN_VERSION_YEAR 2026
#define KAIZEN_VERSION_MONTH 1
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
#define KAIZEN_VERSION_STR STR(KAIZEN_VERSION_YEAR) "." STR(KAIZEN_VERSION_MONTH)
#endif
static FORCE_INLINE constexpr u32 GetCyclesPerFrame(bool pal) {
if (pal) {