]> git.uio.no Git - u/mrichter/AliRoot.git/blame - cmake/CheckGitVersion.cmake
CMake: ZeroMQ - removing mandatory requirement for static library
[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
fae85bcc 24# - ALIROOT_VERSION_RPM - name of the branch/tag in rpm format, - replaced with .
3d675842 25# - ALIROOT_REVISION - short sha1
b22a7396 26if(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
27 include(GetGitRevisionDescription)
28
29 find_package(Git)
30
31 if(GIT_FOUND)
6772faf1 32 message(STATUS "Git version = ${GIT_VERSION_STRING}")
33
b22a7396 34 get_git_head_revision(GIT_REFSPEC GIT_SHA1)
35
3d675842 36 # generate the short version of the revision hash
37 execute_process(COMMAND git rev-parse --short ${GIT_SHA1}
38 WORKING_DIRECTORY ${AliRoot_SOURCE_DIR}
39 OUTPUT_STRIP_TRAILING_WHITESPACE
40 RESULT_VARIABLE res
41 OUTPUT_VARIABLE GIT_SHORT_SHA1)
42
43 # if the rev-parse fails we set the short sha to the long initial one
44 if(NOT res EQUAL 0)
45 set(GIT_SHORT_SHA1 ${GIT_SHA1})
46 endif()
f19da7e9 47
6772faf1 48 # Older Git version < 1.7.3 do not have --count option for rev-list
49 # We use simple rev-list and we count the lines of the output
50 string(COMPARE GREATER "${GIT_VERSION_STRING}" "1.7.3" NEWGIT)
51
52 if(NEWGIT)
53 # generate the short version of the revision hash using --count
54 execute_process(COMMAND git rev-list --count ${GIT_SHA1}
55 WORKING_DIRECTORY ${AliRoot_SOURCE_DIR}
56 OUTPUT_STRIP_TRAILING_WHITESPACE
57 RESULT_VARIABLE revcount
58 OUTPUT_VARIABLE ALIROOT_SERIAL_ORIGINAL)
59 else()
60 # generate the short version of the revision hash using -wc -l
0e4b65c9 61 execute_process(COMMAND git rev-list ${GIT_SHA1}
62 COMMAND wc -l
6772faf1 63 WORKING_DIRECTORY ${AliRoot_SOURCE_DIR}
64 OUTPUT_STRIP_TRAILING_WHITESPACE
65 RESULT_VARIABLE revcount
66 OUTPUT_VARIABLE ALIROOT_SERIAL_ORIGINAL)
67 endif()
3d675842 68
b22a7396 69 # GIT_REFSPEC is empty for detached mode = tags in detached mode or checkout to specific hash
70
71 # returns the closest reference to the current hash
72 # name of the current tag or heads/branch in the case of branches
f19da7e9 73 # Older git version of Git report only the name of the tag
74 # Newer version report tags/vAN-20141215
75 # Just in case we replace tags/ with nothing
b22a7396 76 git_describe(ALIROOT_GIT_TAG "--all" "--abbrev=0")
f19da7e9 77
78 if(ALIROOT_GIT_TAG)
79 string(STRIP ${ALIROOT_GIT_TAG} ALIROOT_GIT_TAG)
80 string(REPLACE "tags/" "" ALIROOT_GIT_TAG ${ALIROOT_GIT_TAG})
81 endif(ALIROOT_GIT_TAG)
82
fb0ae393 83 # using the closest tag for branches
84 git_describe(ALIROOT_CLOSEST_GIT_TAG "--abbrev=0")
85
86 if(ALIROOT_GIT_TAG)
87 string(STRIP ${ALIROOT_GIT_TAG} ALIROOT_GIT_TAG)
88 string(REPLACE "tags/" "" ALIROOT_GIT_TAG ${ALIROOT_GIT_TAG})
89 endif(ALIROOT_GIT_TAG)
90
b22a7396 91 STRING(REGEX REPLACE "^(.+/)(.+)/(.*)$" "\\2" BRANCH_TYPE "${GIT_REFSPEC}" )
92
93 # the revision is not set in the case of a branch, it means we are doing development
94 # and the revision will trigger a reconfiguration
95 if(BRANCH_TYPE STREQUAL "heads")
96 set(ALIROOT_REVISION "ThisIsaBranchNoRevisionProvided")
f19da7e9 97 set(ALIROOT_SERIAL 0)
fb0ae393 98 set(ALIROOT_GIT_TAG ${ALIROOT_CLOSEST_GIT_TAG})
b22a7396 99 STRING(REGEX REPLACE "^(.+/)(.+/)(.*)$" "\\3" SHORT_BRANCH "${GIT_REFSPEC}" )
f19da7e9 100 message(STATUS "This is a working branch, ARVersion will not contain the revision and the serial number")
b22a7396 101 else()
9cdf3698 102 set(BRANCH_TYPE "tags")
b22a7396 103 set(SHORT_BRANCH ${ALIROOT_GIT_TAG})
3d675842 104 set(ALIROOT_REVISION ${GIT_SHORT_SHA1})
0c17f9d0 105 set(ALIROOT_SERIAL ${ALIROOT_SERIAL_ORIGINAL})
b22a7396 106 endif()
107
108 set(ALIROOT_BRANCH ${SHORT_BRANCH})
3d675842 109 set(ALIROOT_VERSION ${SHORT_BRANCH})
c2f9135f 110
fb0ae393 111 # extract major minor and patch from AliRoot tag
112 string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" ALIROOT_VERSION_MAJOR "${ALIROOT_GIT_TAG}")
113 string(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" ALIROOT_VERSION_MINOR "${ALIROOT_GIT_TAG}")
114 string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" ALIROOT_VERSION_PATCH "${ALIROOT_GIT_TAG}")
115 message(STATUS "Found ALIROOT version ${ALIROOT_VERSION_MAJOR}.${ALIROOT_VERSION_MINOR}.${ALIROOT_VERSION_PATCH}")
116
c2f9135f 117 # Replace - with . for rpm creation
118 string(REPLACE "-" "." ALIROOT_VERSION_RPM ${ALIROOT_VERSION})
b22a7396 119
0c17f9d0 120 message(STATUS "Aliroot branch/tag: \"${ALIROOT_VERSION}\" - Revision: \"${GIT_SHORT_SHA1}\" - Serial: \"${ALIROOT_SERIAL_ORIGINAL}\"")
b22a7396 121
122 else()
123 message(STATUS "Git not installed. I can't tell you which revision you are using!")
124 endif(GIT_FOUND)
125else()
126 message("AliRoot sources not downloaded from a Version Control System. I can't tell which revision you are using!")
127endif(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
128
129configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_BINARY_DIR}/version/ARVersion.h @ONLY)
fae85bcc 130install(FILES ${PROJECT_BINARY_DIR}/version/ARVersion.h DESTINATION include)