LookingGlass/version.cmake
Jonathan Rubenstein 57a5488ac2 [cmake] replace git diff logic with git describe --dirty
The --dirty argument of git describe performs the same function as the
now-removed git diff logic.

It will add its argument (default '-dirty') to the end of the revision.

Providing '+' as the argument replicates old behavior.
2021-01-01 12:04:55 +11:00

28 lines
772 B
CMake

execute_process(
COMMAND git describe --always --long --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()