]> git.uio.no Git - u/mrichter/AliRoot.git/blame - cmake/CheckGitVersion.cmake
Create DA RPM
[u/mrichter/AliRoot.git] / cmake / CheckGitVersion.cmake
CommitLineData
b22a7396 1# **************************************************************************
2# * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3# * *
4# * Author: The ALICE Off-line Project. *
5# * Contributors are mentioned in the code where appropriate. *
6# * *
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# **************************************************************************
15
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
3d675842 22#
23# - ALIROOT_VERSION - name of the branch/tag
24# - ALIROOT_REVISION - short sha1
b22a7396 25if(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
26 include(GetGitRevisionDescription)
27
28 find_package(Git)
29
30 if(GIT_FOUND)
31 get_git_head_revision(GIT_REFSPEC GIT_SHA1)
32
3d675842 33 # generate the short version of the revision hash
34 execute_process(COMMAND git rev-parse --short ${GIT_SHA1}
35 WORKING_DIRECTORY ${AliRoot_SOURCE_DIR}
36 OUTPUT_STRIP_TRAILING_WHITESPACE
37 RESULT_VARIABLE res
38 OUTPUT_VARIABLE GIT_SHORT_SHA1)
39
40 # if the rev-parse fails we set the short sha to the long initial one
41 if(NOT res EQUAL 0)
42 set(GIT_SHORT_SHA1 ${GIT_SHA1})
43 endif()
44
b22a7396 45 # GIT_REFSPEC is empty for detached mode = tags in detached mode or checkout to specific hash
46
47 # returns the closest reference to the current hash
48 # name of the current tag or heads/branch in the case of branches
49 git_describe(ALIROOT_GIT_TAG "--all" "--abbrev=0")
50
51 STRING(REGEX REPLACE "^(.+/)(.+)/(.*)$" "\\2" BRANCH_TYPE "${GIT_REFSPEC}" )
52
53 # the revision is not set in the case of a branch, it means we are doing development
54 # and the revision will trigger a reconfiguration
55 if(BRANCH_TYPE STREQUAL "heads")
56 set(ALIROOT_REVISION "ThisIsaBranchNoRevisionProvided")
57 STRING(REGEX REPLACE "^(.+/)(.+/)(.*)$" "\\3" SHORT_BRANCH "${GIT_REFSPEC}" )
58 else()
59 set(SHORT_BRANCH ${ALIROOT_GIT_TAG})
3d675842 60 set(ALIROOT_REVISION ${GIT_SHORT_SHA1})
b22a7396 61 endif()
62
63 set(ALIROOT_BRANCH ${SHORT_BRANCH})
3d675842 64 set(ALIROOT_VERSION ${SHORT_BRANCH})
c2f9135f 65
66 # Replace - with . for rpm creation
67 string(REPLACE "-" "." ALIROOT_VERSION_RPM ${ALIROOT_VERSION})
b22a7396 68
3d675842 69 message(STATUS "Aliroot branch/tag: \"${ALIROOT_VERSION}\" - Revision: \"${GIT_SHORT_SHA1}\" ")
b22a7396 70
71 else()
72 message(STATUS "Git not installed. I can't tell you which revision you are using!")
73 endif(GIT_FOUND)
74else()
75 message("AliRoot sources not downloaded from a Version Control System. I can't tell which revision you are using!")
76endif(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
77
78configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_BINARY_DIR}/version/ARVersion.h @ONLY)
79install(FILES ${PROJECT_BINARY_DIR}/version/ARVersion.h DESTINATION include)
80
81string (REPLACE "-" "." ALIROOT_BRANCH_SPEC "${ALIROOT_BRANCH}")