diff --git a/.gitignore b/.gitignore index 8a6dd3bc..cf15b5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ build/ *.ipch *.gch *.pch + +# generated by CMAKE +version.cpp \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d5d144f..d4ff4154 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(YimMenu CXX ASM_MASM) set(SRC_DIR "${PROJECT_SOURCE_DIR}/src") +# Git commit embed +include(scripts/git.cmake) # Fetch modules message("\nFetching modules") diff --git a/scripts/git.cmake b/scripts/git.cmake new file mode 100644 index 00000000..4b9d674a --- /dev/null +++ b/scripts/git.cmake @@ -0,0 +1,35 @@ +find_package(Git) +if(Git_FOUND) + message("Git found: ${GIT_EXECUTABLE}") + + # the commit's SHA1, and whether the building workspace was dirty or not + execute_process(COMMAND + "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=40 --dirty + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_SHA1 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + # the date of the commit + execute_process(COMMAND + "${GIT_EXECUTABLE}" log -1 --format=%ad --date=local + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_DATE + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + # the subject of the commit + execute_process(COMMAND + "${GIT_EXECUTABLE}" log -1 --format=%s + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_COMMIT_SUBJECT + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + # branch name + execute_process(COMMAND + "${GIT_EXECUTABLE}" branch --show-current + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_BRANCH + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + # generate version.cpp + configure_file("${SRC_DIR}/version.cpp.in" "${SRC_DIR}/version.cpp" @ONLY) +endif() \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8a671e7d..f3e6d536 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "renderer.hpp" #include "script_mgr.hpp" #include "thread_pool.hpp" +#include "version.hpp" #include "backend/backend.hpp" #include "native_hooks/native_hooks.hpp" @@ -58,6 +59,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) try { LOG(INFO) << "Yim's Menu Initializing"; + LOGF(INFO, "Git Info\n\tBranch:\t%s\n\tHash:\t%s\n\tDate:\t%s", version::GIT_BRANCH, version::GIT_SHA1, version::GIT_DATE); g->load(); LOG(INFO) << "Settings Loaded."; diff --git a/src/version.cpp.in b/src/version.cpp.in new file mode 100644 index 00000000..abed2d7a --- /dev/null +++ b/src/version.cpp.in @@ -0,0 +1,9 @@ +#include "version.hpp" + +namespace big +{ + const char* version::GIT_SHA1 = "@GIT_SHA1@"; + const char* version::GIT_BRANCH = "@GIT_BRANCH@"; + const char* version::GIT_DATE = "@GIT_DATE@"; + const char* version::GIT_COMMIT_SUBJECT = "@GIT_COMMIT_SUBJECT@"; +}; \ No newline at end of file diff --git a/src/version.hpp b/src/version.hpp new file mode 100644 index 00000000..7655fee1 --- /dev/null +++ b/src/version.hpp @@ -0,0 +1,12 @@ +#pragma once + +namespace big +{ + struct version + { + static const char* GIT_SHA1; + static const char* GIT_DATE; + static const char* GIT_COMMIT_SUBJECT; + static const char* GIT_BRANCH; + }; +} \ No newline at end of file