[all] more versioning fixes

This commit is contained in:
Geoffrey McRae 2020-10-09 03:09:45 +11:00
parent 4d8a116849
commit a15de57e58

View File

@ -9,23 +9,27 @@ if (NOT "${GIT_REV}" STREQUAL "")
COMMAND bash -c "git diff --quiet --exit-code || echo +" COMMAND bash -c "git diff --quiet --exit-code || echo +"
WORKING_DIRECTORY "${PROJECT_TOP}" WORKING_DIRECTORY "${PROJECT_TOP}"
OUTPUT_VARIABLE GIT_DIFF) OUTPUT_VARIABLE GIT_DIFF)
string(STRIP "${GIT_REV}" GIT_REV)
endif()
set(GIT_VERSION "const char * BUILD_VERSION = \"${GIT_REV}\";")
if(EXISTS ${CMAKE_BINARY_DIR}/version.c)
file(READ ${CMAKE_BINARY_DIR}/version.c GIT_VERSION_)
else() else()
if (EXISTS ${PROJECT_TOP}/VERSION) if (EXISTS ${PROJECT_TOP}/VERSION)
file(READ ${PROJECT_TOP}/VERSION GIT_VERSION_) file(READ ${PROJECT_TOP}/VERSION GIT_REV)
else() else()
set(GIT_VERSION_ "UNKNOWN") set(GIT_REV "UNKNOWN")
set(GIT_DIFF "")
endif() endif()
endif() endif()
if (NOT "${GIT_VERSION}" STREQUAL "${GIT_VERSION_}") string(STRIP "${GIT_REV}" GIT_REV)
file(WRITE ${CMAKE_BINARY_DIR}/version.c "${GIT_VERSION}") string(STRIP "${GIT_DIFF}" GIT_DIFF)
file(WRITE ${CMAKE_BINARY_DIR}/VERSION "${GIT_REV}") set(GIT_VERSION "${GIT_REV}${GIT_DIFF}")
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() endif()