2022-07-04 03:09:56 +02:00
# Copyright (C) 2022, Michael Fabian 'Xaymar' Dirks <info@xaymar.com>. All Rights Reserved
#
# 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.
2022-07-04 07:47:10 +02:00
#[=======================================================================[.rst:
v e r s i o n
- - - - - - -
G e n e r a t e , p a r s e a n d m o d i f y v e r s i o n s p u r e l y w i t h C M a k e . S u p p o r t s S e m a n t i c V e r s i o n i n g 2 . 0 . 0 , 1 . 0 . 0 a n d o t h e r v e r s i o n f o r m a t s .
S y n o p s i s
^ ^ ^ ^ ^ ^ ^ ^
. . p a r s e d - l i t e r a l : :
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> )
T h e f o l l o w i n g v e r s i o n c o n s t r u c t s a r e c u r r e n t l y s u p p o r t e d :
. . c o d e - b l o c k : :
< m a j o r > " . " < m i n o r > [ " . " < p a t c h > [ " . " < t w e a k > ] ]
< m a j o r > " . " < m i n o r > [ " . " < p a t c h > [ " . " < t w e a k > ] ] [ [ " - " ] < p r e - r e l e a s e > ] [ " + " < b u i l d > ]
P a r s i n g
^ ^ ^ ^ ^ ^ ^
. . _ P A R S E :
. . c o d e - b l o c k : : c m a k e
version ( PARSE <out-var> <string> )
A t t e m p t s t o p a r s e t h e v e r s i o n i n ` ` < s t r i n g > ` ` a n d s t o r e s t h e i n d i v i d u a l c o m p o e n t s i n t o ` ` < o u t - v a r > _ < c o m p o n e n t > ` ` . I f a c o m p o n e n t i s n o t p r e s e n t i n t h e g i v e n v e r s i o n , i t w i l l b e u n d e f i n e d . I f a n e r r o r o c c u r r e d , ` ` < o u t - v a r > _ E R R O R ` ` w i l l b e d e f i n e d a n d c o n t a i n t h e e r r o r m e s s a g e .
G e n e r a t i n g
^ ^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ G E N E R A T E :
. . c o d e - b l o c k : : c m a k e
version ( GENERATE <out-var> [COMPRESS] [MAJOR <major>] [MINOR <minor>] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] )
G e n e r a t e s a v e r s i o n f r o m t h e c o m p o n e n t s p r o v i d e d a n d s t o r e s t h e r e s u l t i n ` ` < o u t - v a r > ` ` . T h e c o m p o n e n t s ` ` < m a j o r > ` ` a n d ` ` < m i n o r > ` ` w i l l d e f a u l t t o ` ` 0 ` ` i f n o t p r o v i d e d . I f a n e r r o r o c c u r r e d , ` ` < o u t - v a r > _ E R R O R ` ` w i l l b e d e f i n e d a n d c o n t a i n t h e e r r o r m e s s a g e .
M o d i f y i n g
^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ M O D I F Y :
. . c o d e - b l o c k : : c m a k e
version ( MODIFY <out-var> <string> [COMPRESS] [MAJOR <major>] [MINOR <minor] [PATCH <patch>] [TWEAK <tweak>] [PRERELEASE <prerelease>] [BUILD <build>] )
M o d i f i e s t h e v e r s i o n p r o v i d e d i n ` ` < s t r i n g > ` ` w i t h t h e c o m p o n e n t s p r o v i d e d . T h e c o m p o n e n t s ` ` < m a j o r > ` ` , ` ` < m i n o r > ` ` , ` ` < p a t c h > ` ` a n d ` ` < t w e a k > ` ` m a y h a v e a p r e f i x o f ` ` + ` ` o r ` ` - ` ` t o a d d a n d s u b t r a c t t h e v a l u e , o r n o p r e f i x t o r e p l a c e . T h e r e s u l t o f t h i s o p e r a t i o n w i l l b e s t o r e d a s a s t r i n g i n ` ` < o u t - v a r > ` ` . I f a c o m p o n e n t d i d n o t e x i s t i n t h e o r i g i n a l , i t w i l l b e a d d e d t o t h e v e r s i o n a s a r e p l a c e o p e r a t i o n . I f a n e r r o r o c c u r r e d , ` ` < o u t - v a r > _ E R R O R ` ` w i l l b e d e f i n e d a n d c o n t a i n t h e e r r o r m e s s a g e .
C o m p a r i n g
^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ C O M P A R E :
. . c o d e - b l o c k : : c m a k e
version ( COMPARE <out-var> <a> <b> )
C o m p a r e s t h e v e r s i o n ` ` < a > ` ` a g a i n s t ` ` < b > ` ` a n d s t o r e s t h e r e s u l t i n ` ` < o u t - v a r > ` ` . T h e p r o v i d e d v e r s i o n w i l l b e e v a l u a t e d i n t h e o r d e r M A J O R , M I N O R , P A T C H , T W E A K , P R E R E L E A S E , a n d t h e n B U I L D . T h e f o l l o w i n g r e s u l t s s h o u l d b e e x p e c t e d :
- I f a c o m p o n e n t i s o n l y i n ` ` < a > ` ` , ` ` < o u t - v a r > ` ` w i l l c o n t a i n t h e c o m p o n e n e n t n a m e p r e f i x e d b y ` ` + ` ` .
- I f a c o m p o n e n t i s o n l y i n ` ` < b > ` ` , ` ` < o u t - v a r > ` ` w i l l c o n t a i n t h e c o m p o n e n e n t n a m e p r e f i x e d b y ` ` - ` ` .
- I f a c o m p o n e n t i s n u m e r i c a l a n d t h e v a l u e i s l a r g e r i n ` ` < a > ` ` , ` ` < o u t - v a r > ` ` w i l l c o n t a i n t h e c o m p o n e n e n t n a m e p r e f i x e d b y ` ` > ` ` .
- I f a c o m p o n e n t i s n u m e r i c a l a n d t h e v a l u e i s l a r g e r i n ` ` < b > ` ` , ` ` < o u t - v a r > ` ` w i l l c o n t a i n t h e c o m p o n e n e n t n a m e p r e f i x e d b y ` ` < ` ` .
- I f a c o m p o n e n t i s a l p h a n u m e r i c a l a n d t h e v a l u e i s d i f f e r e n t i n e i t h e r , ` ` < o u t - v a r > ` ` w i l l c o n t a i n t h e c o m p o n e n t n a m e w i t h n o p r e f i x .
- I n a l l o t h e r c a s e s , ` ` < o u t - v a r > ` ` w i l l b e e m p t y .
- I f a n e r r o r o c c u r r e d , ` ` < o u t - v a r > _ E R R O R ` ` w i l l b e d e f i n e d a n d c o n t a i n t h e e r r o r m e s s a g e , a n d ` ` < o u t - v a r > ` ` w i l l b e u n d e f i n e d .
#]=======================================================================]
2022-07-04 03:09:56 +02:00
function ( version )
2022-07-05 01:01:58 +02:00
# CMake functions do not have their own proper scope, they act more
2022-07-04 03:09:56 +02:00
set ( OUT_VAR "${ARGV1}" )
2022-07-05 01:01:58 +02:00
# Force clean parent elements.
set ( ${ OUT_VAR } _ERROR "" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
string ( TOUPPER "${ARGV0}" ARGV0 )
if ( ARGV0 STREQUAL "PARSE" )
# <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 )
return ( )
endif ( )
# {1} = Major
set ( ${ OUT_VAR } _MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE )
# {2} = Minor
set ( ${ OUT_VAR } _MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE )
# {3} = Patch
2022-07-05 22:22:58 +02:00
if ( ( DEFINED CMAKE_MATCH_3 ) AND ( NOT "${CMAKE_MATCH_3}" STREQUAL "" ) )
2022-07-04 03:09:56 +02:00
string ( SUBSTRING "${CMAKE_MATCH_3}" 1 -1 _TMP )
set ( ${ OUT_VAR } _PATCH "${_TMP}" PARENT_SCOPE )
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _PATCH "" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
endif ( )
# {4} = Tweak
2022-07-05 22:22:58 +02:00
if ( ( DEFINED CMAKE_MATCH_4 ) AND ( NOT "${CMAKE_MATCH_4}" STREQUAL "" ) )
2022-07-04 03:09:56 +02:00
string ( SUBSTRING "${CMAKE_MATCH_4}" 1 -1 _TMP )
set ( ${ OUT_VAR } _TWEAK "${_TMP}" PARENT_SCOPE )
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _TWEAK "" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
endif ( )
# {5} = PreRelease
2022-07-05 22:22:58 +02:00
if ( ( DEFINED CMAKE_MATCH_5 ) AND ( NOT "${CMAKE_MATCH_5}" STREQUAL "" ) )
2022-07-04 22:32:35 +02:00
string ( REPLACE "." ";" CMAKE_MATCH_5 "${CMAKE_MATCH_5}" ) # Handle dot separation as list.
2022-07-04 03:09:56 +02:00
string ( SUBSTRING "${CMAKE_MATCH_5}" 0 1 _TMP )
if ( _TMP STREQUAL "-" )
2022-07-04 22:32:35 +02:00
string ( SUBSTRING "${CMAKE_MATCH_5}" 1 -1 CMAKE_MATCH_5 )
set ( ${ OUT_VAR } _PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
else ( )
set ( ${ OUT_VAR } _PRERELEASE "${CMAKE_MATCH_5}" PARENT_SCOPE )
endif ( )
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _PRERELEASE "" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
endif ( )
# {6} = Build
2022-07-05 22:22:58 +02:00
if ( ( DEFINED CMAKE_MATCH_6 ) AND ( NOT "${CMAKE_MATCH_6}" STREQUAL "" ) )
2022-07-04 22:32:35 +02:00
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 )
2022-07-04 03:09:56 +02:00
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _BUILD "" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
endif ( )
elseif ( ARGV0 STREQUAL "GENERATE" )
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "" )
set ( _32070faa "" )
set ( _32070faa_MAJOR "" )
set ( _32070faa_MINOR "" )
set ( _32070faa_PATCH "" )
set ( _32070faa_TWEAK "" )
set ( _32070faa_PRERELEASE "" )
set ( _32070faa_BUILD "" )
set ( _32070faa_ERROR "" )
2022-07-04 03:09:56 +02:00
cmake_parse_arguments (
PARSE_ARGV 2
2022-07-05 01:01:58 +02:00
_32070faa
2022-07-04 03:09:56 +02:00
"COMPRESS"
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
""
)
# Do we have the major component, and is it valid?
2022-07-05 22:22:58 +02:00
if ( NOT "${_32070faa_MAJOR}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
string ( STRIP "${_32070faa_MAJOR}" _32070faa_MAJOR )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_MAJOR}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _32070faa_MAJOR 0 )
elseif ( NOT ( _32070faa_MAJOR MATCHES [[^[0-9]+ $ ]] ) )
set ( ${ OUT_VAR } _ERROR "MAJOR component must be a numeric identifier, but is: '${_32070faa_MAJOR}'" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
else ( )
2022-07-05 01:01:58 +02:00
set ( _32070faa_MAJOR 0 )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "${_feeb1eff}${_32070faa_MAJOR}" )
2022-07-04 03:09:56 +02:00
# Do we have the minor component, and is it valid?
2022-07-05 22:22:58 +02:00
if ( NOT "${_32070faa_MINOR}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
string ( STRIP "${_32070faa_MINOR}" _32070faa_MINOR )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_MINOR}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _32070faa_MINOR 0 )
elseif ( NOT ( _32070faa_MINOR MATCHES [[^[0-9]+ $ ]] ) )
set ( ${ OUT_VAR } _ERROR "MINOR component must be a numeric identifier, but is: '${_32070faa_MINOR}'" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
else ( )
2022-07-05 01:01:58 +02:00
set ( _32070faa_MINOR 0 )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "${_feeb1eff}.${_32070faa_MINOR}" )
2022-07-04 03:09:56 +02:00
# Do we have the patch component, and is it valid?
2022-07-05 22:22:58 +02:00
if ( NOT "${_32070faa_PATCH}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
string ( STRIP "${_32070faa_PATCH}" _32070faa_PATCH )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_PATCH}" STREQUAL "" )
set ( _32070faa_PATCH "" )
2022-07-05 01:01:58 +02:00
elseif ( _32070faa_PATCH MATCHES [[^[0-9]+ $ ]] )
set ( _feeb1eff "${_feeb1eff}.${_32070faa_PATCH}" )
2022-07-04 03:09:56 +02:00
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _ERROR "PATCH component must be a numeric identifier, but is: '${_32070faa_PATCH}'" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
endif ( )
# Do we have the tweak component, and is it valid?
2022-07-05 22:22:58 +02:00
if ( NOT "${_32070faa_TWEAK}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
string ( STRIP "${_32070faa_TWEAK}" _32070faa_TWEAK )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_TWEAK}" STREQUAL "" )
set ( _32070faa_TWEAK "" )
2022-07-05 01:01:58 +02:00
elseif ( _32070faa_TWEAK MATCHES [[^[0-9]+ $ ]] )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_PATCH}" STREQUAL "" )
# Patch did not exist, so it is zero.
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "${_feeb1eff}.0" )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "${_feeb1eff}.${_32070faa_TWEAK}" )
2022-07-04 03:09:56 +02:00
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _ERROR "TWEAK component must be a numeric identifier, but is: '${_32070faa_TWEAK}'" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
endif ( )
# Do we have the pre-release component, and is it valid?
2022-07-05 22:22:58 +02:00
if ( NOT "${_32070faa_PRERELEASE}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
string ( STRIP "${_32070faa_PRERELEASE}" _32070faa_PRERELEASE )
list ( JOIN _32070faa_PRERELEASE "." _32070faa_PRERELEASE )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_PRERELEASE}" STREQUAL "" )
set ( _32070faa_PRERELEASE "" )
2022-07-05 01:01:58 +02:00
elseif ( _32070faa_PRERELEASE MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]* $ ]] )
2022-07-05 22:22:58 +02:00
if ( _32070faa_COMPRESS AND ( _32070faa_PRERELEASE MATCHES [[^[a-zA-Z]+[a-zA-Z0-9\-\.]* $ ]] ) )
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "${_feeb1eff}${_32070faa_PRERELEASE}" )
2022-07-04 03:09:56 +02:00
else ( )
2022-07-05 01:01:58 +02:00
set ( _feeb1eff "${_feeb1eff}-${_32070faa_PRERELEASE}" )
2022-07-04 03:09:56 +02:00
endif ( )
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _ERROR "PRERELEASE component must be an alphanumeric identifier, but is: '${_32070faa_PRERELEASE}'" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
endif ( )
# Do we have the build component, and is it valid?
2022-07-05 22:22:58 +02:00
if ( NOT "${_32070faa_BUILD}" STREQUAL "" )
string ( STRIP "${_32070faa_BUILD}" _32070faa_BUILD )
2022-07-05 01:01:58 +02:00
list ( JOIN _32070faa_BUILD "." _32070faa_BUILD )
2022-07-05 22:22:58 +02:00
if ( "${_32070faa_BUILD}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
unset ( _32070faa_BUILD )
elseif ( _32070faa_BUILD MATCHES [[^[a-zA-Z0-9]+[a-zA-Z0-9\-\.]* $ ]] )
set ( _feeb1eff "${_feeb1eff}+${_32070faa_BUILD}" )
2022-07-04 03:09:56 +02:00
else ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } _ERROR "BUILD component must be an alphanumeric identifier, but is: '${_32070faa_BUILD}'" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
endif ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } "${_feeb1eff}" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
elseif ( ARGV0 STREQUAL "MODIFY" )
# Requires PARSE and GENERATE.
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd "" )
set ( _fe7bcddd_MAJOR "" )
set ( _fe7bcddd_MINOR "" )
set ( _fe7bcddd_PATCH "" )
set ( _fe7bcddd_TWEAK "" )
set ( _fe7bcddd_PRERELEASE "" )
set ( _fe7bcddd_BUILD "" )
set ( _fe7bcddd_ERROR "" )
2022-07-04 03:09:56 +02:00
cmake_parse_arguments (
PARSE_ARGV 3
2022-07-05 01:01:58 +02:00
_fe7bcddd
2022-07-04 03:09:56 +02:00
"COMPRESS"
2022-07-05 01:01:58 +02:00
"MAJOR;MINOR;PATCH;TWEAK;PRERELEASE;BUILD"
2022-07-04 03:09:56 +02:00
""
)
# Helpers
macro ( modify_version_number )
2022-07-05 22:22:58 +02:00
if ( NOT ( "${${ARGV1}}" STREQUAL "" ) )
if ( "${${ARGV1}}" MATCHES "^(\\+|\\-)([0-9]+)$" )
if ( "${${ARGV0}}" STREQUAL "" )
2022-07-04 03:09:56 +02:00
math ( EXPR ${ ARGV0 } "0 ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}" )
2022-07-05 22:22:58 +02:00
else ( )
math ( EXPR ${ ARGV0 } "${${ARGV0}} ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}" )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 22:22:58 +02:00
else ( )
2022-07-04 03:09:56 +02:00
set ( ${ ARGV0 } "${${ARGV1}}" )
endif ( )
endif ( )
endmacro ( )
# Parse the given version.
2022-07-05 01:01:58 +02:00
set ( _df8abcce "" )
set ( _df8abcce_MAJOR "" )
set ( _df8abcce_MINOR "" )
set ( _df8abcce_PATCH "" )
set ( _df8abcce_TWEAK "" )
set ( _df8abcce_PRERELEASE "" )
set ( _df8abcce_BUILD "" )
set ( _df8abcce_ERROR "" )
version ( PARSE _df8abcce "${ARGV2}" )
if ( _df8abcce_ERROR )
set ( ${ OUT_VAR } _ERROR ${ _df8abcce_ERROR } PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
# Modify core version components
2022-07-05 01:01:58 +02:00
modify_version_number ( _df8abcce_MAJOR _fe7bcddd_MAJOR )
modify_version_number ( _df8abcce_MINOR _fe7bcddd_MINOR )
modify_version_number ( _df8abcce_PATCH _fe7bcddd_PATCH )
modify_version_number ( _df8abcce_TWEAK _fe7bcddd_TWEAK )
2022-07-04 03:09:56 +02:00
# Replace other components if defined.
2022-07-05 22:22:58 +02:00
if ( NOT "${_fe7bcddd_PRERELEASE}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _df8abcce_PRERELEASE "${_fe7bcddd_PRERELEASE}" )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 22:22:58 +02:00
if ( NOT "${_fe7bcddd_BUILD}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _df8abcce_BUILD "${_fe7bcddd_BUILD}" )
2022-07-04 03:09:56 +02:00
endif ( )
# Generate a new version.
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "" )
2022-07-05 22:22:58 +02:00
if ( NOT "${_df8abcce_MAJOR}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} MAJOR \" ${ _df8abcce_MAJOR } \"")
2022-07-04 03:09:56 +02:00
endif( )
2022-07-05 22:22:58 +02:00
if ( NOT "${_df8abcce_MINOR}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} MINOR \" ${ _df8abcce_MINOR } \"")
2022-07-04 03:09:56 +02:00
endif( )
2022-07-05 22:22:58 +02:00
if ( NOT "${_df8abcce_PATCH}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} PATCH \" ${ _df8abcce_PATCH } \"")
2022-07-04 03:09:56 +02:00
endif( )
2022-07-05 22:22:58 +02:00
if ( NOT "${_df8abcce_TWEAK}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} TWEAK \" ${ _df8abcce_TWEAK } \"")
2022-07-04 03:09:56 +02:00
endif( )
2022-07-05 22:22:58 +02:00
if ( NOT "${_df8abcce_PRERELEASE}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} PRERELEASE \" ${ _df8abcce_PRERELEASE } \"")
2022-07-04 03:09:56 +02:00
endif( )
2022-07-05 22:22:58 +02:00
if ( NOT "${_df8abcce_BUILD}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} BUILD \" ${ _df8abcce_BUILD } \"")
2022-07-04 03:09:56 +02:00
endif( )
2022-07-05 01:01:58 +02:00
if ( _fe7bcddd_COMPRESS )
set ( _fe7bcddd_GEN "${_fe7bcddd_GEN} COMPRESS" )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 01:01:58 +02:00
cmake_language ( EVAL CODE "version(GENERATE _df8abcce ${_fe7bcddd_GEN})" )
if ( _df8abcce_ERROR )
set ( ${ OUT_VAR } _ERROR ${ _df8abcce_ERROR } PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } "${_df8abcce}" PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
elseif ( ARGV0 STREQUAL "COMPARE" )
# Requires PARSE.
# Parse first version
2022-07-05 01:01:58 +02:00
set ( _00fdeadb "" )
set ( _00fdeadb_MAJOR "" )
set ( _00fdeadb_MINOR "" )
set ( _00fdeadb_PATCH "" )
set ( _00fdeadb_TWEAK "" )
set ( _00fdeadb_PRERELEASE "" )
set ( _00fdeadb_BUILD "" )
set ( _00fdeadb_ERROR "" )
version ( PARSE _00fdeadb "${ARGV2}" )
if ( _00fdeadb_ERROR )
set ( ${ OUT_VAR } _ERROR ${ _00fdeadb_ERROR } PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
# Parse second version
2022-07-05 01:01:58 +02:00
set ( _ca75feel "" )
set ( _ca75feel_MAJOR "" )
set ( _ca75feel_MINOR "" )
set ( _ca75feel_PATCH "" )
set ( _ca75feel_TWEAK "" )
set ( _ca75feel_PRERELEASE "" )
set ( _ca75feel_BUILD "" )
set ( _ca75feel_ERROR "" )
version ( PARSE _ca75feel "${ARGV3}" )
if ( _ca75feel_ERROR )
set ( ${ OUT_VAR } _ERROR ${ _ca75feel_ERROR } PARENT_SCOPE )
2022-07-04 03:09:56 +02:00
return ( )
endif ( )
# Major
2022-07-05 01:01:58 +02:00
if ( _00fdeadb_MAJOR GREATER _ca75feel_MAJOR )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } ">MAJOR" PARENT_SCOPE )
return ( )
2022-07-05 01:01:58 +02:00
elseif ( _00fdeadb_MAJOR LESS _ca75feel_MAJOR )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "<MAJOR" PARENT_SCOPE )
return ( )
endif ( )
# Minor
2022-07-05 01:01:58 +02:00
if ( _00fdeadb_MINOR GREATER _ca75feel_MINOR )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } ">MINOR" PARENT_SCOPE )
return ( )
2022-07-05 01:01:58 +02:00
elseif ( _00fdeadb_MINOR LESS _ca75feel_MINOR )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "<MINOR" PARENT_SCOPE )
return ( )
endif ( )
# Patch
2022-07-05 01:01:58 +02:00
if ( _00fdeadb_PATCH GREATER _ca75feel_PATCH )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } ">PATCH" PARENT_SCOPE )
return ( )
2022-07-05 01:01:58 +02:00
elseif ( _00fdeadb_PATCH LESS _ca75feel_PATCH )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "<PATCH" PARENT_SCOPE )
return ( )
2022-07-05 22:22:58 +02:00
elseif ( ( "${_00fdeadb_PATCH}" STREQUAL "" ) OR ( "${_ca75feel_PATCH}" STREQUAL "" ) )
if ( NOT "${_00fdeadb_PATCH}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } "+PATCH" PARENT_SCOPE )
return ( )
2022-07-05 22:22:58 +02:00
elseif ( NOT "${_ca75feel_PATCH}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } "-PATCH" PARENT_SCOPE )
return ( )
endif ( )
2022-07-04 03:09:56 +02:00
endif ( )
# Tweak
2022-07-05 01:01:58 +02:00
if ( _00fdeadb_TWEAK GREATER _ca75feel_TWEAK )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } ">TWEAK" PARENT_SCOPE )
return ( )
2022-07-05 01:01:58 +02:00
elseif ( _00fdeadb_TWEAK LESS _ca75feel_TWEAK )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "<TWEAK" PARENT_SCOPE )
return ( )
2022-07-05 22:22:58 +02:00
elseif ( ( "${_00fdeadb_TWEAK}" STREQUAL "" ) OR ( "${_ca75feel_TWEAK}" STREQUAL "" ) )
if ( NOT "${_00fdeadb_TWEAK}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } "+TWEAK" PARENT_SCOPE )
return ( )
2022-07-05 22:22:58 +02:00
elseif ( NOT "${_ca75feel_TWEAK}" STREQUAL "" )
2022-07-05 01:01:58 +02:00
set ( ${ OUT_VAR } "-TWEAK" PARENT_SCOPE )
return ( )
endif ( )
2022-07-04 03:09:56 +02:00
endif ( )
# Pre-Release
2022-07-05 22:22:58 +02:00
if ( ( "${_00fdeadb_PRERELEASE}" STREQUAL "" ) OR ( "${_ca75feel_PRERELEASE}" STREQUAL "" ) )
if ( NOT "${_00fdeadb_PRERELEASE}" STREQUAL "" )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "+PRERELEASE" PARENT_SCOPE )
2022-07-05 01:01:58 +02:00
return ( )
2022-07-05 22:22:58 +02:00
elseif ( NOT "${_ca75feel_PRERELEASE}" STREQUAL "" )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "-PRERELEASE" PARENT_SCOPE )
2022-07-05 01:01:58 +02:00
return ( )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 01:01:58 +02:00
elseif ( NOT ( _00fdeadb_PRERELEASE STREQUAL _ca75feel_PRERELEASE ) )
set ( ${ OUT_VAR } "PRERELEASE" PARENT_SCOPE )
return ( )
2022-07-04 03:09:56 +02:00
endif ( )
# Build
2022-07-05 22:22:58 +02:00
if ( ( "${_00fdeadb_BUILD}" STREQUAL "" ) OR ( "${_ca75feel_BUILD}" STREQUAL "" ) )
if ( NOT "${_00fdeadb_BUILD}" STREQUAL "" )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "+BUILD" PARENT_SCOPE )
2022-07-05 01:01:58 +02:00
return ( )
2022-07-05 22:22:58 +02:00
elseif ( NOT "${_ca75feel_BUILD}" STREQUAL "" )
2022-07-04 03:09:56 +02:00
set ( ${ OUT_VAR } "-BUILD" PARENT_SCOPE )
2022-07-05 01:01:58 +02:00
return ( )
2022-07-04 03:09:56 +02:00
endif ( )
2022-07-05 01:01:58 +02:00
elseif ( NOT ( _00fdeadb_BUILD STREQUAL _ca75feel_BUILD ) )
set ( ${ OUT_VAR } "BUILD" PARENT_SCOPE )
return ( )
2022-07-04 03:09:56 +02:00
endif ( )
# Both are exactly the same.
set ( ${ OUT_VAR } "" PARENT_SCOPE )
else ( )
message ( FATAL_ERROR "Unknown command '${ARGV0}'" )
return ( )
endif ( )
endfunction ( )