FindPackageHandleStandardArgs.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME (DEFAULT_MSG|"Custom failure message") VAR1 ... )
  2. # This macro is intended to be used in FindXXX.cmake modules files.
  3. # It handles the REQUIRED and QUIET argument to FIND_PACKAGE() and
  4. # it also sets the <UPPERCASED_NAME>_FOUND variable.
  5. # The package is found if all variables listed are TRUE.
  6. # Example:
  7. #
  8. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
  9. #
  10. # LibXml2 is considered to be found, if both LIBXML2_LIBRARIES and
  11. # LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE.
  12. # If it is not found and REQUIRED was used, it fails with FATAL_ERROR,
  13. # independent whether QUIET was used or not.
  14. # If it is found, the location is reported using the VAR1 argument, so
  15. # here a message "Found LibXml2: /usr/lib/libxml2.so" will be printed out.
  16. # If the second argument is DEFAULT_MSG, the message in the failure case will
  17. # be "Could NOT find LibXml2", if you don't like this message you can specify
  18. # your own custom failure message there.
  19. #=============================================================================
  20. # Copyright 2007-2009 Kitware, Inc.
  21. #
  22. # Distributed under the OSI-approved BSD License (the "License");
  23. # see accompanying file Copyright.txt for details.
  24. #
  25. # This software is distributed WITHOUT ANY WARRANTY; without even the
  26. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  27. # See the License for more information.
  28. #=============================================================================
  29. # (To distributed this file outside of CMake, substitute the full
  30. # License text for the above reference.)
  31. INCLUDE(FindPackageMessage)
  32. FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )
  33. IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
  34. SET(_FAIL_MESSAGE "Could NOT find ${_NAME}")
  35. ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
  36. SET(_FAIL_MESSAGE "${_FAIL_MSG}")
  37. ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
  38. STRING(TOUPPER ${_NAME} _NAME_UPPER)
  39. # collect all variables which were not found, so they can be printed, so the
  40. # user knows better what went wrong (#6375)
  41. SET(MISSING_VARS "")
  42. SET(DETAILS "")
  43. SET(${_NAME_UPPER}_FOUND TRUE)
  44. IF(NOT ${_VAR1})
  45. SET(${_NAME_UPPER}_FOUND FALSE)
  46. SET(MISSING_VARS " ${_VAR1}")
  47. ELSE(NOT ${_VAR1})
  48. SET(DETAILS "${DETAILS}[${${_VAR1}}]")
  49. ENDIF(NOT ${_VAR1})
  50. # check if all passed variables are valid
  51. FOREACH(_CURRENT_VAR ${ARGN})
  52. IF(NOT ${_CURRENT_VAR})
  53. SET(${_NAME_UPPER}_FOUND FALSE)
  54. SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
  55. ELSE(NOT ${_CURRENT_VAR})
  56. SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
  57. ENDIF(NOT ${_CURRENT_VAR})
  58. ENDFOREACH(_CURRENT_VAR)
  59. IF (${_NAME_UPPER}_FOUND)
  60. FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_VAR1}}" "${DETAILS}")
  61. ELSE (${_NAME_UPPER}_FOUND)
  62. IF (${_NAME}_FIND_REQUIRED)
  63. MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
  64. ELSE (${_NAME}_FIND_REQUIRED)
  65. IF (NOT ${_NAME}_FIND_QUIETLY)
  66. MESSAGE(STATUS "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
  67. ENDIF (NOT ${_NAME}_FIND_QUIETLY)
  68. ENDIF (${_NAME}_FIND_REQUIRED)
  69. ENDIF (${_NAME_UPPER}_FOUND)
  70. SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
  71. ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS)