code: Add support for requiring PATCH and TWEAK components
These will be set to 0 if required instead of leaving them blank.
This commit is contained in:
+6
-6
@@ -8,9 +8,9 @@ Synopsis
|
||||
|
||||
.. 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(`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>)
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ Parsing
|
||||
|
||||
.. 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
|
||||
^^^^^^^^^^
|
||||
@@ -49,9 +49,9 @@ Modifying
|
||||
|
||||
.. 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
|
||||
^^^^^^^^^
|
||||
|
||||
+21
-6
@@ -98,12 +98,19 @@ function(version)
|
||||
|
||||
string(TOUPPER "${ARGV0}" ARGV0)
|
||||
if(ARGV0 STREQUAL "PARSE")
|
||||
cmake_parse_arguments(
|
||||
PARSE_ARGV 2
|
||||
_992ae727
|
||||
""
|
||||
""
|
||||
"REQUIRE"
|
||||
)
|
||||
# <major> "." <minor> ["." <patch> ["." <tweak>]]
|
||||
# <major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release>] ["+" <build>]
|
||||
|
||||
# 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\.\-]*|)$]]))
|
||||
set(${OUT_VAR}_ERROR "Version format not supported: '${ARGV2}'" PARENT_SCOPE)
|
||||
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: '${_992ae727_UNPARSED_ARGUMENTS}'" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -116,14 +123,22 @@ function(version)
|
||||
string(SUBSTRING "${CMAKE_MATCH_3}" 1 -1 _TMP)
|
||||
set(${OUT_VAR}_PATCH "${_TMP}" PARENT_SCOPE)
|
||||
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()
|
||||
# {4} = Tweak
|
||||
if((DEFINED CMAKE_MATCH_4) AND (NOT "${CMAKE_MATCH_4}" STREQUAL ""))
|
||||
string(SUBSTRING "${CMAKE_MATCH_4}" 1 -1 _TMP)
|
||||
set(${OUT_VAR}_TWEAK "${_TMP}" PARENT_SCOPE)
|
||||
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()
|
||||
# {5} = PreRelease
|
||||
if((DEFINED CMAKE_MATCH_5) AND (NOT "${CMAKE_MATCH_5}" STREQUAL ""))
|
||||
@@ -270,7 +285,7 @@ function(version)
|
||||
_fe7bcddd
|
||||
"COMPRESS"
|
||||
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
|
||||
""
|
||||
"REQUIRE"
|
||||
)
|
||||
|
||||
# Helpers
|
||||
@@ -297,7 +312,7 @@ function(version)
|
||||
set(_df8abcce_PRERELEASE "")
|
||||
set(_df8abcce_BUILD "")
|
||||
set(_df8abcce_ERROR "")
|
||||
version(PARSE _df8abcce "${ARGV2}")
|
||||
version(PARSE _df8abcce "${ARGV2}" REQUIRE "${_df8abcce_REQUIRE}")
|
||||
if(_df8abcce_ERROR)
|
||||
set(${OUT_VAR}_ERROR ${_df8abcce_ERROR} PARENT_SCOPE)
|
||||
return()
|
||||
|
||||
Reference in New Issue
Block a user