blob: 0fddab6e0a7031089b066f8208bc82b49582a791 (
plain)
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
|
set(min_ver 2.7.20090305)
cmake_minimum_required(VERSION ${min_ver})
if("${CMAKE_VERSION}" VERSION_LESS "${min_ver}")
message(FATAL_ERROR
"CMAKE_VERSION=[${CMAKE_VERSION}] is less than [${min_ver}]")
else()
message("CMAKE_VERSION=[${CMAKE_VERSION}] is not less than [${min_ver}]")
endif()
set(EQUALV "1 1")
list(APPEND EQUALV "1.0 1")
list(APPEND EQUALV "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0 1")
list(APPEND EQUALV "1.2.3.4.5.6.7 1.2.3.4.5.6.7")
list(APPEND EQUALV "1.2.3.4.5.6.7.8.9 1.2.3.4.5.6.7.8.9")
foreach(v IN LISTS EQUALV)
string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
# modify any of the operands to see the negative check also works
if("${CMAKE_MATCH_1}.2" VERSION_EQUAL CMAKE_MATCH_2)
message(FATAL_ERROR "${CMAKE_MATCH_1}.2 is equal ${CMAKE_MATCH_2}?")
else()
message(STATUS "${CMAKE_MATCH_1}.2 is not equal ${CMAKE_MATCH_2}")
endif()
if(CMAKE_MATCH_1 VERSION_EQUAL "${CMAKE_MATCH_2}.2")
message(FATAL_ERROR "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}.2?")
else()
message(STATUS "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}.2")
endif()
endforeach()
# test the negative outcomes first, due to the implementation the positive
# allow some additional strings to pass that would not fail for the negative
# tests
list(APPEND EQUALV "1a 1")
list(APPEND EQUALV "1.1a 1.1")
list(APPEND EQUALV "1.0a 1")
list(APPEND EQUALV "1a 1.0")
list(APPEND EQUALV "1a1 1")
list(APPEND EQUALV "1.1a1 1.1")
list(APPEND EQUALV "1.0a1 1")
list(APPEND EQUALV "1a1 1.0")
list(APPEND EQUALV "1-suffix 1")
list(APPEND EQUALV "1.1-suffix 1.1")
list(APPEND EQUALV "1.0-suffix 1")
list(APPEND EQUALV "1-suffix 1.0")
list(APPEND EQUALV "1-suffix.1 1")
list(APPEND EQUALV "1.1-suffix.1 1.1")
list(APPEND EQUALV "1.0-suffix.1 1")
list(APPEND EQUALV "1-suffix.1 1.0")
foreach(v IN LISTS EQUALV)
string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
# check equal versions
if(CMAKE_MATCH_1 VERSION_EQUAL CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}?")
endif()
# still equal, but inverted order of operands
if(CMAKE_MATCH_2 VERSION_EQUAL CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is equal ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is not equal ${CMAKE_MATCH_1}?")
endif()
# check less or equal
if(CMAKE_MATCH_1 VERSION_LESS_EQUAL CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}")
endif()
# check less or equal, inverted order of operands
if(CMAKE_MATCH_2 VERSION_LESS_EQUAL CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is equal ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is not equal ${CMAKE_MATCH_1}")
endif()
# check greater or equal
if(CMAKE_MATCH_1 VERSION_GREATER_EQUAL CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}")
endif()
# check greater or equal, inverted order of operands
if(CMAKE_MATCH_2 VERSION_GREATER_EQUAL CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is equal ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is not equal ${CMAKE_MATCH_1}")
endif()
# check less
if(NOT CMAKE_MATCH_1 VERSION_LESS CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is not less than ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is less than ${CMAKE_MATCH_2}")
endif()
# check less, inverted order of operands
if(NOT CMAKE_MATCH_2 VERSION_LESS CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is not less than ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is less than ${CMAKE_MATCH_1}")
endif()
# check greater
if(NOT CMAKE_MATCH_1 VERSION_GREATER CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is not greater than ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is greater than ${CMAKE_MATCH_2}")
endif()
# check greater, inverted order of operands
if(NOT CMAKE_MATCH_2 VERSION_GREATER CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is not greater than ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is greater than ${CMAKE_MATCH_1}")
endif()
endforeach()
set(LESSV "1.2.3.4.5.6.7.8 1.2.3.4.5.6.7.9")
list(APPEND LESSV "1.2.3.4.5.6.7 1.2.3.4.5.6.7.9")
list(APPEND LESSV "1 1.0.0.1")
list(APPEND LESSV "1 2a")
list(APPEND LESSV "1a 2")
list(APPEND LESSV "1 2a1")
list(APPEND LESSV "1a1 2")
list(APPEND LESSV "1 2-suffix")
list(APPEND LESSV "1-suffix 2")
list(APPEND LESSV "1 2-suffix.1")
list(APPEND LESSV "1-suffix.1 2")
foreach(v IN LISTS LESSV)
string(REGEX MATCH "(.*) (.*)" _dummy "${v}")
# check less
if(CMAKE_MATCH_1 VERSION_LESS CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is less than ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is not less than ${CMAKE_MATCH_2}?")
endif()
# check greater
if(CMAKE_MATCH_2 VERSION_GREATER CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is greater than ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is not greater than ${CMAKE_MATCH_1}?")
endif()
# check less negative case
if(NOT CMAKE_MATCH_2 VERSION_LESS CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is not less than ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is less than ${CMAKE_MATCH_1}?")
endif()
# check greater or equal (same as less negative)
if(CMAKE_MATCH_2 VERSION_GREATER_EQUAL CMAKE_MATCH_1)
message(STATUS "${CMAKE_MATCH_2} is not less than ${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_2} is less than ${CMAKE_MATCH_1}?")
endif()
# check greater negative case
if(NOT CMAKE_MATCH_1 VERSION_GREATER CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is not greater than ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is greater than ${CMAKE_MATCH_2}?")
endif()
# check less or equal (same as greater negative) case
if(CMAKE_MATCH_1 VERSION_LESS_EQUAL CMAKE_MATCH_2)
message(STATUS "${CMAKE_MATCH_1} is not greater than ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "${CMAKE_MATCH_1} is greater than ${CMAKE_MATCH_2}?")
endif()
endforeach()
|