feat(cmake): embed git info in binary (#644)
This commit is contained in:
parent
61f4cb3ebc
commit
38c56f6532
3
.gitignore
vendored
3
.gitignore
vendored
@ -10,3 +10,6 @@ build/
|
||||
*.ipch
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# generated by CMAKE
|
||||
version.cpp
|
@ -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")
|
||||
|
35
scripts/git.cmake
Normal file
35
scripts/git.cmake
Normal file
@ -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()
|
@ -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.";
|
||||
|
9
src/version.cpp.in
Normal file
9
src/version.cpp.in
Normal file
@ -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@";
|
||||
};
|
12
src/version.hpp
Normal file
12
src/version.hpp
Normal file
@ -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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user