|
| 1 | +# This file defines the following macros for developers to use in ensuring |
| 2 | +# that installed software is of the right version: |
| 3 | +# |
| 4 | +# MACRO_ENSURE_VERSION - test that a version number is greater than |
| 5 | +# or equal to some minimum |
| 6 | +# MACRO_ENSURE_VERSION_RANGE - test that a version number is greater than |
| 7 | +# or equal to some minimum and less than some |
| 8 | +# maximum |
| 9 | +# MACRO_ENSURE_VERSION2 - deprecated, do not use in new code |
| 10 | +# |
| 11 | + |
| 12 | +# MACRO_ENSURE_VERSION |
| 13 | +# This macro compares version numbers of the form "x.y.z" or "x.y" |
| 14 | +# MACRO_ENSURE_VERSION( FOO_MIN_VERSION FOO_VERSION_FOUND FOO_VERSION_OK) |
| 15 | +# will set FOO_VERSION_OK to true if FOO_VERSION_FOUND >= FOO_MIN_VERSION |
| 16 | +# Leading and trailing text is ok, e.g. |
| 17 | +# MACRO_ENSURE_VERSION( "2.5.31" "flex 2.5.4a" VERSION_OK) |
| 18 | +# which means 2.5.31 is required and "flex 2.5.4a" is what was found on the system |
| 19 | + |
| 20 | +# Copyright (c) 2006, David Faure, <faure@kde.org> |
| 21 | +# Copyright (c) 2007, Will Stephenson <wstephenson@kde.org> |
| 22 | +# |
| 23 | +# Redistribution and use is allowed according to the terms of the BSD license. |
| 24 | +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 25 | + |
| 26 | +# MACRO_ENSURE_VERSION_RANGE |
| 27 | +# This macro ensures that a version number of the form |
| 28 | +# "x.y.z" or "x.y" falls within a range defined by |
| 29 | +# min_version <= found_version < max_version. |
| 30 | +# If this expression holds, FOO_VERSION_OK will be set TRUE |
| 31 | +# |
| 32 | +# Example: MACRO_ENSURE_VERSION_RANGE3( "0.1.0" ${FOOCODE_VERSION} "0.7.0" FOO_VERSION_OK ) |
| 33 | +# |
| 34 | +# This macro will break silently if any of x,y,z are greater than 100. |
| 35 | +# |
| 36 | +# Copyright (c) 2007, Will Stephenson <wstephenson@kde.org> |
| 37 | +# |
| 38 | +# Redistribution and use is allowed according to the terms of the BSD license. |
| 39 | +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 40 | + |
| 41 | +# NORMALIZE_VERSION |
| 42 | +# Helper macro to convert version numbers of the form "x.y.z" |
| 43 | +# to an integer equal to 10^4 * x + 10^2 * y + z |
| 44 | +# |
| 45 | +# This macro will break silently if any of x,y,z are greater than 100. |
| 46 | +# |
| 47 | +# Copyright (c) 2006, David Faure, <faure@kde.org> |
| 48 | +# Copyright (c) 2007, Will Stephenson <wstephenson@kde.org> |
| 49 | +# |
| 50 | +# Redistribution and use is allowed according to the terms of the BSD license. |
| 51 | +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 52 | + |
| 53 | +# CHECK_RANGE_INCLUSIVE_LOWER |
| 54 | +# Helper macro to check whether x <= y < z |
| 55 | +# |
| 56 | +# Copyright (c) 2007, Will Stephenson <wstephenson@kde.org> |
| 57 | +# |
| 58 | +# Redistribution and use is allowed according to the terms of the BSD license. |
| 59 | +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 60 | + |
| 61 | + |
| 62 | +MACRO(NORMALIZE_VERSION _requested_version _normalized_version) |
| 63 | + STRING(REGEX MATCH "[^0-9]*[0-9]+\\.[0-9]+\\.[0-9]+.*" _threePartMatch "${_requested_version}") |
| 64 | + if (_threePartMatch) |
| 65 | + # parse the parts of the version string |
| 66 | + STRING(REGEX REPLACE "[^0-9]*([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" _major_vers "${_requested_version}") |
| 67 | + STRING(REGEX REPLACE "[^0-9]*[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" _minor_vers "${_requested_version}") |
| 68 | + STRING(REGEX REPLACE "[^0-9]*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" _patch_vers "${_requested_version}") |
| 69 | + else (_threePartMatch) |
| 70 | + STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+" "\\1" _major_vers "${_requested_version}") |
| 71 | + STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)" "\\1" _minor_vers "${_requested_version}") |
| 72 | + set(_patch_vers "0") |
| 73 | + endif (_threePartMatch) |
| 74 | + |
| 75 | + # compute an overall version number which can be compared at once |
| 76 | + MATH(EXPR ${_normalized_version} "${_major_vers}*10000 + ${_minor_vers}*100 + ${_patch_vers}") |
| 77 | +ENDMACRO(NORMALIZE_VERSION) |
| 78 | + |
| 79 | +MACRO(MACRO_CHECK_RANGE_INCLUSIVE_LOWER _lower_limit _value _upper_limit _ok) |
| 80 | + if (${_value} LESS ${_lower_limit}) |
| 81 | + set( ${_ok} FALSE ) |
| 82 | + elseif (${_value} EQUAL ${_lower_limit}) |
| 83 | + set( ${_ok} TRUE ) |
| 84 | + elseif (${_value} EQUAL ${_upper_limit}) |
| 85 | + set( ${_ok} FALSE ) |
| 86 | + elseif (${_value} GREATER ${_upper_limit}) |
| 87 | + set( ${_ok} FALSE ) |
| 88 | + else (${_value} LESS ${_lower_limit}) |
| 89 | + set( ${_ok} TRUE ) |
| 90 | + endif (${_value} LESS ${_lower_limit}) |
| 91 | +ENDMACRO(MACRO_CHECK_RANGE_INCLUSIVE_LOWER) |
| 92 | + |
| 93 | +MACRO(MACRO_ENSURE_VERSION requested_version found_version var_too_old) |
| 94 | + NORMALIZE_VERSION( ${requested_version} req_vers_num ) |
| 95 | + NORMALIZE_VERSION( ${found_version} found_vers_num ) |
| 96 | + |
| 97 | + if (found_vers_num LESS req_vers_num) |
| 98 | + set( ${var_too_old} FALSE ) |
| 99 | + else (found_vers_num LESS req_vers_num) |
| 100 | + set( ${var_too_old} TRUE ) |
| 101 | + endif (found_vers_num LESS req_vers_num) |
| 102 | + |
| 103 | +ENDMACRO(MACRO_ENSURE_VERSION) |
| 104 | + |
| 105 | +MACRO(MACRO_ENSURE_VERSION2 requested_version2 found_version2 var_too_old2) |
| 106 | + MACRO_ENSURE_VERSION( ${requested_version2} ${found_version2} ${var_too_old2}) |
| 107 | +ENDMACRO(MACRO_ENSURE_VERSION2) |
| 108 | + |
| 109 | +MACRO(MACRO_ENSURE_VERSION_RANGE min_version found_version max_version var_ok) |
| 110 | + NORMALIZE_VERSION( ${min_version} req_vers_num ) |
| 111 | + NORMALIZE_VERSION( ${found_version} found_vers_num ) |
| 112 | + NORMALIZE_VERSION( ${max_version} max_vers_num ) |
| 113 | + |
| 114 | + MACRO_CHECK_RANGE_INCLUSIVE_LOWER( ${req_vers_num} ${found_vers_num} ${max_vers_num} ${var_ok}) |
| 115 | +ENDMACRO(MACRO_ENSURE_VERSION_RANGE) |
0 commit comments