FindPackageVersionCheck.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # (c) 2014 Copyright ownCloud GmbH
  2. # Redistribution and use is allowed according to the terms of the BSD license.
  3. # For details see the accompanying COPYING* file.
  4. # FIND_PACKAGE_VERSION_CHECK(NAME (DEFAULT_MSG|"Custom failure message"))
  5. # This function is intended to be used in FindXXX.cmake modules files.
  6. # It handles NAME_FIND_VERSION and NAME_VERSION variables in a Module.
  7. #
  8. # Example:
  9. # find_package(LibSSH 0.3.2)
  10. #
  11. # # check for the version and set it
  12. # set(LibSSH_VERSION 0.3.0)
  13. # find_package_version_check(LibSSH DEFAULT_MSG)
  14. #
  15. #
  16. # Copyright (c) 2009 Andreas Schneider <asn@cryptomilk.org>
  17. #
  18. # Redistribution and use is allowed according to the terms of the New
  19. # BSD license.
  20. function(FIND_PACKAGE_VERSION_CHECK _NAME _FAIL_MSG)
  21. string(TOUPPER ${_NAME} _NAME_UPPER)
  22. set(_AGE "old")
  23. if(${_NAME}_FIND_VERSION_EXACT)
  24. if (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
  25. # exact version found
  26. set(${_NAME_UPPER}_FOUND TRUE)
  27. else (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
  28. # exect version not found
  29. set(${_NAME_UPPER}_FOUND FALSE)
  30. # check if newer or older
  31. if (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
  32. set(_AGE "new")
  33. else (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
  34. set(_AGE "old")
  35. endif (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
  36. endif (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
  37. else (${_NAME}_FIND_VERSION_EXACT)
  38. if (${_NAME}_FIND_VERSION)
  39. if (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
  40. set(${_NAME_UPPER}_FOUND FALSE)
  41. set(_AGE "old")
  42. else (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
  43. set(${_NAME_UPPER}_FOUND TRUE)
  44. endif (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
  45. endif (${_NAME}_FIND_VERSION)
  46. endif(${_NAME}_FIND_VERSION_EXACT)
  47. if ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
  48. if (${_NAME}_FIND_VERSION_EXACT)
  49. set(_FAIL_MESSAGE "The installed ${_NAME} version ${${_NAME}_VERSION} is too ${_AGE}, version ${${_NAME}_FIND_VERSION} is required.")
  50. else (${_NAME}_FIND_VERSION_EXACT)
  51. set(_FAIL_MESSAGE "The installed ${_NAME} version ${${_NAME}_VERSION} is too ${_AGE}, at least version ${${_NAME}_FIND_VERSION} is required.")
  52. endif (${_NAME}_FIND_VERSION_EXACT)
  53. else ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
  54. set(_FAIL_MESSAGE "${_FAIL_MSG}")
  55. endif ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
  56. if (NOT ${_NAME_UPPER}_FOUND)
  57. if (${_NAME}_FIND_REQUIRED)
  58. message(FATAL_ERROR "${_FAIL_MESSAGE}")
  59. else (${_NAME}_FIND_REQUIRED)
  60. if (NOT ${_NAME}_FIND_QUIETLY)
  61. message(STATUS "${_FAIL_MESSAGE}")
  62. endif (NOT ${_NAME}_FIND_QUIETLY)
  63. endif (${_NAME}_FIND_REQUIRED)
  64. endif (NOT ${_NAME_UPPER}_FOUND)
  65. set(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
  66. endfunction(FIND_PACKAGE_VERSION_CHECK)