| 1 |
# This macro compares version numbers of the form "x.y.z" |
| 2 |
# MACRO_ENSURE_VERSION( FOO_MIN_VERSION FOO_VERSION_FOUND FOO_VERSION_OK) |
| 3 |
# will set FOO_VERSIN_OK to true if FOO_VERSION_FOUND >= FOO_MIN_VERSION |
| 4 |
# where both have to be in a 3-part-version format, leading and trailing |
| 5 |
# text is ok, e.g. |
| 6 |
# MACRO_ENSURE_VERSION( "2.5.31" "flex 2.5.4a" VERSION_OK) |
| 7 |
# which means 2.5.31 is required and "flex 2.5.4a" is what was found on the system |
| 8 |
|
| 9 |
# Copyright (c) 2006, David Faure, <[email protected]> |
| 10 |
# |
| 11 |
# Redistribution and use is allowed according to the terms of the BSD license. |
| 12 |
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 13 |
|
| 14 |
MACRO(MACRO_ENSURE_VERSION requested_version found_version var_too_old) |
| 15 |
|
| 16 |
# parse the parts of the version string |
| 17 |
STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" req_major_vers "${requested_version}") |
| 18 |
STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" req_minor_vers "${requested_version}") |
| 19 |
STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_patch_vers "${requested_version}") |
| 20 |
|
| 21 |
STRING(REGEX REPLACE "[^0-9]*([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" found_major_vers "${found_version}") |
| 22 |
STRING(REGEX REPLACE "[^0-9]*[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" found_minor_vers "${found_version}") |
| 23 |
STRING(REGEX REPLACE "[^0-9]*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" found_patch_vers "${found_version}") |
| 24 |
|
| 25 |
# compute an overall version number which can be compared at once |
| 26 |
MATH(EXPR req_vers_num "${req_major_vers}*10000 + ${req_minor_vers}*100 + ${req_patch_vers}") |
| 27 |
MATH(EXPR found_vers_num "${found_major_vers}*10000 + ${found_minor_vers}*100 + ${found_patch_vers}") |
| 28 |
|
| 29 |
if (found_vers_num LESS req_vers_num) |
| 30 |
set( ${var_too_old} FALSE ) |
| 31 |
else (found_vers_num LESS req_vers_num) |
| 32 |
set( ${var_too_old} TRUE ) |
| 33 |
endif (found_vers_num LESS req_vers_num) |
| 34 |
|
| 35 |
ENDMACRO(MACRO_ENSURE_VERSION) |
| 36 |
|
| 37 |
|
| 38 |
# This macro compares version numbers of the form "x.y" |
| 39 |
# MACRO_ENSURE_VERSION( FOO_MIN_VERSION FOO_VERSION_FOUND FOO_VERSION_OK) |
| 40 |
# will set FOO_VERSIN_OK to true if FOO_VERSION_FOUND >= FOO_MIN_VERSION |
| 41 |
# where both have to be in a 2-part-version format, leading and trailing |
| 42 |
# text is ok, e.g. |
| 43 |
# MACRO_ENSURE_VERSION( "0.5" "foo 0.6" VERSION_OK) |
| 44 |
# which means 0.5 is required and "foo 0.6" is what was found on the system |
| 45 |
|
| 46 |
# Copyright (c) 2006, David Faure, <[email protected]> |
| 47 |
# Copyright (c) 2007, Pino Toscano, <[email protected]> |
| 48 |
# |
| 49 |
# Redistribution and use is allowed according to the terms of the BSD license. |
| 50 |
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 51 |
|
| 52 |
MACRO(MACRO_ENSURE_VERSION2 requested_version found_version var_too_old) |
| 53 |
|
| 54 |
# parse the parts of the version string |
| 55 |
STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+" "\\1" req_major_vers "${requested_version}") |
| 56 |
STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)" "\\1" req_minor_vers "${requested_version}") |
| 57 |
|
| 58 |
STRING(REGEX REPLACE "[^0-9]*([0-9]+)\\.[0-9]+.*" "\\1" found_major_vers "${found_version}") |
| 59 |
STRING(REGEX REPLACE "[^0-9]*[0-9]+\\.([0-9]+).*" "\\1" found_minor_vers "${found_version}") |
| 60 |
|
| 61 |
# compute an overall version number which can be compared at once |
| 62 |
MATH(EXPR req_vers_num "${req_major_vers}*100 + ${req_minor_vers}") |
| 63 |
MATH(EXPR found_vers_num "${found_major_vers}*100 + ${found_minor_vers}") |
| 64 |
|
| 65 |
if (found_vers_num LESS req_vers_num) |
| 66 |
set( ${var_too_old} FALSE ) |
| 67 |
else (found_vers_num LESS req_vers_num) |
| 68 |
set( ${var_too_old} TRUE ) |
| 69 |
endif (found_vers_num LESS req_vers_num) |
| 70 |
|
| 71 |
ENDMACRO(MACRO_ENSURE_VERSION2) |