2 Commits

Author SHA1 Message Date
Michael Fabian 'Xaymar' Dirks 2494a2b6c8 Version: 1.3.0 2022-07-22 13:50:59 +02:00
Michael Fabian 'Xaymar' Dirks e240967c27 code: Add support for requiring PATCH and TWEAK components
These will be set to 0 if required instead of leaving them blank.
2022-07-22 13:50:54 +02:00
3 changed files with 29 additions and 14 deletions
+2 -2
View File
@@ -20,8 +20,8 @@
project = 'version' project = 'version'
copyright = "2022, Michael Fabian Dirks" copyright = "2022, Michael Fabian Dirks"
author = "Michael Fabian 'Xaymar' Dirks" author = "Michael Fabian 'Xaymar' Dirks"
version = "1.2.2" version = "1.3.0"
release = "1.2.2" release = "1.3.0"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
+6 -6
View File
@@ -8,9 +8,9 @@ Synopsis
.. parsed-literal:: .. parsed-literal::
version(`PARSE`_ <out-var> <string>) version(`PARSE`_ <out-var> [REQUIRE [PATCH|TWEAK][;...]] <string>)
version(`GENERATE`_ <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>]) version(`GENERATE`_ <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
version(`MODIFY`_ <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>]) version(`MODIFY`_ <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] [REQUIRE [PATCH|TWEAK][;...]])
version(`COMPARE`_ <out-var> <a> <b>) version(`COMPARE`_ <out-var> <a> <b>)
@@ -27,9 +27,9 @@ Parsing
.. code-block:: cmake .. code-block:: cmake
version(PARSE <out-var> <string>) version(PARSE <out-var> [REQUIRE [PATCH|TWEAK][;...]] <string>)
Attempts to parse the version in ``<string>`` and stores the individual compoents into ``<out-var>_<component>``. If a component is not present in the given version, it will be set to a false constant. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be turned into a list if they are encountered. Attempts to parse the version in ``<string>`` and stores the individual compoents into ``<out-var>_<component>``. If a component is not present in the given version, it will be set to a false constant. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be turned into a list if they are encountered. The optional ``REQUIRE`` allows forcing the components ``PATCH`` and ``TWEAK`` to always be defined.
Generating Generating
^^^^^^^^^^ ^^^^^^^^^^
@@ -49,9 +49,9 @@ Modifying
.. code-block:: cmake .. code-block:: cmake
version(MODIFY <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>]) version(MODIFY <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] [REQUIRE [PATCH|TWEAK][;...]])
Modifies the version provided in ``<string>`` with the components provided. The components ``<major>``, ``<minor>``, ``<patch>`` and ``<tweak>`` may have a prefix of ``+`` or ``-`` to add and subtract the value, or no prefix to replace. The result of this operation will be stored as a string in ``<out-var>``. If a component did not exist in the original, it will be added to the version as a replace operation. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. Modifies the version provided in ``<string>`` with the components provided. The components ``<major>``, ``<minor>``, ``<patch>`` and ``<tweak>`` may have a prefix of ``+`` or ``-`` to add and subtract the value, or no prefix to replace. The result of this operation will be stored as a string in ``<out-var>``. If a component did not exist in the original, it will be added to the version as a replace operation. If an error occurred, ``<out-var>_ERROR`` will contain the error message otherwise it will be a false constant. The optional ``REQUIRE`` allows forcing the components ``PATCH`` and ``TWEAK`` to always be defined.
Comparing Comparing
^^^^^^^^^ ^^^^^^^^^
+21 -6
View File
@@ -98,12 +98,19 @@ function(version)
string(TOUPPER "${ARGV0}" ARGV0) string(TOUPPER "${ARGV0}" ARGV0)
if(ARGV0 STREQUAL "PARSE") if(ARGV0 STREQUAL "PARSE")
cmake_parse_arguments(
PARSE_ARGV 2
_992ae727
""
""
"REQUIRE"
)
# <major> "." <minor> ["." <patch> ["." <tweak>]] # <major> "." <minor> ["." <patch> ["." <tweak>]]
# <major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release>] ["+" <build>] # <major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release>] ["+" <build>]
# One regex to rule them all... # One regex to rule them all...
if(NOT (ARGV2 MATCHES [[^([0-9]+)\.([0-9]+)(\.[0-9]+|)(\.[0-9]+|)(-?[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)(\+[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)$]])) if(NOT (_992ae727_UNPARSED_ARGUMENTS MATCHES [[^([0-9]+)\.([0-9]+)(\.[0-9]+|)(\.[0-9]+|)(-?[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)(\+[a-zA-Z0-9]+[a-zA-Z0-9\.\-]*|)$]]))
set(${OUT_VAR}_ERROR "Version format not supported: '${ARGV2}'" PARENT_SCOPE) set(${OUT_VAR}_ERROR "Version format not supported: '${_992ae727_UNPARSED_ARGUMENTS}'" PARENT_SCOPE)
return() return()
endif() endif()
@@ -116,14 +123,22 @@ function(version)
string(SUBSTRING "${CMAKE_MATCH_3}" 1 -1 _TMP) string(SUBSTRING "${CMAKE_MATCH_3}" 1 -1 _TMP)
set(${OUT_VAR}_PATCH "${_TMP}" PARENT_SCOPE) set(${OUT_VAR}_PATCH "${_TMP}" PARENT_SCOPE)
else() else()
set(${OUT_VAR}_PATCH "" PARENT_SCOPE) if("PATCH" IN_LIST _992ae727_REQUIRE)
set(${OUT_VAR}_PATCH "0" PARENT_SCOPE)
else()
set(${OUT_VAR}_PATCH "" PARENT_SCOPE)
endif()
endif() endif()
# {4} = Tweak # {4} = Tweak
if((DEFINED CMAKE_MATCH_4) AND (NOT "${CMAKE_MATCH_4}" STREQUAL "")) if((DEFINED CMAKE_MATCH_4) AND (NOT "${CMAKE_MATCH_4}" STREQUAL ""))
string(SUBSTRING "${CMAKE_MATCH_4}" 1 -1 _TMP) string(SUBSTRING "${CMAKE_MATCH_4}" 1 -1 _TMP)
set(${OUT_VAR}_TWEAK "${_TMP}" PARENT_SCOPE) set(${OUT_VAR}_TWEAK "${_TMP}" PARENT_SCOPE)
else() else()
set(${OUT_VAR}_TWEAK "" PARENT_SCOPE) if("TWEAK" IN_LIST _992ae727_REQUIRE)
set(${OUT_VAR}_TWEAK "0" PARENT_SCOPE)
else()
set(${OUT_VAR}_TWEAK "" PARENT_SCOPE)
endif()
endif() endif()
# {5} = PreRelease # {5} = PreRelease
if((DEFINED CMAKE_MATCH_5) AND (NOT "${CMAKE_MATCH_5}" STREQUAL "")) if((DEFINED CMAKE_MATCH_5) AND (NOT "${CMAKE_MATCH_5}" STREQUAL ""))
@@ -270,7 +285,7 @@ function(version)
_fe7bcddd _fe7bcddd
"COMPRESS" "COMPRESS"
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD" "MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
"" "REQUIRE"
) )
# Helpers # Helpers
@@ -297,7 +312,7 @@ function(version)
set(_df8abcce_PRERELEASE "") set(_df8abcce_PRERELEASE "")
set(_df8abcce_BUILD "") set(_df8abcce_BUILD "")
set(_df8abcce_ERROR "") set(_df8abcce_ERROR "")
version(PARSE _df8abcce "${ARGV2}") version(PARSE _df8abcce "${ARGV2}" REQUIRE "${_df8abcce_REQUIRE}")
if(_df8abcce_ERROR) if(_df8abcce_ERROR)
set(${OUT_VAR}_ERROR ${_df8abcce_ERROR} PARENT_SCOPE) set(${OUT_VAR}_ERROR ${_df8abcce_ERROR} PARENT_SCOPE)
return() return()