Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / cmake / gitinfo.cmake
blob0262961c18f66130700d7af8773f7f6f0ec87e53
1 # WRF Macro to identify the commit where the compiled code came from
2 macro( wrf_git_commit )
4   set( options        )
5   set( oneValueArgs   WORKING_DIRECTORY RESULT_VAR )
6   set( multiValueArgs )
8   cmake_parse_arguments(
9                         WRF_GIT_COMMIT
10                         "${options}"  "${oneValueArgs}"  "${multiValueArgs}"
11                         ${ARGN}
12                         )
13   
14   
15   message( STATUS "Retrieving git information..." )
16   execute_process(
17                   OUTPUT_VARIABLE       WRF_GIT_COMMIT_SHA
18                   COMMAND               git describe --dirty --long --always --abbrev=40
19                   WORKING_DIRECTORY     ${WRF_GIT_COMMIT_WORKING_DIRECTORY}
20                   RESULT_VARIABLE       WRF_GIT_COMMIT_NO_GIT_REPO
21                   # ECHO_OUTPUT_VARIABLE
22                   OUTPUT_STRIP_TRAILING_WHITESPACE
23                   )
24   execute_process(
25                   OUTPUT_VARIABLE       WRF_GIT_COMMIT_DIFF
26                   COMMAND               git diff --shortstat
27                   WORKING_DIRECTORY     ${WRF_GIT_COMMIT_WORKING_DIRECTORY}
28                   # ECHO_OUTPUT_VARIABLE
29                   OUTPUT_STRIP_TRAILING_WHITESPACE
30                   )
32   if ( ${WRF_GIT_COMMIT_NO_GIT_REPO} GREATER 0 )
33     set( ${WRF_GIT_COMMIT_RESULT_VAR} "No git found or not a git repository, git commit version not available.")
34     message( STATUS "git info : Unable to get info" )
35   else()
36     set( ${WRF_GIT_COMMIT_RESULT_VAR} "git info : ${WRF_GIT_COMMIT_SHA} ${WRF_GIT_COMMIT_DIFF}" )
37     message( STATUS "git SHA  : ${WRF_GIT_COMMIT_SHA}" )
38     message( STATUS "git diff : ${WRF_GIT_COMMIT_DIFF}" )
39   endif()
40   
41 endmacro()