Add git revision

This commit is contained in:
Phillip Stephens 2015-11-19 23:33:09 -08:00
parent c997b7d3c4
commit 18c4b1aa6d
3 changed files with 22 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
*.user
version.h
*.user

View File

@ -44,3 +44,16 @@ add_subdirectory(DataSpec)
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
add_subdirectory(Runtime)
endif()
find_package(Git)
if(GIT_FOUND)
message("git found: ${GIT_EXECUTABLE}")
# Get the current working branch
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE )
# Get the latest abbreviated commit hash of the working branch
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH_FULL OUTPUT_STRIP_TRAILING_WHITESPACE)
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_SOURCE_DIR}/version.h)
endif()

7
version.h.in Normal file
View File

@ -0,0 +1,7 @@
#ifndef VERSION_H
#define VERSION_H
#define GIT_BRANCH "@GIT_BRANCH@"
#define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"
#define GIT_COMMIT_HASH_FULL "@GIT_COMMIT_HASH_FULL@"
#endif