code: Add REQUIRE to GENERATE command
Allows generating versions which contain all necessary components
This commit is contained in:
+3
-3
@@ -9,7 +9,7 @@ Synopsis
|
|||||||
.. parsed-literal::
|
.. parsed-literal::
|
||||||
|
|
||||||
version(`PARSE`_ <out-var> [REQUIRE [PATCH|TWEAK][;...]] <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>] [REQUIRE [PATCH|TWEAK][;...]])
|
||||||
version(`MODIFY`_ <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] [REQUIRE [PATCH|TWEAK][;...]])
|
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>)
|
||||||
|
|
||||||
@@ -38,9 +38,9 @@ Generating
|
|||||||
|
|
||||||
.. code-block:: cmake
|
.. code-block:: cmake
|
||||||
|
|
||||||
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>] [REQUIRE [PATCH|TWEAK][;...]])
|
||||||
|
|
||||||
Generates a version from the components provided and stores the result in ``<out-var>``. The components ``<major>`` and ``<minor>`` will default to ``0`` if not provided. 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 converted from a list if encountered.
|
Generates a version from the components provided and stores the result in ``<out-var>``. The components ``<major>`` and ``<minor>`` will default to ``0`` if not provided. 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 converted from a list if encountered. The optional ``REQUIRE`` allows forcing the components ``PATCH`` and ``TWEAK`` to always be defined.
|
||||||
|
|
||||||
Modifying
|
Modifying
|
||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|||||||
+15
-85
@@ -10,84 +10,6 @@
|
|||||||
#
|
#
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#[=======================================================================[.rst:
|
|
||||||
version
|
|
||||||
-------
|
|
||||||
|
|
||||||
Generate, parse and modify versions purely with CMake. Supports Semantic Versioning 2.0.0, 1.0.0 and other version formats.
|
|
||||||
|
|
||||||
Synopsis
|
|
||||||
^^^^^^^^
|
|
||||||
|
|
||||||
.. parsed-literal::
|
|
||||||
|
|
||||||
version(`PARSE`_ <out-var> <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(`COMPARE`_ <out-var> <a> <b>)
|
|
||||||
|
|
||||||
|
|
||||||
The following version constructs are currently supported:
|
|
||||||
|
|
||||||
.. code-block::
|
|
||||||
|
|
||||||
<major> "." <minor> ["." <patch> ["." <tweak>]]
|
|
||||||
<major> "." <minor> ["." <patch> ["." <tweak>]] [["-"] <pre-release>] ["+" <build>]
|
|
||||||
|
|
||||||
|
|
||||||
Parsing
|
|
||||||
^^^^^^^
|
|
||||||
|
|
||||||
.. _PARSE:
|
|
||||||
|
|
||||||
.. code-block:: cmake
|
|
||||||
|
|
||||||
version(PARSE <out-var> <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 undefined. If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message.
|
|
||||||
|
|
||||||
Generating
|
|
||||||
^^^^^^^^^^
|
|
||||||
|
|
||||||
.. _GENERATE:
|
|
||||||
|
|
||||||
.. code-block:: cmake
|
|
||||||
|
|
||||||
version(GENERATE <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
|
|
||||||
|
|
||||||
Generates a version from the components provided and stores the result in ``<out-var>``. The components ``<major>`` and ``<minor>`` will default to ``0`` if not provided. If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message.
|
|
||||||
|
|
||||||
Modifying
|
|
||||||
^^^^^^^^^
|
|
||||||
|
|
||||||
.. _MODIFY:
|
|
||||||
|
|
||||||
.. code-block:: cmake
|
|
||||||
|
|
||||||
version(MODIFY <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>])
|
|
||||||
|
|
||||||
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 be defined and contain the error message.
|
|
||||||
|
|
||||||
Comparing
|
|
||||||
^^^^^^^^^
|
|
||||||
|
|
||||||
.. _COMPARE:
|
|
||||||
|
|
||||||
.. code-block:: cmake
|
|
||||||
|
|
||||||
version(COMPARE <out-var> <a> <b>)
|
|
||||||
|
|
||||||
Compares the version ``<a>`` against ``<b>`` and stores the result in ``<out-var>``. The provided version will be evaluated in the order MAJOR, MINOR, PATCH, TWEAK, PRERELEASE, and then BUILD. The following results should be expected:
|
|
||||||
|
|
||||||
- If a component is only in ``<a>``, ``<out-var>`` will contain the componenent name prefixed by ``+``.
|
|
||||||
- If a component is only in ``<b>``, ``<out-var>`` will contain the componenent name prefixed by ``-``.
|
|
||||||
- If a component is numerical and the value is larger in ``<a>``, ``<out-var>`` will contain the componenent name prefixed by ``>``.
|
|
||||||
- If a component is numerical and the value is larger in ``<b>``, ``<out-var>`` will contain the componenent name prefixed by ``<``.
|
|
||||||
- If a component is alphanumerical and the value is different in either, ``<out-var>`` will contain the component name with no prefix.
|
|
||||||
- In all other cases, ``<out-var>`` will be empty.
|
|
||||||
- If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message, and ``<out-var>`` will be undefined.
|
|
||||||
#]=======================================================================]
|
|
||||||
|
|
||||||
function(version)
|
function(version)
|
||||||
# CMake functions do not have their own proper scope, they act more
|
# CMake functions do not have their own proper scope, they act more
|
||||||
|
|
||||||
@@ -171,12 +93,13 @@ function(version)
|
|||||||
set(_32070faa_PRERELEASE "")
|
set(_32070faa_PRERELEASE "")
|
||||||
set(_32070faa_BUILD "")
|
set(_32070faa_BUILD "")
|
||||||
set(_32070faa_ERROR "")
|
set(_32070faa_ERROR "")
|
||||||
|
set(_32070faa_REQUIRE "")
|
||||||
cmake_parse_arguments(
|
cmake_parse_arguments(
|
||||||
PARSE_ARGV 2
|
PARSE_ARGV 2
|
||||||
_32070faa
|
_32070faa
|
||||||
"COMPRESS"
|
"COMPRESS"
|
||||||
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
|
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
|
||||||
""
|
"REQUIRE"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Do we have the major component, and is it valid?
|
# Do we have the major component, and is it valid?
|
||||||
@@ -210,22 +133,26 @@ function(version)
|
|||||||
# Do we have the patch component, and is it valid?
|
# Do we have the patch component, and is it valid?
|
||||||
if(NOT "${_32070faa_PATCH}" STREQUAL "")
|
if(NOT "${_32070faa_PATCH}" STREQUAL "")
|
||||||
string(STRIP "${_32070faa_PATCH}" _32070faa_PATCH)
|
string(STRIP "${_32070faa_PATCH}" _32070faa_PATCH)
|
||||||
if("${_32070faa_PATCH}" STREQUAL "")
|
if(("${_32070faa_PATCH}" STREQUAL "") AND ("PATCH" IN_LIST _32070faa_REQUIRE))
|
||||||
set(_32070faa_PATCH "")
|
set(_32070faa_PATCH "0")
|
||||||
elseif(_32070faa_PATCH MATCHES [[^[0-9]+$]])
|
endif()
|
||||||
|
if(_32070faa_PATCH MATCHES [[^[0-9]+$]])
|
||||||
set(_feeb1eff "${_feeb1eff}.${_32070faa_PATCH}")
|
set(_feeb1eff "${_feeb1eff}.${_32070faa_PATCH}")
|
||||||
else()
|
else()
|
||||||
set(${OUT_VAR}_ERROR "PATCH component must be a numeric identifier, but is: '${_32070faa_PATCH}'" PARENT_SCOPE)
|
set(${OUT_VAR}_ERROR "PATCH component must be a numeric identifier, but is: '${_32070faa_PATCH}'" PARENT_SCOPE)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
elseif("PATCH" IN_LIST _32070faa_REQUIRE)
|
||||||
|
set(_feeb1eff "${_feeb1eff}.0")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Do we have the tweak component, and is it valid?
|
# Do we have the tweak component, and is it valid?
|
||||||
if(NOT "${_32070faa_TWEAK}" STREQUAL "")
|
if(NOT "${_32070faa_TWEAK}" STREQUAL "")
|
||||||
string(STRIP "${_32070faa_TWEAK}" _32070faa_TWEAK)
|
string(STRIP "${_32070faa_TWEAK}" _32070faa_TWEAK)
|
||||||
if("${_32070faa_TWEAK}" STREQUAL "")
|
if(("${_32070faa_TWEAK}" STREQUAL "") AND ("TWEAK" IN_LIST _32070faa_REQUIRE))
|
||||||
set(_32070faa_TWEAK "")
|
set(_32070faa_TWEAK "0")
|
||||||
elseif(_32070faa_TWEAK MATCHES [[^[0-9]+$]])
|
endif()
|
||||||
|
if(_32070faa_TWEAK MATCHES [[^[0-9]+$]])
|
||||||
if("${_32070faa_PATCH}" STREQUAL "")
|
if("${_32070faa_PATCH}" STREQUAL "")
|
||||||
# Patch did not exist, so it is zero.
|
# Patch did not exist, so it is zero.
|
||||||
set(_feeb1eff "${_feeb1eff}.0")
|
set(_feeb1eff "${_feeb1eff}.0")
|
||||||
@@ -355,6 +282,9 @@ function(version)
|
|||||||
if(_fe7bcddd_COMPRESS)
|
if(_fe7bcddd_COMPRESS)
|
||||||
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} COMPRESS")
|
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} COMPRESS")
|
||||||
endif()
|
endif()
|
||||||
|
if(_fe7bcddd_REQUIRE)
|
||||||
|
set(_fe7bcddd_GEN "${_fe7bcddd_GEN} REQUIRE \"${_df8abcce_REQUIRE}\"")
|
||||||
|
endif()
|
||||||
cmake_language(EVAL CODE "version(GENERATE _df8abcce ${_fe7bcddd_GEN})")
|
cmake_language(EVAL CODE "version(GENERATE _df8abcce ${_fe7bcddd_GEN})")
|
||||||
if(_df8abcce_ERROR)
|
if(_df8abcce_ERROR)
|
||||||
set(${OUT_VAR}_ERROR ${_df8abcce_ERROR} PARENT_SCOPE)
|
set(${OUT_VAR}_ERROR ${_df8abcce_ERROR} PARENT_SCOPE)
|
||||||
|
|||||||
Reference in New Issue
Block a user