-
Notifications
You must be signed in to change notification settings - Fork 2
/
GitRepoTag.cmake
28 lines (21 loc) · 1.04 KB
/
GitRepoTag.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/.git)
execute_process(COMMAND git rev-parse -q HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_SHA
RESULT_VARIABLE GIT_SHA_RET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${GIT_SHA_RET})
execute_process(COMMAND git describe --tags HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAGNAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND sh -c "basename `git rev-parse --show-toplevel`"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE REPO_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(CODEVERSION_COMPILE_DEFS "REPO_NAME=${REPO_NAME};REPO_VERSION=${GIT_SHA};REPO_TAGNAME=${GIT_TAGNAME}")
message(STATUS "git repo ${REPO_NAME} tag '${GIT_TAGNAME}' (SHA ${GIT_SHA})")
else()
message(WARNING "Project source directory not tracked by version control")
SET(CODEVERSION_COMPILE_DEFS "REPO_NAME=untracked;REPO_VERSION=unversioned;REPO_TAGNAME=untagged")
endif()