diff --git a/.gitignore b/.gitignore index aabdc88c..d4651cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ CMakeSettings.json compile_commands.json *.diagsession tests/ -.DS_Store \ No newline at end of file +.DS_Store +resources/version.hpp \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index bd094f4b..f659f5b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/version.hpp.in b/cmake/version.hpp.in new file mode 100644 index 00000000..c4a9b65c --- /dev/null +++ b/cmake/version.hpp.in @@ -0,0 +1,2 @@ +#pragma once +#define KAIZEN_GIT_COMMIT_HASH "${_git_hash}" \ No newline at end of file diff --git a/src/common.hpp b/src/common.hpp index 81a849c2..b1813c5c 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -1,12 +1,20 @@ #pragma once -#include #include #include #define FORCE_INLINE inline __attribute__((always_inline)) constexpr u32 N64_CPU_FREQ = 93750000; -constexpr u16 KAIZEN_VERSION = 0x010; +#ifdef KAIZEN_USE_HASH +#include +#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) {