version.cmake (view raw)
1set(LIB_VERSION_MAJOR 0)
2set(LIB_VERSION_MINOR 3)
3set(LIB_VERSION_PATCH 0)
4set(LIB_VERSION_ABI 0.3)
5set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
6
7execute_process(COMMAND git describe --always --abbrev=40 --dirty OUTPUT_VARIABLE GIT_COMMIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
8execute_process(COMMAND git describe --always --dirty OUTPUT_VARIABLE GIT_COMMIT_SHORT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
9execute_process(COMMAND git symbolic-ref --short HEAD OUTPUT_VARIABLE GIT_BRANCH ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
10execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE GIT_REV ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
11execute_process(COMMAND git describe --tag --exact-match OUTPUT_VARIABLE GIT_TAG ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
12
13if(GIT_REV STREQUAL "")
14 set(GIT_REV -1)
15endif()
16if(NOT GIT_TAG STREQUAL "")
17 set(VERSION_STRING ${GIT_TAG})
18elseif(GIT_BRANCH STREQUAL "")
19 set(VERSION_STRING ${LIB_VERSION_STRING})
20else()
21 if(GIT_BRANCH STREQUAL "master")
22 set(VERSION_STRING ${GIT_REV}-${GIT_COMMIT_SHORT})
23 else()
24 set(VERSION_STRING ${GIT_BRANCH}-${GIT_REV}-${GIT_COMMIT_SHORT})
25 endif()
26
27 if(NOT LIB_VERSION_ABI STREQUAL GIT_BRANCH)
28 set(VERSION_STRING ${LIB_VERSION_ABI}-${VERSION_STRING})
29 endif()
30endif()
31
32if(CONFIG_FILE AND OUT_FILE)
33 configure_file("${CONFIG_FILE}" "${OUT_FILE}")
34endif()