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
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 "")
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)
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_)
31 if (NOT "${VERSION}" STREQUAL "${VERSION_}")
32 file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/qpms_version.c "${VERSION}")