cmake: Add proper version override support

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-01-31 17:21:52 +01:00
parent 49eff4a1cf
commit 851e1e8939

View file

@ -89,6 +89,8 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
set(VERSION_PATCH "${CMAKE_MATCH_1}")
if(CMAKE_MATCH_2)
set(VERSION_SUFFIX "${CMAKE_MATCH_2}")
else()
set(VERSION_SUFFIX "")
endif()
else()
message(WARNING "${LOGPREFIX} Failed to detect version, using default instead.")
@ -97,17 +99,35 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
endif()
# Allow manual overrides of the detected version.
set(${PREFIX}VERSION "" CACHE STRING "Override StreamFX version with this string. Format: /[0-9]{1,9}.[0-9]{1,9}.[0-9]{1,9}(|[a-z]{1,1}[0-9]{1,9})-[0-9]{1,9}-[0-9a-fA-F]{8,8}")
set(${PREFIX}VERSION "" CACHE STRING "Override StreamFX version with this string. Format: Major.Minor.Patch[Suffix][-Tweak[-Commit8c]]")
if(${PREFIX}VERSION)
string(REPLACE "-" "." T_VERSION "${${PREFIX}VERSION}")
string(REPLACE "." ";" T_VERSION "${T_VERSION}")
string(REPLACE "." ";" T_VERSION "${${PREFIX}VERSION}")
# Parse Version
list(GET GIT_OUTPUT 0 VERSION_MAJOR)
list(GET GIT_OUTPUT 1 VERSION_MINOR)
list(GET GIT_OUTPUT 2 VERSION_PATCH)
list(GET GIT_OUTPUT 3 VERSION_BUILD)
list(GET GIT_OUTPUT 4 VERSION_COMMIT)
list(LENGTH T_VERSION T_VERSIONLEN)
list(GET T_VERSION 0 VERSION_MAJOR)
list(GET T_VERSION 1 VERSION_MINOR)
list(GET T_VERSION 2 VERSION_PATCH)
if (T_VERSIONLEN GREATER_EQUAL 3)
list(GET T_VERSION 3 VERSION_BUILD)
else()
set(VERSION_BUILD 0)
endif()
if (T_VERSIONLEN GREATER_EQUAL 4)
list(GET T_VERSION 4 VERSION_COMMIT)
else()
# set(VERSION_COMMIT "00000000")
endif()
# Patch needs additional parsing.
# This may be a [0-9]*[a-z]*[0-9]+ string.
string(REGEX MATCHALL "([0-9]+)([a-z0-9]+)" T_MATCHES "${VERSION_PATCH}")
set(VERSION_PATCH "${CMAKE_MATCH_1}")
if(CMAKE_MATCH_2)
set(VERSION_SUFFIX "${CMAKE_MATCH_2}")
else()
set(VERSION_SUFFIX "")
endif()
endif()
# Generate Version String