Commit 8b18187e authored by Alvin Wong's avatar Alvin Wong

CMake: Use `git rev-parse HEAD` to get commit hash

parent 8ca5abd4
......@@ -112,13 +112,17 @@ set(KRITA_GIT_SHA1_STRING "")
set(KRITA_GIT_BRANCH_STRING "")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
get_git_head_hash(GIT_SHA1)
get_git_branch(GIT_BRANCH)
if(GIT_SHA1 AND GIT_BRANCH)
string(SUBSTRING ${GIT_SHA1} 0 7 GIT_SHA1)
set(KRITA_GIT_SHA1_STRING ${GIT_SHA1})
set(KRITA_GIT_BRANCH_STRING ${GIT_BRANCH})
if(GIT_SHA1)
string(SUBSTRING ${GIT_SHA1} 0 7 GIT_SHA1)
set(KRITA_GIT_SHA1_STRING ${GIT_SHA1})
if(GIT_BRANCH)
set(KRITA_GIT_BRANCH_STRING ${GIT_BRANCH})
else()
set(KRITA_GIT_BRANCH_STRING "(detached HEAD)")
endif()
endif()
if(NOT DEFINED RELEASE_BUILD)
......
......@@ -128,6 +128,33 @@ function(git_describe _var)
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(get_git_head_hash _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
execute_process(COMMAND
"${GIT_EXECUTABLE}"
rev-parse --verify HEAD
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(get_git_branch _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
......
......@@ -35,4 +35,11 @@
*/
#cmakedefine KRITA_GIT_BRANCH_STRING "@KRITA_GIT_BRANCH_STRING@"
/**
* @def KRITA_GIT_DESCRIBE_STRING
* @ingroup KritaMacros
* @brief Indicates the git describe string
*/
#cmakedefine KRITA_GIT_DESCRIBE_STRING "@KRITA_GIT_DESCRIBE_STRING@"
#endif /* __KRITA_GIT_VERSION_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment