forked from gnif/LookingGlass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.cmake
35 lines (31 loc) · 1008 Bytes
/
version.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
29
30
31
32
33
34
35
execute_process(
COMMAND git describe --always --long --abbrev=10 --tags
WORKING_DIRECTORY "${PROJECT_TOP}"
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)
if (NOT "${GIT_REV}" STREQUAL "")
execute_process(
COMMAND bash -c "git diff --quiet --exit-code || echo +"
WORKING_DIRECTORY "${PROJECT_TOP}"
OUTPUT_VARIABLE GIT_DIFF)
else()
if (EXISTS ${PROJECT_TOP}/VERSION)
file(READ ${PROJECT_TOP}/VERSION GIT_REV)
else()
set(GIT_REV "UNKNOWN")
set(GIT_DIFF "")
endif()
endif()
string(STRIP "${GIT_REV}" GIT_REV)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
set(GIT_VERSION "${GIT_REV}${GIT_DIFF}")
set(BUILD_VERSION "const char * BUILD_VERSION = \"${GIT_VERSION}\";")
if(EXISTS "${CMAKE_BINARY_DIR}/version.c")
file(READ ${CMAKE_BINARY_DIR}/version.c BUILD_VERSION_)
else()
set(BUILD_VERSION_ "")
endif()
if (NOT "${BUILD_VERSION}" STREQUAL "${BUILD_VERSION_}")
file(WRITE ${CMAKE_BINARY_DIR}/version.c "${BUILD_VERSION}")
file(WRITE ${CMAKE_BINARY_DIR}/VERSION "${GIT_VERSION}")
endif()