PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/strigi-0.7.7/libstreamanalyzer/cmake/FindPackageHandleStandardArgs.cmake

#
CMake | 210 lines | 98 code | 32 blank | 80 comment | 1 complexity | 9e870aec82f63585070ab97d1308218a MD5 | raw file
Possible License(s): LGPL-2.0
  1. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(<name> ... )
  2. #
  3. # This function is intended to be used in FindXXX.cmake modules files.
  4. # It handles the REQUIRED, QUIET and version-related arguments to FIND_PACKAGE().
  5. # It also sets the <UPPERCASED_NAME>_FOUND variable.
  6. # The package is considered found if all variables <var1>... listed contain
  7. # valid results, e.g. valid filepaths.
  8. #
  9. # There are two modes of this function. The first argument in both modes is
  10. # the name of the Find-module where it is called (in original casing).
  11. #
  12. # The first simple mode looks like this:
  13. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(<name> (DEFAULT_MSG|"Custom failure message") <var1>...<varN> )
  14. # If the variables <var1> to <varN> are all valid, then <UPPERCASED_NAME>_FOUND
  15. # will be set to TRUE.
  16. # If DEFAULT_MSG is given as second argument, then the function will generate
  17. # itself useful success and error messages. You can also supply a custom error message
  18. # for the failure case. This is not recommended.
  19. #
  20. # The second mode is more powerful and also supports version checking:
  21. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [REQUIRED_VARS <var1>...<varN>]
  22. # [VERSION_VAR <versionvar>
  23. # [FAIL_MESSAGE "Custom failure message"] )
  24. #
  25. # As above, if <var1> through <varN> are all valid, <UPPERCASED_NAME>_FOUND
  26. # will be set to TRUE.
  27. # Via FAIL_MESSAGE a custom failure message can be specified, if this is not
  28. # used, the default message will be displayed.
  29. # Following VERSION_VAR the name of the variable can be specified which holds
  30. # the version of the package which has been found. If this is done, this version
  31. # will be checked against the (potentially) specified required version used
  32. # in the find_package() call. The EXACT keyword is also handled. The default
  33. # messages include information about the required version and the version
  34. # which has been actually found, both if the version is ok or not.
  35. #
  36. # Example for mode 1:
  37. #
  38. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)
  39. #
  40. # LibXml2 is considered to be found, if both LIBXML2_LIBRARY and
  41. # LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE.
  42. # If it is not found and REQUIRED was used, it fails with FATAL_ERROR,
  43. # independent whether QUIET was used or not.
  44. # If it is found, success will be reported, including the content of <var1>.
  45. # On repeated Cmake runs, the same message won't be printed again.
  46. #
  47. # Example for mode 2:
  48. #
  49. # FIND_PACKAGE_HANDLE_STANDARD_ARGS(BISON REQUIRED_VARS BISON_EXECUTABLE
  50. # VERSION_VAR BISON_VERSION)
  51. # In this case, BISON is considered to be found if the variable(s) listed
  52. # after REQUIRED_VAR are all valid, i.e. BISON_EXECUTABLE in this case.
  53. # Also the version of BISON will be checked by using the version contained
  54. # in BISON_VERSION.
  55. # Since no FAIL_MESSAGE is given, the default messages will be printed.
  56. #=============================================================================
  57. # Copyright 2007-2009 Kitware, Inc.
  58. #
  59. # Distributed under the OSI-approved BSD License (the "License");
  60. # see accompanying file Copyright.txt for details.
  61. #
  62. # This software is distributed WITHOUT ANY WARRANTY; without even the
  63. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  64. # See the License for more information.
  65. #=============================================================================
  66. # (To distribute this file outside of CMake, substitute the full
  67. # License text for the above reference.)
  68. INCLUDE(FindPackageMessage)
  69. INCLUDE(CMakeParseArguments)
  70. FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG _VAR1)
  71. # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in
  72. # new extended or in the "old" mode:
  73. SET(options) # none
  74. SET(oneValueArgs FAIL_MESSAGE VERSION_VAR)
  75. SET(multiValueArgs REQUIRED_VARS)
  76. SET(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
  77. LIST(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX)
  78. IF(${INDEX} EQUAL -1)
  79. SET(FPHSA_FAIL_MESSAGE ${_FIRST_ARG})
  80. SET(FPHSA_REQUIRED_VARS ${_VAR1} ${ARGN})
  81. SET(FPHSA_VERSION_VAR)
  82. ELSE(${INDEX} EQUAL -1)
  83. CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${_VAR1} ${ARGN})
  84. IF(FPHSA_UNPARSED_ARGUMENTS)
  85. MESSAGE(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"")
  86. ENDIF(FPHSA_UNPARSED_ARGUMENTS)
  87. IF(NOT FPHSA_FAIL_MESSAGE)
  88. SET(FPHSA_FAIL_MESSAGE "DEFAULT_MSG")
  89. ENDIF(NOT FPHSA_FAIL_MESSAGE)
  90. ENDIF(${INDEX} EQUAL -1)
  91. # now that we collected all arguments, process them
  92. IF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG")
  93. SET(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}")
  94. ENDIF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG")
  95. IF(NOT FPHSA_REQUIRED_VARS)
  96. MESSAGE(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()")
  97. ENDIF(NOT FPHSA_REQUIRED_VARS)
  98. LIST(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR)
  99. STRING(TOUPPER ${_NAME} _NAME_UPPER)
  100. # collect all variables which were not found, so they can be printed, so the
  101. # user knows better what went wrong (#6375)
  102. SET(MISSING_VARS "")
  103. SET(DETAILS "")
  104. SET(${_NAME_UPPER}_FOUND TRUE)
  105. # check if all passed variables are valid
  106. FOREACH(_CURRENT_VAR ${FPHSA_REQUIRED_VARS})
  107. IF(NOT ${_CURRENT_VAR})
  108. SET(${_NAME_UPPER}_FOUND FALSE)
  109. SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
  110. ELSE(NOT ${_CURRENT_VAR})
  111. SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
  112. ENDIF(NOT ${_CURRENT_VAR})
  113. ENDFOREACH(_CURRENT_VAR)
  114. # version handling:
  115. SET(VERSION_MSG "")
  116. SET(VERSION_OK TRUE)
  117. IF (${_NAME}_FIND_VERSION)
  118. # if the package was found, check for the version using <NAME>_FIND_VERSION
  119. IF (${_NAME_UPPER}_FOUND)
  120. SET(VERSION ${${FPHSA_VERSION_VAR}} )
  121. IF(VERSION)
  122. IF(${_NAME}_FIND_VERSION_EXACT) # exact version required
  123. IF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
  124. SET(VERSION_MSG " Found version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
  125. SET(VERSION_OK FALSE)
  126. ELSE (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
  127. SET(VERSION_MSG " (found exact version \"${VERSION}\")")
  128. ENDIF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
  129. ELSE(${_NAME}_FIND_VERSION_EXACT) # minimum version specified:
  130. IF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
  131. SET(VERSION_MSG " Found version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"")
  132. SET(VERSION_OK FALSE)
  133. ELSE ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
  134. SET(VERSION_MSG " (found version \"${VERSION}\", required is \"${${_NAME}_FIND_VERSION}\")")
  135. ENDIF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
  136. ENDIF(${_NAME}_FIND_VERSION_EXACT)
  137. # Uncomment the following two lines to see to which Find-modules the VERSION_VAR keywords still need to be added:
  138. # ELSE(VERSION)
  139. # SET(VERSION_MSG " (WARNING: Required version is \"${${_NAME}_FIND_VERSION}\", but version of ${_NAME} is unknown)")
  140. ENDIF(VERSION)
  141. # if the package was not found, but a version was given, add that to the output:
  142. ELSE (${_NAME_UPPER}_FOUND)
  143. IF(${_NAME}_FIND_VERSION_EXACT)
  144. SET(VERSION_MSG " (Required is exact version \"${${_NAME}_FIND_VERSION}\")")
  145. ELSE(${_NAME}_FIND_VERSION_EXACT)
  146. SET(VERSION_MSG " (Required is at least version \"${${_NAME}_FIND_VERSION}\")")
  147. ENDIF(${_NAME}_FIND_VERSION_EXACT)
  148. ENDIF (${_NAME_UPPER}_FOUND)
  149. ENDIF (${_NAME}_FIND_VERSION)
  150. IF(VERSION_OK)
  151. SET(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]")
  152. ELSE(VERSION_OK)
  153. SET(${_NAME_UPPER}_FOUND FALSE)
  154. ENDIF(VERSION_OK)
  155. # print the result:
  156. IF (${_NAME_UPPER}_FOUND)
  157. FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}")
  158. ELSE (${_NAME_UPPER}_FOUND)
  159. IF(NOT VERSION_OK)
  160. IF (${_NAME}_FIND_REQUIRED)
  161. MESSAGE(FATAL_ERROR "${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})")
  162. ELSE (${_NAME}_FIND_REQUIRED)
  163. IF (NOT ${_NAME}_FIND_QUIETLY)
  164. MESSAGE(STATUS "${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})")
  165. ENDIF (NOT ${_NAME}_FIND_QUIETLY)
  166. ENDIF (${_NAME}_FIND_REQUIRED)
  167. ELSE(NOT VERSION_OK)
  168. IF (${_NAME}_FIND_REQUIRED)
  169. MESSAGE(FATAL_ERROR "${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}")
  170. ELSE (${_NAME}_FIND_REQUIRED)
  171. IF (NOT ${_NAME}_FIND_QUIETLY)
  172. MESSAGE(STATUS "${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}")
  173. ENDIF (NOT ${_NAME}_FIND_QUIETLY)
  174. ENDIF (${_NAME}_FIND_REQUIRED)
  175. ENDIF(NOT VERSION_OK)
  176. ENDIF (${_NAME_UPPER}_FOUND)
  177. SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
  178. ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _FIRST_ARG)