Some little docstrings.
[qpms.git] / version.cmake
blobf8b632ea483c9dd01ff2655544960e95ec1a164a
1 # based on https://www.mattkeeter.com/blog/2018-01-06-versioning/
3 execute_process(COMMAND git describe --tags --dirty --always
4                 OUTPUT_VARIABLE GIT_REV
5                 ERROR_QUIET)
7 # Check whether we got any revision (which isn't
8 # always the case, e.g. when someone downloaded a zip
9 # file from Github instead of a checkout)
10 if ("${GIT_REV}" STREQUAL "")
11     set(GIT_REV "N/A")
12     set(GIT_BRANCH "N/A")
13 else()
14     execute_process(
15         COMMAND git rev-parse --abbrev-ref HEAD
16         OUTPUT_VARIABLE GIT_BRANCH)
18     string(STRIP "${GIT_REV}" GIT_REV)
19     string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
20 endif()
22 set(VERSION "const char* GIT_REV=\"${GIT_REV}\";
23 const char* GIT_BRANCH=\"${GIT_BRANCH}\";")
25 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/qpms_version.c)
26     file(READ ${CMAKE_CURRENT_SOURCE_DIR}/qpms_version.c VERSION_)
27 else()
28     set(VERSION_ "")
29 endif()
31 if (NOT "${VERSION}" STREQUAL "${VERSION_}")
32     file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/qpms_version.c "${VERSION}")
33 endif()