LookingGlass/version.cmake
Jonathan Rubenstein fabb5bd4a9 [cmake] remove --long from version.cmake
This means if someone checks out a tagged revision, the extra commit N
and commit hash are removed from the VERSION, leaving just the tag name

Adding any commits will cause -<commitssince>-g<commithash> to return.

The dirty worktree '+' still functions as normal, simply appended to
the end of the tag name, like 'v1.0.3+'. With both extra commits and a
dirty worktree, it will look like 'v1.0.3-2-gd6e00e4f34a+', as usual.
2021-01-01 12:10:35 +11:00

28 lines
765 B
CMake

execute_process(
COMMAND git describe --always --abbrev=10 --dirty=+ --tags
WORKING_DIRECTORY "${PROJECT_TOP}"
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)
if ("${GIT_REV}" STREQUAL "")
if (EXISTS ${PROJECT_TOP}/VERSION)
file(READ ${PROJECT_TOP}/VERSION GIT_REV)
else()
set(GIT_REV "UNKNOWN")
endif()
endif()
string(STRIP "${GIT_REV}" GIT_VERSION)
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()