Add support for dbusmenu
[quassel.git] / cmake / modules / FindPackageHandleStandardArgs.cmake
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 considered found if all variables listed are TRUE.
6 #    The version-argument of FIND_PACKAGE() is also handled. 
7 #    For checking whether the version is ok, this macro compares the 
8 #    variable <UPPERCASED_NAME>_VERSION with the specified version.
9 #    Example:
10 #
11 #    FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
12 #
13 #    LibXml2 is considered to be found, if both LIBXML2_LIBRARIES and 
14 #    LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE.
15 #    If it is not found and REQUIRED was used, it fails with FATAL_ERROR, 
16 #    independent whether QUIET was used or not.
17 #    If it is found, the location is reported using the VAR1 argument, so 
18 #    here a message "Found LibXml2: /usr/lib/libxml2.so" will be printed out.
19 #    If the second argument is DEFAULT_MSG, the message in the failure case will 
20 #    be "Could NOT find LibXml2", if you don't like this message you can specify
21 #    your own custom failure message there.
22
23 #=============================================================================
24 # Copyright 2007-2009 Kitware, Inc.
25 #
26 # Distributed under the OSI-approved BSD License (the "License");
27 # see accompanying file Copyright.txt for details.
28 #
29 # This software is distributed WITHOUT ANY WARRANTY; without even the
30 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31 # See the License for more information.
32 #=============================================================================
33 # (To distributed this file outside of CMake, substitute the full
34 #  License text for the above reference.)
35
36 INCLUDE(FindPackageMessage)
37 FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )
38
39   IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
40     SET(_FAIL_MESSAGE "Could NOT find ${_NAME}")
41   ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
42     SET(_FAIL_MESSAGE "${_FAIL_MSG}")
43   ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
44
45   STRING(TOUPPER ${_NAME} _NAME_UPPER)
46
47   # collect all variables which were not found, so they can be printed, so the 
48   # user knows better what went wrong (#6375)
49   SET(MISSING_VARS "")
50   SET(DETAILS "")
51   SET(${_NAME_UPPER}_FOUND TRUE)
52   IF(NOT ${_VAR1})
53     SET(${_NAME_UPPER}_FOUND FALSE)
54     SET(MISSING_VARS " ${_VAR1}")
55   ELSE(NOT ${_VAR1})
56     SET(DETAILS "${DETAILS}[${${_VAR1}}]")
57   ENDIF(NOT ${_VAR1})
58
59   # check if all passed variables are valid
60   FOREACH(_CURRENT_VAR ${ARGN})
61     IF(NOT ${_CURRENT_VAR})
62       SET(${_NAME_UPPER}_FOUND FALSE)
63       SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
64     ELSE(NOT ${_CURRENT_VAR})
65       SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
66     ENDIF(NOT ${_CURRENT_VAR})
67   ENDFOREACH(_CURRENT_VAR)
68
69   # version handling:
70   SET(VERSION_MSG "")
71   SET(VERSION_OK TRUE)
72   IF (${_NAME}_FIND_VERSION)
73
74     # if the package was found, check for the version using <NAME>_FIND_VERSION
75     IF (${_NAME_UPPER}_FOUND)
76       IF(${_NAME_UPPER}_VERSION)
77         SET(VERSION ${${_NAME_UPPER}_VERSION})
78       ELSEIF(${_NAME}_VERSION)
79         SET(VERSION ${${_NAME}_VERSION})
80       ENDIF(${_NAME_UPPER}_VERSION)
81       
82       IF(VERSION)  #hmm what do we do if the module in question doesn't set FOO_VERSION but something else ?... Ignore it for now
83
84       IF(${_NAME}_FIND_VERSION_EXACT)       # exact version required
85         IF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
86           SET(VERSION_MSG " Found version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
87           SET(VERSION_OK FALSE)
88         ELSE (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
89           SET(VERSION_MSG " (found exact version \"${VERSION}\")")
90         ENDIF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
91
92       ELSE(${_NAME}_FIND_VERSION_EXACT)     # minimum version specified:
93         IF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
94           SET(VERSION_MSG " Found version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"")
95           SET(VERSION_OK FALSE)
96         ELSE ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
97           SET(VERSION_MSG " (found version \"${VERSION}\", required is \"${${_NAME}_FIND_VERSION}\")")
98         ENDIF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")
99       ENDIF(${_NAME}_FIND_VERSION_EXACT)
100
101       ELSE(VERSION)
102         SET(VERSION_MSG " (WARNING: Required version is \"${${_NAME}_FIND_VERSION}\", but version of ${_NAME} is unknown)")
103       ENDIF(VERSION)
104
105     # if the package was not found, but some a version was given, add that to the output:
106     ELSE (${_NAME_UPPER}_FOUND)
107       IF(${_NAME}_FIND_VERSION_EXACT)
108          SET(VERSION_MSG " (Required is exact version \"${${_NAME}_FIND_VERSION}\")")
109       ELSE(${_NAME}_FIND_VERSION_EXACT)
110          SET(VERSION_MSG " (Required is at least version \"${${_NAME}_FIND_VERSION}\")")
111       ENDIF(${_NAME}_FIND_VERSION_EXACT)
112     ENDIF (${_NAME_UPPER}_FOUND)
113   ENDIF (${_NAME}_FIND_VERSION)
114
115   IF(VERSION_OK)
116       SET(DETAILS "${DETAILS}[v${${VERSION}}]")
117   ELSE(VERSION_OK)
118     SET(${_NAME_UPPER}_FOUND FALSE)
119   ENDIF(VERSION_OK)
120
121
122   # print the result:
123   IF (${_NAME_UPPER}_FOUND)
124     FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_VAR1}} ${VERSION_MSG}" "${DETAILS}")
125   ELSE (${_NAME_UPPER}_FOUND)
126     IF(NOT VERSION_OK)
127
128       IF (${_NAME}_FIND_REQUIRED)
129           MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_VAR1}})")
130       ELSE (${_NAME}_FIND_REQUIRED)
131         IF (NOT ${_NAME}_FIND_QUIETLY)
132           MESSAGE(STATUS "${_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_VAR1}})")
133         ENDIF (NOT ${_NAME}_FIND_QUIETLY)
134       ENDIF (${_NAME}_FIND_REQUIRED)
135
136     ELSE(NOT VERSION_OK)
137
138       IF (${_NAME}_FIND_REQUIRED)
139           MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}")
140       ELSE (${_NAME}_FIND_REQUIRED)
141         IF (NOT ${_NAME}_FIND_QUIETLY)
142           MESSAGE(STATUS "${_FAIL_MESSAGE}  (missing: ${MISSING_VARS}) ${VERSION_MSG}")
143         ENDIF (NOT ${_NAME}_FIND_QUIETLY)
144       ENDIF (${_NAME}_FIND_REQUIRED)
145     ENDIF(NOT VERSION_OK)
146
147   ENDIF (${_NAME_UPPER}_FOUND)
148
149   SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
150
151 ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS)