8 Commits

Author SHA1 Message Date
Michael Fabian 'Xaymar' Dirks 2b0699284a Version 1.0
- Supports Semantic Versioning 1.0.0, Semantic Versioning 2.0.0, CMake Versioning and mixtures of these.
- Functionality for parsing, modifying, generating and comparing.
2022-07-04 07:48:33 +02:00
Michael Fabian 'Xaymar' Dirks 9fe3d44d54 code: Add documentation to the file itself
This is a duplicate of index.rst, and should be considered secondary to the actual documentation at https://xaymar.github.io/cmake-version/.
2022-07-04 07:47:10 +02:00
Michael Fabian 'Xaymar' Dirks 208fb31040 ci: Automatically generate documentation 2022-07-04 07:43:09 +02:00
Michael Fabian 'Xaymar' Dirks c61e2cb2ce ci: Also run tests for pull requests 2022-07-04 07:10:13 +02:00
Michael Fabian 'Xaymar' Dirks e4313a31ad ci: Run tests on all branches, and on changes to the workflow 2022-07-04 07:07:56 +02:00
Michael Fabian 'Xaymar' Dirks f3d5d3956c docs: Reduce generated bloat
This is a single function, no need for more than the index
2022-07-04 06:51:00 +02:00
Michael Fabian 'Xaymar' Dirks 519fe4cc75 ci: Add automated testing 2022-07-04 06:48:30 +02:00
Michael Fabian 'Xaymar' Dirks 50e6f494af Add README and fix Copyright headers
This was written in 2022, not 2021. Still doesn't feel like a new year even started...
2022-07-04 05:41:47 +02:00
8 changed files with 299 additions and 86 deletions
+88
View File
@@ -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
+38
View File
@@ -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 -1
View File
@@ -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: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+18
View File
@@ -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
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 = "0.1" version = "1.0"
release = "0.1" release = "1.0"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
@@ -53,4 +53,4 @@ html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here, # 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, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = []
+74 -5
View File
@@ -1,7 +1,76 @@
Version handling for CMake version
========================================= -------
.. toctree:: Generate, parse and modify versions purely with CMake. Supports Semantic Versioning 2.0.0, 1.0.0 and other version formats.
:maxdepth: 1
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.
version
-76
View File
@@ -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.
+77 -1
View File
@@ -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. # 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) function(version)
unset(${OUT_VAR} PARENT_SCOPE) unset(${OUT_VAR} PARENT_SCOPE)