cmake: Fix version detection code

When the CMake script was rewritten, not much attention was put into the versioning code, resulting in odd behavior which was never found or fixed. For example, the automatic splitting of the suffix from the number never worked, and the build number was being stored in the wrong variable.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-03-23 20:41:20 +01:00
parent d24fb07dcc
commit 8189076cd2

View file

@ -78,12 +78,12 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
list(GET GIT_OUTPUT 0 VERSION_MAJOR) list(GET GIT_OUTPUT 0 VERSION_MAJOR)
list(GET GIT_OUTPUT 1 VERSION_MINOR) list(GET GIT_OUTPUT 1 VERSION_MINOR)
list(GET GIT_OUTPUT 2 VERSION_PATCH) list(GET GIT_OUTPUT 2 VERSION_PATCH)
list(GET GIT_OUTPUT 3 VERSION_BUILD) list(GET GIT_OUTPUT 3 VERSION_TWEAK)
list(GET GIT_OUTPUT 4 VERSION_COMMIT) list(GET GIT_OUTPUT 4 VERSION_COMMIT)
# Patch needs additional parsing. # Patch needs additional parsing.
# This may be a [0-9]*[a-z]*[0-9]+ string. # This may be a [0-9]*[a-z]*[0-9]+ string.
string(REGEX MATCHALL "([0-9]+)([a-z0-9]+)" T_MATCHES "${VERSION_PATCH}") string(REGEX MATCHALL "^([0-9]+)([a-z]+[0-9]+)?" T_MATCHES "${VERSION_PATCH}")
set(VERSION_PATCH "${CMAKE_MATCH_1}") set(VERSION_PATCH "${CMAKE_MATCH_1}")
if(CMAKE_MATCH_2) if(CMAKE_MATCH_2)
set(VERSION_SUFFIX "${CMAKE_MATCH_2}") set(VERSION_SUFFIX "${CMAKE_MATCH_2}")
@ -94,11 +94,13 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
message(WARNING "${LOGPREFIX} Failed to detect version, using default instead.") message(WARNING "${LOGPREFIX} Failed to detect version, using default instead.")
endif() endif()
endif() endif()
else()
message(STATUS "${LOGPREFIX} Not a git repository, automatic version detection disabled.")
endif() endif()
# Allow manual overrides of the detected version. # Allow manual overrides of the detected version.
set(${PREFIX}VERSION "" CACHE STRING "Override StreamFX version with this string. Format: Major.Minor.Patch[Suffix][-Tweak[-Commit8c]]") set(${PREFIX}VERSION "" CACHE STRING "Override StreamFX version with this string. Format: Major.Minor.Patch[Suffix][-Tweak[-Commit8c]]")
if(${PREFIX}VERSION) if(NOT (${PREFIX}VERSION STREQUAL ""))
string(REPLACE "-" "." T_VERSION "${${PREFIX}VERSION}") string(REPLACE "-" "." T_VERSION "${${PREFIX}VERSION}")
string(REPLACE "." ";" T_VERSION "${${PREFIX}VERSION}") string(REPLACE "." ";" T_VERSION "${${PREFIX}VERSION}")
@ -107,19 +109,19 @@ if(${PREFIX}VERSION)
list(GET T_VERSION 1 VERSION_MINOR) list(GET T_VERSION 1 VERSION_MINOR)
list(GET T_VERSION 2 VERSION_PATCH) list(GET T_VERSION 2 VERSION_PATCH)
if (T_VERSIONLEN GREATER_EQUAL 3) if (T_VERSIONLEN GREATER_EQUAL 3)
list(GET T_VERSION 3 VERSION_BUILD) list(GET T_VERSION 3 VERSION_TWEAK)
else() else()
set(VERSION_BUILD 0) set(VERSION_BUILD 0)
endif() endif()
if (T_VERSIONLEN GREATER_EQUAL 4) if (T_VERSIONLEN GREATER_EQUAL 4)
list(GET T_VERSION 4 VERSION_COMMIT) list(GET T_VERSION 4 VERSION_COMMIT)
else() else()
# set(VERSION_COMMIT "00000000") set(VERSION_COMMIT "")
endif() endif()
# Patch needs additional parsing. # Patch needs additional parsing.
# This may be a [0-9]*[a-z]*[0-9]+ string. # This may be a [0-9]*[a-z]*[0-9]+ string.
string(REGEX MATCHALL "([0-9]+)([a-z0-9]+)" T_MATCHES "${VERSION_PATCH}") string(REGEX MATCHALL "^([0-9]+)([a-z]+[0-9]+)?" T_MATCHES "${VERSION_PATCH}")
set(VERSION_PATCH "${CMAKE_MATCH_1}") set(VERSION_PATCH "${CMAKE_MATCH_1}")
if(CMAKE_MATCH_2) if(CMAKE_MATCH_2)
set(VERSION_SUFFIX "${CMAKE_MATCH_2}") set(VERSION_SUFFIX "${CMAKE_MATCH_2}")
@ -129,7 +131,7 @@ if(${PREFIX}VERSION)
endif() endif()
# Generate Version String # Generate Version String
if(VERSION_COMMIT) if(NOT (VERSION_COMMIT STREQUAL ""))
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}${VERSION_SUFFIX}-${VERSION_COMMIT}") set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}${VERSION_SUFFIX}-${VERSION_COMMIT}")
else() else()
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}${VERSION_SUFFIX}") set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}${VERSION_SUFFIX}")