xref: /aosp_15_r20/external/bcc/cmake/version.cmake (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker# Copyright (c) PLUMgrid, Inc.
2*387f9dfdSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License")
3*387f9dfdSAndroid Build Coastguard Workerif(NOT REVISION)
4*387f9dfdSAndroid Build Coastguard Worker  get_git_head_revision(GIT_REFSPEC GIT_SHA1)
5*387f9dfdSAndroid Build Coastguard Worker  string(SUBSTRING "${GIT_SHA1}" 0 8 GIT_SHA1_SHORT)
6*387f9dfdSAndroid Build Coastguard Worker  git_describe(GIT_DESCRIPTION)
7*387f9dfdSAndroid Build Coastguard Worker  git_describe(GIT_TAG_LAST "--abbrev=0" "--tags")
8*387f9dfdSAndroid Build Coastguard Worker  git_get_exact_tag(GIT_TAG_EXACT)
9*387f9dfdSAndroid Build Coastguard Worker  string(SUBSTRING "${GIT_TAG_LAST}+${GIT_SHA1_SHORT}" 1 -1 REVISION)
10*387f9dfdSAndroid Build Coastguard Worker  if(GIT_TAG_EXACT)
11*387f9dfdSAndroid Build Coastguard Worker    string(SUBSTRING "${GIT_TAG_EXACT}" 1 -1 REVISION)
12*387f9dfdSAndroid Build Coastguard Worker    message(STATUS "Currently on Git tag ${GIT_TAG_EXACT}")
13*387f9dfdSAndroid Build Coastguard Worker  else ()
14*387f9dfdSAndroid Build Coastguard Worker    message(STATUS "Latest recognized Git tag is ${GIT_TAG_LAST}")
15*387f9dfdSAndroid Build Coastguard Worker    set(GIT_TAG_EXACT "")
16*387f9dfdSAndroid Build Coastguard Worker  endif()
17*387f9dfdSAndroid Build Coastguard Worker  message(STATUS "Git HEAD is ${GIT_SHA1}")
18*387f9dfdSAndroid Build Coastguard Worker  # rpm/deb packaging uses this, only works on whole tag numbers
19*387f9dfdSAndroid Build Coastguard Worker  if(NOT REVISION_LAST)
20*387f9dfdSAndroid Build Coastguard Worker    string(SUBSTRING "${GIT_TAG_LAST}" 1 -1 REVISION_LAST)
21*387f9dfdSAndroid Build Coastguard Worker  endif()
22*387f9dfdSAndroid Build Coastguard Workerelse()
23*387f9dfdSAndroid Build Coastguard Worker  set(REVISION_LAST "${REVISION}")
24*387f9dfdSAndroid Build Coastguard Workerendif()
25*387f9dfdSAndroid Build Coastguard Worker
26*387f9dfdSAndroid Build Coastguard Workerif (REVISION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
27*387f9dfdSAndroid Build Coastguard Worker    set(REVISION_MAJOR ${CMAKE_MATCH_1})
28*387f9dfdSAndroid Build Coastguard Worker    set(REVISION_MINOR ${CMAKE_MATCH_2})
29*387f9dfdSAndroid Build Coastguard Worker    set(REVISION_PATCH ${CMAKE_MATCH_3})
30*387f9dfdSAndroid Build Coastguard Workerelse()
31*387f9dfdSAndroid Build Coastguard Worker  message(WARNING "Could not extract major/minor/patch from revision ${REVISION}" )
32*387f9dfdSAndroid Build Coastguard Workerendif()
33*387f9dfdSAndroid Build Coastguard Worker# strip leading 'v', and make unique for the tag
34*387f9dfdSAndroid Build Coastguard Workermessage(STATUS "Revision is ${REVISION} (major ${REVISION_MAJOR}, minor ${REVISION_MINOR}, patch ${REVISION_PATCH})")
35