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.
8 # FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
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.
20 INCLUDE(FindPackageMessage)
21 FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )
23 IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
24 SET(_FAIL_MESSAGE "Could NOT find ${_NAME}")
25 ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
26 SET(_FAIL_MESSAGE "${_FAIL_MSG}")
27 ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
29 STRING(TOUPPER ${_NAME} _NAME_UPPER)
31 # collect all variables which were not found, so they can be printed, so the
32 # user knows better what went wrong (#6375)
35 SET(${_NAME_UPPER}_FOUND TRUE)
37 SET(${_NAME_UPPER}_FOUND FALSE)
38 SET(MISSING_VARS " ${_VAR1}")
40 SET(DETAILS "${DETAILS}[${${_VAR1}}]")
43 # check if all passed variables are valid
44 FOREACH(_CURRENT_VAR ${ARGN})
45 IF(NOT ${_CURRENT_VAR})
46 SET(${_NAME_UPPER}_FOUND FALSE)
47 SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
48 ELSE(NOT ${_CURRENT_VAR})
49 SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
50 ENDIF(NOT ${_CURRENT_VAR})
51 ENDFOREACH(_CURRENT_VAR)
53 IF (${_NAME_UPPER}_FOUND)
54 FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_VAR1}}" "${DETAILS}")
55 ELSE (${_NAME_UPPER}_FOUND)
56 IF (${_NAME}_FIND_REQUIRED)
57 MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
58 ELSE (${_NAME}_FIND_REQUIRED)
59 IF (NOT ${_NAME}_FIND_QUIETLY)
60 MESSAGE(STATUS "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
61 ENDIF (NOT ${_NAME}_FIND_QUIETLY)
62 ENDIF (${_NAME}_FIND_REQUIRED)
63 ENDIF (${_NAME_UPPER}_FOUND)
65 SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
67 ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS)