/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#=============================================================================
58# Copyright 2007-2009 Kitware, Inc.
59#
60# Distributed under the OSI-approved BSD License (the "License");
61# see accompanying file Copyright.txt for details.
62#
63# This software is distributed WITHOUT ANY WARRANTY; without even the
64# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
65# See the License for more information.
66#=============================================================================
67# (To distribute this file outside of CMake, substitute the full
68# License text for the above reference.)
69
70INCLUDE(FindPackageMessage)
71INCLUDE(CMakeParseArguments)
72
73
74FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG _VAR1)
75
76# set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in
77# new extended or in the "old" mode:
78 SET(options) # none
79 SET(oneValueArgs FAIL_MESSAGE VERSION_VAR)
80 SET(multiValueArgs REQUIRED_VARS)
81 SET(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
82 LIST(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX)
83
84 IF(${INDEX} EQUAL -1)
85 SET(FPHSA_FAIL_MESSAGE ${_FIRST_ARG})
86 SET(FPHSA_REQUIRED_VARS ${_VAR1} ${ARGN})
87 SET(FPHSA_VERSION_VAR)
88 ELSE(${INDEX} EQUAL -1)
89
90 CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${_VAR1} ${ARGN})
91
92 IF(FPHSA_UNPARSED_ARGUMENTS)
93 MESSAGE(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"")
94 ENDIF(FPHSA_UNPARSED_ARGUMENTS)
95
96 IF(NOT FPHSA_FAIL_MESSAGE)
97 SET(FPHSA_FAIL_MESSAGE "DEFAULT_MSG")
98 ENDIF(NOT FPHSA_FAIL_MESSAGE)
99 ENDIF(${INDEX} EQUAL -1)
100
101# now that we collected all arguments, process them
102
103 IF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG")
104 SET(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}")
105 ENDIF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG")
106
107 IF(NOT FPHSA_REQUIRED_VARS)
108 MESSAGE(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()")
109 ENDIF(NOT FPHSA_REQUIRED_VARS)
110
111 LIST(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR)
112
113 STRING(TOUPPER ${_NAME} _NAME_UPPER)
114
115 # collect all variables which were not found, so they can be printed, so the
116 # user knows better what went wrong (#6375)
117 SET(MISSING_VARS "")
118 SET(DETAILS "")
119 SET(${_NAME_UPPER}_FOUND TRUE)
120 # check if all passed variables are valid
121 FOREACH(_CURRENT_VAR ${FPHSA_REQUIRED_VARS})
122 IF(NOT ${_CURRENT_VAR})
123 SET(${_NAME_UPPER}_FOUND FALSE)
124 SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
125 ELSE(NOT ${_CURRENT_VAR})
126 SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
127 ENDIF(NOT ${_CURRENT_VAR})
128 ENDFOREACH(_CURRENT_VAR)
129
130
131 # version handling:
132 SET(VERSION_MSG "")
133 SET(VERSION_OK TRUE)
134 IF (${_NAME}_FIND_VERSION)
135
136 # if the package was found, check for the version using <NAME>_FIND_VERSION
137 IF (${_NAME_UPPER}_FOUND)
138 SET(VERSION ${${FPHSA_VERSION_VAR}} )
139
140 IF(VERSION)
141
142 IF(${_NAME}_FIND_VERSION_EXACT) # exact version required
143 IF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
144 SET(VERSION_MSG " Found version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
145 SET(VERSION_OK FALSE)
146 ELSE (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
147 SET(VERSION_MSG " (found exact version \"${VERSION}\")")
148 ENDIF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
149
150 ELSE(${_NAME}_FIND_VERSION_EXACT) # minimum version specified:
151 IF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
152 SET(VERSION_MSG " Found version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"")
153 SET(VERSION_OK FALSE)
154 ELSE ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
155 SET(VERSION_MSG " (found version \"${VERSION}\", required is \"${${_NAME}_FIND_VERSION}\")")
156 ENDIF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
157 ENDIF(${_NAME}_FIND_VERSION_EXACT)
158
159# Uncomment the following two lines to see to which Find-modules the VERSION_VAR keywords still need to be added:
160# ELSE(VERSION)
161# SET(VERSION_MSG " (WARNING: Required version is \"${${_NAME}_FIND_VERSION}\", but version of ${_NAME} is unknown)")
162 ENDIF(VERSION)
163
164 # if the package was not found, but a version was given, add that to the output:
165 ELSE (${_NAME_UPPER}_FOUND)
166 IF(${_NAME}_FIND_VERSION_EXACT)
167 SET(VERSION_MSG " (Required is exact version \"${${_NAME}_FIND_VERSION}\")")
168 ELSE(${_NAME}_FIND_VERSION_EXACT)
169 SET(VERSION_MSG " (Required is at least version \"${${_NAME}_FIND_VERSION}\")")
170 ENDIF(${_NAME}_FIND_VERSION_EXACT)
171 ENDIF (${_NAME_UPPER}_FOUND)
172 ENDIF (${_NAME}_FIND_VERSION)
173
174 IF(VERSION_OK)
175 SET(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]")
176 ELSE(VERSION_OK)
177 SET(${_NAME_UPPER}_FOUND FALSE)
178 ENDIF(VERSION_OK)
179
180
181 # print the result:
182 IF (${_NAME_UPPER}_FOUND)
183 FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}")
184 ELSE (${_NAME_UPPER}_FOUND)
185 IF(NOT VERSION_OK)
186
187 IF (${_NAME}_FIND_REQUIRED)
188 MESSAGE(FATAL_ERROR "${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})")
189 ELSE (${_NAME}_FIND_REQUIRED)
190 IF (NOT ${_NAME}_FIND_QUIETLY)
191 MESSAGE(STATUS "${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})")
192 ENDIF (NOT ${_NAME}_FIND_QUIETLY)
193 ENDIF (${_NAME}_FIND_REQUIRED)
194
195 ELSE(NOT VERSION_OK)
196
197 IF (${_NAME}_FIND_REQUIRED)
198 MESSAGE(FATAL_ERROR "${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}")
199 ELSE (${_NAME}_FIND_REQUIRED)
200 IF (NOT ${_NAME}_FIND_QUIETLY)
201 MESSAGE(STATUS "${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}")
202 ENDIF (NOT ${_NAME}_FIND_QUIETLY)
203 ENDIF (${_NAME}_FIND_REQUIRED)
204 ENDIF(NOT VERSION_OK)
205
206 ENDIF (${_NAME_UPPER}_FOUND)
207
208 SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
209
210ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _FIRST_ARG)