-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageConfigVersion.cmake_proto
212 lines (179 loc) · 10 KB
/
PackageConfigVersion.cmake_proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
set( @_PACKAGE_NAME_UPPER@_VERSION_TYPE "@_VERSION_TYPE@" )
set( @_PACKAGE_NAME_UPPER@_VERSION_NAME "@_VERSION_NAME@" )
set( @_PACKAGE_NAME_UPPER@_VERSION_MAJOR @_VERSION_MAJOR@ )
set( @_PACKAGE_NAME_UPPER@_VERSION_MINOR @_VERSION_MINOR@ )
set( @_PACKAGE_NAME_UPPER@_VERSION_PATCH @_VERSION_PATCH@ )
set( @_PACKAGE_NAME_UPPER@_VERSION_TWEAK @_VERSION_TWEAK@ )
set( @_PACKAGE_NAME_UPPER@_VERSION_HWARCH "@VISTA_HWARCH@" )
set( @_PACKAGE_NAME_UPPER@_VERSION "@_VERSION@" )
set( @_PACKAGE_NAME_UPPER@_VERSION_EXT "@_VERSION_EXT@" )
# we store the root dir in order to check if a new installation should delete this one
if( "${PACKAGE_FIND_VERSION}" STREQUAL "" AND "${PACKAGE_FIND_VERSION_EXT}" STREQUAL "" )
# no version given - just accept
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE TRUE )
set( PACKAGE_VERSION_UNSUITABLE FALSE )
else()
# a special macro for loading the the custom versioned file, since luckily CMakes versioning can
# handle just nothing but versions like 2.3.11.42 - absolutely perfect for development versions and branching
# we'd prefer to have the option to use find_package with a more elaborate versioning, including HEAD/TAG/BRANCHNAMES
# and version ranges
# if the versionmatches, the flag is NOT ALTERED! but only set to FALSE if it fails
macro( _local_check_valid_subversion INPUT_SUBVERSION OWN_SUBVERSION ALLOW_COMPATIBLE_ON_LOWER )
if( "${INPUT_SUBVERSION}" STREQUAL "" OR "${OWN_SUBVERSION}" STREQUAL "" )
# fine for us, just accept
elseif( "${INPUT_SUBVERSION}" STREQUAL "" OR "${OWN_SUBVERSION}" STREQUAL "" )
# exact match
elseif( ALLOW_COMPATIBLE_ON_LOWER AND ${INPUT_SUBVERSION} VERSION_LESS ${OWN_SUBVERSION} )
# compatible match
set( PACKAGE_VERSION_EXACT FALSE )
else()
#check if it is NUMBER+ - anything equal or bigger to number
string( REGEX MATCH "([0-9]+)\\+$" _STRING_IS_MIN ${INPUT_SUBVERSION} )
if( _STRING_IS_MIN )
if( ${OWN_SUBVERSION} LESS CMAKE_MATCH_1 )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( ${OWN_SUBVERSION} LESS CMAKE_MATCH_1 )
else( _STRING_IS_MIN )
#check if it is NUMBER-NUMBER - an explicit range
string( REGEX MATCH "([0-9]+)\\-([0-9]+)$" _STRING_IS_RANGE ${INPUT_SUBVERSION} )
if( _STRING_IS_RANGE )
if( NOT ( ${OWN_SUBVERSION} EQUAL CMAKE_MATCH_1 ) OR ( ${OWN_SUBVERSION} GREATER CMAKE_MATCH_1 ) )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
elseif( NOT ( ${OWN_SUBVERSION} EQUAL CMAKE_MATCH_1 ) OR ( ${OWN_SUBVERSION} GREATER CMAKE_MATCH_1 ) )
if( ( ${OWN_SUBVERSION} EQUAL CMAKE_MATCH_2 ) OR ( ${OWN_SUBVERSION} LESS CMAKE_MATCH_2 ) )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( ( ${OWN_SUBVERSION} EQUAL CMAKE_MATCH_2 ) OR ( ${OWN_SUBVERSION} LESS CMAKE_MATCH_2 ) )
endif( NOT ( ${OWN_SUBVERSION} EQUAL CMAKE_MATCH_1 ) OR ( ${OWN_SUBVERSION} GREATER CMAKE_MATCH_1 ) )
else( _STRING_IS_RANGE )
# check if it is just a numer
if( NOT ${INPUT_SUBVERSION} EQUAL ${OWN_SUBVERSION} )
set( PACKAGE_VERSION_EXACT FALSE )
if( NOT ALLOW_COMPATIBLE_ON_LOWER OR ${INPUT_SUBVERSION} GREATER ${OWN_SUBVERSION} )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( NOT ALLOW_COMPATIBLE_ON_LOWER OR ${INPUT_SUBVERSION} GREATER ${OWN_SUBVERSION} )
endif( NOT ${INPUT_SUBVERSION} EQUAL ${OWN_SUBVERSION} )
endif( _STRING_IS_RANGE )
endif( _STRING_IS_MIN )
endif( "${INPUT_SUBVERSION}" STREQUAL "" OR "${OWN_SUBVERSION}" STREQUAL "" )
endmacro( _local_check_valid_subversion )
macro( _local_extract_part _TARGET _ENTRY _SEPARATOR )
set( ${_TARGET} )
if( _REMAINING_VERSION )
string( REGEX MATCH "^(${_ENTRY})${_SEPARATOR}(.*)$" _MATCH_SUCCESS ${_REMAINING_VERSION} )
if( _MATCH_SUCCESS )
# we found a textual start -> type
set( ${_TARGET} ${CMAKE_MATCH_1} )
set( _REMAINING_VERSION ${CMAKE_MATCH_2} )
else( _MATCH_SUCCESS )
string( REGEX MATCH "^(${_ENTRY})$" _MATCH2_SUCCESS ${_REMAINING_VERSION} )
if( _MATCH2_SUCCESS )
# we found a textual start -> type
set( ${_TARGET} ${CMAKE_MATCH_1} )
set( _REMAINING_VERSION ${CMAKE_MATCH_2} )
endif( _MATCH2_SUCCESS )
endif( _MATCH_SUCCESS )
endif( _REMAINING_VERSION )
endmacro( _local_extract_part _TARGET _ENTRY _SEPARATOR )
if( NOT PACKAGE_FIND_VERSION_EXT )
set( PACKAGE_VERSION "${@_PACKAGE_NAME_UPPER@_VERSION}" )
# the cmake native versioning system: just allows an exact match with MAJOR.MINOR.PATCH - just works for releases!
if( @_PACKAGE_NAME_UPPER@_VERSION_TYPE STREQUAL "RELEASE" )
set( PACKAGE_VERSION_EXACT TRUE )
set( PACKAGE_VERSION_COMPATIBLE TRUE )
set( PACKAGE_VERSION_UNSUITABLE FALSE )
if( NOT PACKAGE_FIND_VERSION_MAJOR VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_MAJOR )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( NOT PACKAGE_FIND_VERSION_MAJOR VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_MAJOR )
if( PACKAGE_FIND_VERSION_COUNT GREATER 1 )
if( NOT PACKAGE_FIND_VERSION_MINOR VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_MINOR )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( NOT PACKAGE_FIND_VERSION_MINOR VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_MINOR )
endif( PACKAGE_FIND_VERSION_COUNT GREATER 1 )
if( PACKAGE_FIND_VERSION_COUNT GREATER 2 )
if( NOT PACKAGE_FIND_VERSION_PATCH VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_PATCH )
set( PACKAGE_VERSION_EXACT FALSE )
if( NOT PACKAGE_FIND_VERSION_PATCH VERSION_LESS @_PACKAGE_NAME_UPPER@_VERSION_PATCH )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( NOT PACKAGE_FIND_VERSION_PATCH VERSION_LESS @_PACKAGE_NAME_UPPER@_VERSION_PATCH )
endif( NOT PACKAGE_FIND_VERSION_PATCH VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_PATCH )
endif( PACKAGE_FIND_VERSION_COUNT GREATER 2 )
if( PACKAGE_FIND_VERSION_COUNT GREATER 3 )
if( NOT PACKAGE_FIND_VERSION_TWEAK VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_TWEAK )
set( PACKAGE_VERSION_EXACT FALSE )
if( NOT PACKAGE_FIND_VERSION_TWEAK VERSION_LESS @_PACKAGE_NAME_UPPER@_VERSION_TWEAK )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( NOT PACKAGE_FIND_VERSION_TWEAK VERSION_LESS @_PACKAGE_NAME_UPPER@_VERSION_TWEAK )
endif( NOT PACKAGE_FIND_VERSION_TWEAK VERSION_EQUAL @_PACKAGE_NAME_UPPER@_VERSION_TWEAK )
endif( PACKAGE_FIND_VERSION_COUNT GREATER 3 )
else( @_PACKAGE_NAME_UPPER@_VERSION_TYPE STREQUAL "RELEASE" )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
set( PACKAGE_VERSION_UNSUITABLE TRUE )
endif( @_PACKAGE_NAME_UPPER@_VERSION_TYPE STREQUAL "RELEASE" )
else( NOT PACKAGE_FIND_VERSION_EXT )
set( PACKAGE_VERSION "${@_PACKAGE_NAME_UPPER@_VERSION_EXT}" )
# first, we decompose the input
set( _REMAINING_VERSION ${PACKAGE_FIND_VERSION_EXT} )
_local_extract_part( _IN_TYPE "[a-zA-Z]+" "_" )
if( NOT _IN_TYPE STREQUAL "HEAD"
AND NOT _IN_TYPE STREQUAL "RELEASE"
AND NOT _IN_TYPE STREQUAL "BRANCH"
AND NOT _IN_TYPE STREQUAL "TRUNK" )
set( _IN_TYPE )
set( _REMAINING_VERSION ${PACKAGE_FIND_VERSION_EXT} )
endif( NOT _IN_TYPE STREQUAL "HEAD"
AND NOT _IN_TYPE STREQUAL "RELEASE"
AND NOT _IN_TYPE STREQUAL "BRANCH"
AND NOT _IN_TYPE STREQUAL "TRUNK" )
_local_extract_part( _IN_NAME "[a-zA-Z][^\\\\-]+" "\\\\-" )
_local_extract_part( _IN_MAJOR "[0-9\\\\+\\\\-]+" "\\\\." )
_local_extract_part( _IN_MINOR "[0-9\\\\+\\\\-]+" "\\\\." )
_local_extract_part( _IN_PATCH "[0-9\\\\+\\\\-]+" "\\\\." )
_local_extract_part( _IN_TWEAK "[0-9\\\\+\\\\-]+" "$" )
#we assume match, and only change this if we find non-matches
set( PACKAGE_VERSION_EXACT TRUE )
set( PACKAGE_VERSION_COMPATIBLE TRUE )
set( PACKAGE_VERSION_UNSUITABLE FALSE )
#if there is just one entry, it's the name
if( _IN_TYPE AND NOT _IN_NAME AND NOT _IN_MAJOR )
set( _IN_NAME ${_IN_TYPE} )
set( _IN_TYPE "" )
endif( _IN_TYPE AND NOT _IN_NAME AND NOT _IN_MAJOR )
if( NOT _IN_TYPE OR _IN_TYPE STREQUAL @_PACKAGE_NAME_UPPER@_VERSION_TYPE )
# in case of releases, we don't need a name
if( NOT _IN_NAME AND @_PACKAGE_NAME_UPPER@_VERSION_TYPE STREQUAL "RELEASE" )
set( _IN_NAME ${@_PACKAGE_NAME_UPPER@_VERSION_NAME} )
endif( NOT _IN_NAME AND @_PACKAGE_NAME_UPPER@_VERSION_TYPE STREQUAL "RELEASE" )
# in case of head, either type or name has to be head
if( _IN_TYPE STREQUAL "HEAD" AND NOT _IN_NAME )
set( _IN_NAME "HEAD" )
endif( _IN_TYPE STREQUAL "HEAD" AND NOT _IN_NAME )
#check name
if( NOT _IN_NAME STREQUAL @_PACKAGE_NAME_UPPER@_VERSION_NAME )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
else( NOT _IN_NAME STREQUAL @_PACKAGE_NAME_UPPER@_VERSION_NAME )
#check versions - these automatically adjust PACKAGE_VERSION_EXACT and PACKAGE_VERSION_COMPATIBLE
_local_check_valid_subversion( "${_IN_MAJOR}" "${@_PACKAGE_NAME_UPPER@_VERSION_MAJOR}" FALSE )
_local_check_valid_subversion( "${_IN_MINOR}" "${@_PACKAGE_NAME_UPPER@_VERSION_MINOR}" FALSE )
_local_check_valid_subversion( "${_IN_PATCH}" "${@_PACKAGE_NAME_UPPER@_VERSION_PATCH}" TRUE )
_local_check_valid_subversion( "${_IN_TWEAK}" "${@_PACKAGE_NAME_UPPER@_VERSION_TWEAK}" TRUE )
endif( NOT _IN_NAME STREQUAL @_PACKAGE_NAME_UPPER@_VERSION_NAME )
else( NOT _IN_TYPE OR _IN_TYPE STREQUAL @_PACKAGE_NAME_UPPER@_VERSION_TYPE )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
endif( NOT _IN_TYPE OR _IN_TYPE STREQUAL @_PACKAGE_NAME_UPPER@_VERSION_TYPE )
endif( NOT PACKAGE_FIND_VERSION_EXT )
endif( "${PACKAGE_FIND_VERSION}" STREQUAL "" AND "${PACKAGE_FIND_VERSION_EXT}" STREQUAL "" )
# finally: verify that the HWARCH is correct (if the var exists)
if( VISTA_HWARCH AND NOT "${VISTA_HWARCH}" STREQUAL "${@_PACKAGE_NAME_UPPER@_VERSION_HWARCH}" )
set( PACKAGE_VERSION_EXACT FALSE )
set( PACKAGE_VERSION_COMPATIBLE FALSE )
set( PACKAGE_VERSION_UNSUITABLE TRUE )
endif( VISTA_HWARCH AND NOT "${VISTA_HWARCH}" STREQUAL "${@_PACKAGE_NAME_UPPER@_VERSION_HWARCH}" )