Merge topic 'if-version-depth'
dfa0ebd
if: Compare up to 8 components in VERSION tests
This commit is contained in:
commit
3e7fe5a7a0
|
@ -409,14 +409,18 @@ namespace
|
|||
enum Op { OpLess, OpEqual, OpGreater };
|
||||
bool HandleVersionCompare(Op op, const char* lhs_str, const char* rhs_str)
|
||||
{
|
||||
// Parse out up to 4 components.
|
||||
unsigned int lhs[4] = {0,0,0,0};
|
||||
unsigned int rhs[4] = {0,0,0,0};
|
||||
sscanf(lhs_str, "%u.%u.%u.%u", &lhs[0], &lhs[1], &lhs[2], &lhs[3]);
|
||||
sscanf(rhs_str, "%u.%u.%u.%u", &rhs[0], &rhs[1], &rhs[2], &rhs[3]);
|
||||
// Parse out up to 8 components.
|
||||
unsigned int lhs[8] = {0,0,0,0,0,0,0,0};
|
||||
unsigned int rhs[8] = {0,0,0,0,0,0,0,0};
|
||||
sscanf(lhs_str, "%u.%u.%u.%u.%u.%u.%u.%u",
|
||||
&lhs[0], &lhs[1], &lhs[2], &lhs[3],
|
||||
&lhs[4], &lhs[5], &lhs[6], &lhs[7]);
|
||||
sscanf(rhs_str, "%u.%u.%u.%u.%u.%u.%u.%u",
|
||||
&rhs[0], &rhs[1], &rhs[2], &rhs[3],
|
||||
&rhs[4], &rhs[5], &rhs[6], &rhs[7]);
|
||||
|
||||
// Do component-wise comparison.
|
||||
for(unsigned int i=0; i < 4; ++i)
|
||||
for(unsigned int i=0; i < 8; ++i)
|
||||
{
|
||||
if(lhs[i] < rhs[i])
|
||||
{
|
||||
|
|
|
@ -7,3 +7,10 @@ if("${CMAKE_VERSION}" VERSION_LESS "${min_ver}")
|
|||
else()
|
||||
message("CMAKE_VERSION=[${CMAKE_VERSION}] is not less than [${min_ver}]")
|
||||
endif()
|
||||
|
||||
set(v 1.2.3.4.5.6.7)
|
||||
if("${v}.8" VERSION_LESS "${v}.9")
|
||||
message(STATUS "${v}.8 is less than ${v}.9")
|
||||
else()
|
||||
message(FATAL_ERROR "${v}.8 is not less than ${v}.9?")
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue