1 # **************************************************************************
2 # * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
4 # * Author: The ALICE Off-line Project. *
5 # * Contributors are mentioned in the code where appropriate. *
7 # * Permission to use, copy, modify and distribute this software and its *
8 # * documentation strictly for non-commercial purposes is hereby granted *
9 # * without fee, provided that the above copyright notice appears in all *
10 # * copies and that both the copyright notice and this permission notice *
11 # * appear in the supporting documentation. The authors make no claims *
12 # * about the suitability of this software for any purpose. It is *
13 # * provided "as is" without express or implied warranty. *
14 # **************************************************************************
16 # Configure ARVerion.h using Git informatiion
17 # Sets 4 git variables
18 # - GIT_REFSPEC - complete name of the current reference
19 # - ALIROOT_BRANCH - name of the branch or tag extracted from the current reference
20 # - GIT_SHA1 - current hash in the long format
21 # - GIT_SHORT_SHA1 - current hash in the short format
23 # - ALIROOT_VERSION - name of the branch/tag
24 # - ALIROOT_VERSION_RPM - name of the branch/tag in rpm format, - replaced with .
25 # - ALIROOT_REVISION - short sha1
26 if(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
27 include(GetGitRevisionDescription)
32 get_git_head_revision(GIT_REFSPEC GIT_SHA1)
34 # generate the short version of the revision hash
35 execute_process(COMMAND git rev-parse --short ${GIT_SHA1}
36 WORKING_DIRECTORY ${AliRoot_SOURCE_DIR}
37 OUTPUT_STRIP_TRAILING_WHITESPACE
39 OUTPUT_VARIABLE GIT_SHORT_SHA1)
41 # if the rev-parse fails we set the short sha to the long initial one
43 set(GIT_SHORT_SHA1 ${GIT_SHA1})
46 # generate the short version of the revision hash
47 execute_process(COMMAND git rev-list --count ${GIT_SHA1}
48 WORKING_DIRECTORY ${AliRoot_SOURCE_DIR}
49 OUTPUT_STRIP_TRAILING_WHITESPACE
50 RESULT_VARIABLE revcount
51 OUTPUT_VARIABLE ALIROOT_SERIAL)
54 # GIT_REFSPEC is empty for detached mode = tags in detached mode or checkout to specific hash
56 # returns the closest reference to the current hash
57 # name of the current tag or heads/branch in the case of branches
58 # Older git version of Git report only the name of the tag
59 # Newer version report tags/vAN-20141215
60 # Just in case we replace tags/ with nothing
61 git_describe(ALIROOT_GIT_TAG "--all" "--abbrev=0")
64 string(STRIP ${ALIROOT_GIT_TAG} ALIROOT_GIT_TAG)
65 string(REPLACE "tags/" "" ALIROOT_GIT_TAG ${ALIROOT_GIT_TAG})
66 endif(ALIROOT_GIT_TAG)
68 STRING(REGEX REPLACE "^(.+/)(.+)/(.*)$" "\\2" BRANCH_TYPE "${GIT_REFSPEC}" )
70 # the revision is not set in the case of a branch, it means we are doing development
71 # and the revision will trigger a reconfiguration
72 if(BRANCH_TYPE STREQUAL "heads")
73 set(ALIROOT_REVISION "ThisIsaBranchNoRevisionProvided")
75 STRING(REGEX REPLACE "^(.+/)(.+/)(.*)$" "\\3" SHORT_BRANCH "${GIT_REFSPEC}" )
76 message(STATUS "This is a working branch, ARVersion will not contain the revision and the serial number")
78 set(SHORT_BRANCH ${ALIROOT_GIT_TAG})
79 set(ALIROOT_REVISION ${GIT_SHORT_SHA1})
82 set(ALIROOT_BRANCH ${SHORT_BRANCH})
83 set(ALIROOT_VERSION ${SHORT_BRANCH})
85 # Replace - with . for rpm creation
86 string(REPLACE "-" "." ALIROOT_VERSION_RPM ${ALIROOT_VERSION})
89 message(STATUS "Aliroot branch/tag: \"${ALIROOT_VERSION}\" - Revision: \"${GIT_SHORT_SHA1}\" - Serial: \"${ALIROOT_SERIAL}\"")
92 message(STATUS "Git not installed. I can't tell you which revision you are using!")
95 message("AliRoot sources not downloaded from a Version Control System. I can't tell which revision you are using!")
96 endif(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
98 configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_BINARY_DIR}/version/ARVersion.h @ONLY)
99 install(FILES ${PROJECT_BINARY_DIR}/version/ARVersion.h DESTINATION include)