Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8061b75697 | |||
| 08392721a9 | |||
| ccd1afb22a | |||
| 2b0699284a | |||
| 9fe3d44d54 | |||
| 208fb31040 | |||
| c61e2cb2ce | |||
| e4313a31ad | |||
| f3d5d3956c | |||
| 519fe4cc75 | |||
| 50e6f494af |
@@ -0,0 +1,88 @@
|
||||
name: Generate Documentation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '!documentation'
|
||||
paths:
|
||||
- '.github/workflows/documentation.yml'
|
||||
- 'docs/**'
|
||||
- 'tools/**'
|
||||
- 'LICENSE'
|
||||
|
||||
jobs:
|
||||
docs:
|
||||
name: "Generate Documentation"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Set up Git"
|
||||
shell: bash
|
||||
run: |
|
||||
git config --global user.name 'GitHub Actions'
|
||||
git config --global user.email 'xaymar@users.noreply.github.com'
|
||||
git config --global pull.ff only
|
||||
git config --global pull.rebase true
|
||||
|
||||
- name: "Clone"
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: "Clone Documentation"
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: 'documentation'
|
||||
path: 'build/docs/html'
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
# git clone --progress --recursive -b documentation --single-branch https://x-access-token:${{ github.token }}@github.com/${{ github.repository }} "${{ github.workspace }}/build/docs/html"
|
||||
|
||||
- name: "Install Prerequisites"
|
||||
shell: bash
|
||||
run: |
|
||||
sudo apt-get install make python3 python3-pip python3-virtualenv
|
||||
|
||||
- name: "Install Sphinx and Themes into a VirtualEnv"
|
||||
shell: bash
|
||||
run: |
|
||||
source ~/.profile
|
||||
virtualenv build/venv
|
||||
source build/venv/bin/activate
|
||||
pip install sphinx
|
||||
pip install sphinx-rtd-theme
|
||||
|
||||
- name: "Generate Documentation"
|
||||
shell: bash
|
||||
run: |
|
||||
source ~/.profile
|
||||
source build/venv/bin/activate
|
||||
pushd tools
|
||||
make html
|
||||
ls -lha
|
||||
popd
|
||||
ls -lha
|
||||
|
||||
- name: "Update Documentation"
|
||||
shell: bash
|
||||
run: |
|
||||
pushd build/docs/html
|
||||
git add .
|
||||
git --no-pager diff --patch --minimal HEAD --
|
||||
git update-index --refresh
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
git commit -a -m "${{ github.sha }}"
|
||||
|
||||
# Only push from master branch.
|
||||
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
|
||||
git push
|
||||
echo "Documentation has been updated!"
|
||||
else
|
||||
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
|
||||
fi
|
||||
else
|
||||
echo "Documentation is still up to date."
|
||||
fi
|
||||
popd
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
name: Automated Testing
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '!documentation'
|
||||
paths:
|
||||
- '.github/workflows/test.yml'
|
||||
- 'tests/**'
|
||||
- 'version.cmake'
|
||||
pull_request:
|
||||
paths:
|
||||
- '.github/workflows/test.yml'
|
||||
- 'tests/**'
|
||||
- 'version.cmake'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: "Run Tests"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Clone"
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: "Install Prerequisites"
|
||||
shell: bash
|
||||
run: |
|
||||
sudo apt-get install build-essential cmake
|
||||
|
||||
- name: "Run Tests"
|
||||
shell: bash
|
||||
run: |
|
||||
cmake -Htests -Bbuild/tests
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright 2021 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
||||
Copyright 2022 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# cmake-version
|
||||
Tired of manually parsing, modifying and comparing versions? Then this may help you! cmake-version is a pure CMake module that supports parsing, modifying, generating and comparing versions in the format specified by Semantic Versioning 1.0.0, Semantic Versioning 2.0.0 and CMake. It also supports a mixture of all formats, for much more functionality.
|
||||
|
||||
## [Documentation](https://xaymar.github.io/cmake-version/)
|
||||
The documentation is generated by Sphinx with the `Read the Docs` theme and is available at [xaymar.github.io/cmake-version/](https://xaymar.github.io/cmake-version/).
|
||||
|
||||
## License
|
||||
> Copyright 2022 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
>
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> 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.
|
||||
+3
-3
@@ -20,8 +20,8 @@
|
||||
project = 'version'
|
||||
copyright = "2022, Michael Fabian Dirks"
|
||||
author = "Michael Fabian 'Xaymar' Dirks"
|
||||
version = "0.1"
|
||||
release = "0.1"
|
||||
version = "1.1"
|
||||
release = "1.1"
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
@@ -53,4 +53,4 @@ html_theme = 'sphinx_rtd_theme'
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
html_static_path = []
|
||||
+73
-5
@@ -1,7 +1,75 @@
|
||||
Version handling for CMake
|
||||
=========================================
|
||||
version
|
||||
-------
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
Generate, parse and modify versions purely with CMake. Supports Semantic Versioning 2.0.0, 1.0.0 and other version formats.
|
||||
|
||||
version
|
||||
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>]] [["-"] <pre-release> ["." <pre-release> [...]]] ["+" <build> ["." <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. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be turned into a list if they are encountered.
|
||||
|
||||
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. The ``PRERELEASE`` and ``BUILD`` components support the dot-separation specifier and will be converted from a list if encountered.
|
||||
|
||||
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.
|
||||
- If an error occurred, ``<out-var>_ERROR`` will be defined and contain the error message, and ``<out-var>`` will be undefined.
|
||||
- In all other cases, ``<out-var>`` will be empty.
|
||||
|
||||
There is no special handling for dot-separated ``PRERELEASE`` and ``BUILD`` component. They will be treated as if they were a string, as special handling for these is up to the application.
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
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.
|
||||
|
||||
@@ -15,7 +15,9 @@ test_generate("0.0.3" PATCH 3)
|
||||
test_generate("0.0.0.4" TWEAK 4)
|
||||
test_generate("0.0-5" COMPRESS PRERELEASE 5)
|
||||
test_generate("0.0a5" COMPRESS PRERELEASE a5)
|
||||
test_generate("0.0a5.5" COMPRESS PRERELEASE "a5;5")
|
||||
test_generate("0.0+6" BUILD 6)
|
||||
test_generate("0.0+6.8" BUILD "6;8")
|
||||
# - Invalid Cases
|
||||
test_generate("-1.0.0" FAIL MAJOR "-1")
|
||||
test_generate("0.-1.0" FAIL MINOR "-1")
|
||||
@@ -47,6 +49,9 @@ test_parse("1.2.3.4-5+6" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE 5 BUILD 6)
|
||||
test_parse("1.2a5+6" MAJOR 1 MINOR 2 PRERELEASE a5 BUILD 6)
|
||||
test_parse("1.2.3a5+6" MAJOR 1 MINOR 2 PATCH 3 PRERELEASE a5 BUILD 6)
|
||||
test_parse("1.2.3.4a5+6" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE a5 BUILD 6)
|
||||
test_parse("1.2a5.b5+6.66" MAJOR 1 MINOR 2 PRERELEASE "a5;b5" BUILD "6;66")
|
||||
test_parse("1.2.3a5.b5+6.66" MAJOR 1 MINOR 2 PATCH 3 PRERELEASE "a5;b5" BUILD "6;66")
|
||||
test_parse("1.2.3.4a5.b5+6.66" MAJOR 1 MINOR 2 PATCH 3 TWEAK 4 PRERELEASE "a5;b5" BUILD "6;66")
|
||||
# - Invalid Cases
|
||||
test_parse("" FAIL)
|
||||
test_parse("cmake" FAIL)
|
||||
|
||||
+6
-6
@@ -66,7 +66,7 @@ function(test_parse)
|
||||
set(MESSAGE "MAJOR component missing during parse.")
|
||||
set(FAILED ON)
|
||||
elseif(NOT (_TEST_MAJOR STREQUAL _ARGS_MAJOR))
|
||||
set(MESSAGE "MAJOR component mismatch.")
|
||||
set(MESSAGE "MAJOR component mismatch: '${_TEST_MAJOR}' != '${_ARGS_MAJOR}'")
|
||||
set(FAILED ON)
|
||||
endif()
|
||||
endif()
|
||||
@@ -76,7 +76,7 @@ function(test_parse)
|
||||
set(MESSAGE "MINOR component missing during parse.")
|
||||
set(FAILED ON)
|
||||
elseif(NOT (_TEST_MINOR STREQUAL _ARGS_MINOR))
|
||||
set(MESSAGE "MINOR component mismatch.")
|
||||
set(MESSAGE "MINOR component mismatch: '${_TEST_MINOR}' != '${_ARGS_MINOR}'")
|
||||
set(FAILED ON)
|
||||
endif()
|
||||
endif()
|
||||
@@ -86,7 +86,7 @@ function(test_parse)
|
||||
set(MESSAGE "PATCH component missing during parse.")
|
||||
set(FAILED ON)
|
||||
elseif(NOT (_TEST_PATCH STREQUAL _ARGS_PATCH))
|
||||
set(MESSAGE "PATCH component mismatch.")
|
||||
set(MESSAGE "PATCH component mismatch: '${_TEST_PATCH}' != '${_ARGS_PATCH}'")
|
||||
set(FAILED ON)
|
||||
endif()
|
||||
endif()
|
||||
@@ -96,7 +96,7 @@ function(test_parse)
|
||||
set(MESSAGE "TWEAK component missing during parse.")
|
||||
set(FAILED ON)
|
||||
elseif(NOT (_TEST_TWEAK STREQUAL _ARGS_TWEAK))
|
||||
set(MESSAGE "TWEAK component mismatch.")
|
||||
set(MESSAGE "TWEAK component mismatch: '${_TEST_TWEAK}' != '${_ARGS_TWEAK}'")
|
||||
set(FAILED ON)
|
||||
endif()
|
||||
endif()
|
||||
@@ -106,7 +106,7 @@ function(test_parse)
|
||||
set(MESSAGE "PRERELEASE component missing during parse.")
|
||||
set(FAILED ON)
|
||||
elseif(NOT (_TEST_PRERELEASE STREQUAL _ARGS_PRERELEASE))
|
||||
set(MESSAGE "PRERELEASE component mismatch.")
|
||||
set(MESSAGE "PRERELEASE component mismatch: '${_TEST_PRERELEASE}' != '${_ARGS_PRERELEASE}'")
|
||||
set(FAILED ON)
|
||||
endif()
|
||||
endif()
|
||||
@@ -116,7 +116,7 @@ function(test_parse)
|
||||
set(MESSAGE "BUILD component missing during parse.")
|
||||
set(FAILED ON)
|
||||
elseif(NOT (_TEST_BUILD STREQUAL _ARGS_BUILD))
|
||||
set(MESSAGE "BUILD component mismatch.")
|
||||
set(MESSAGE "BUILD component mismatch: '${_TEST_BUILD}' != '${_ARGS_BUILD}'")
|
||||
set(FAILED ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
+86
-6
@@ -10,7 +10,83 @@
|
||||
#
|
||||
# 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.
|
||||
|
||||
# For SemVer 2.0.0
|
||||
#[=======================================================================[.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)
|
||||
unset(${OUT_VAR} PARENT_SCOPE)
|
||||
@@ -49,10 +125,11 @@ function(version)
|
||||
endif()
|
||||
# {5} = PreRelease
|
||||
if(CMAKE_MATCH_5)
|
||||
string(REPLACE "." ";" CMAKE_MATCH_5 "${CMAKE_MATCH_5}") # Handle dot separation as list.
|
||||
string(SUBSTRING "${CMAKE_MATCH_5}" 0 1 _TMP)
|
||||
if(_TMP STREQUAL "-")
|
||||
string(SUBSTRING "${CMAKE_MATCH_5}" 1 -1 _TMP)
|
||||
set(${OUT_VAR}_PRERELEASE "${_TMP}" PARENT_SCOPE)
|
||||
string(SUBSTRING "${CMAKE_MATCH_5}" 1 -1 CMAKE_MATCH_5)
|
||||
set(${OUT_VAR}_PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE)
|
||||
else()
|
||||
set(${OUT_VAR}_PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE)
|
||||
endif()
|
||||
@@ -61,8 +138,9 @@ function(version)
|
||||
endif()
|
||||
# {6} = Build
|
||||
if(CMAKE_MATCH_6)
|
||||
string(SUBSTRING "${CMAKE_MATCH_6}" 1 -1 _TMP)
|
||||
set(${OUT_VAR}_BUILD "${_TMP}" PARENT_SCOPE)
|
||||
string(REPLACE "." ";" CMAKE_MATCH_6 "${CMAKE_MATCH_6}") # Handle dot separation as list.
|
||||
string(SUBSTRING "${CMAKE_MATCH_6}" 1 -1 CMAKE_MATCH_6)
|
||||
set(${OUT_VAR}_BUILD "${CMAKE_MATCH_6}" PARENT_SCOPE)
|
||||
else()
|
||||
unset(${OUT_VAR}_BUILD PARENT_SCOPE)
|
||||
endif()
|
||||
@@ -135,10 +213,11 @@ function(version)
|
||||
# Do we have the pre-release component, and is it valid?
|
||||
if(DEFINED _ARGS_PRERELEASE)
|
||||
string(STRIP "${_ARGS_PRERELEASE}" _ARGS_PRERELEASE)
|
||||
list(JOIN _ARGS_PRERELEASE "." _ARGS_PRERELEASE)
|
||||
if(_ARGS_PRERELEASE STREQUAL "")
|
||||
unset(_ARGS_PRERELEASE)
|
||||
elseif(_ARGS_PRERELEASE MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]])
|
||||
if(_ARGS_COMPRESS AND (_ARGS_PRERELEASE MATCHES [[[a-zA-Z]+[a-zA-Z0-9\\-\\.]*$]]))
|
||||
if(_ARGS_COMPRESS AND (_ARGS_PRERELEASE MATCHES [[[a-zA-Z]+[a-zA-Z0-9\-\.]*$]]))
|
||||
set(_ "${_}${_ARGS_PRERELEASE}")
|
||||
else()
|
||||
set(_ "${_}-${_ARGS_PRERELEASE}")
|
||||
@@ -152,6 +231,7 @@ function(version)
|
||||
# Do we have the build component, and is it valid?
|
||||
if(DEFINED _ARGS_BUILD)
|
||||
string(STRIP "${_ARGS_BUILD}" _ARGS_PRERELEASE)
|
||||
list(JOIN _ARGS_BUILD "." _ARGS_BUILD)
|
||||
if(_ARGS_BUILD STREQUAL "")
|
||||
unset(_ARGS_BUILD)
|
||||
elseif(_ARGS_BUILD MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]*$]])
|
||||
|
||||
Reference in New Issue
Block a user