From 7bb1abe56a05ccc50ff2c56e2df60f305af17ca4 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Wed, 20 Feb 2013 19:35:11 +0100 Subject: FPHSA: Add FOUND_VAR option to specify _FOUND variable name In the new mode FPHSA now accepts a FOUND_VAR option, which can be set either to ExactCase_FOUND or UPPERCASE_FOUND, no other values are accepted. Also add tests for that, including failure. Alex --- Modules/FindPackageHandleStandardArgs.cmake | 47 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'Modules/FindPackageHandleStandardArgs.cmake') diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index e89e9a97dd..ce89c059ff 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -2,7 +2,7 @@ # # This function is intended to be used in FindXXX.cmake modules files. # It handles the REQUIRED, QUIET and version-related arguments to find_package(). -# It also sets the _FOUND variable. +# It also sets the _FOUND variable. # The package is considered found if all variables ... listed contain # valid results, e.g. valid filepaths. # @@ -18,14 +18,21 @@ # for the failure case. This is not recommended. # # The second mode is more powerful and also supports version checking: -# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [REQUIRED_VARS ...] +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [FOUND_VAR ] +# [REQUIRED_VARS ...] # [VERSION_VAR ] # [HANDLE_COMPONENTS] # [CONFIG_MODE] # [FAIL_MESSAGE "Custom failure message"] ) # -# As above, if through are all valid, _FOUND -# will be set to TRUE. +# In this mode, the name of the result-variable can be set either to either +# _FOUND or _FOUND using the FOUND_VAR option. +# Other names for the result-variable are not allowed. +# So for a Find-module named FindFooBar.cmake, the two possible names are +# FooBar_FOUND and FOOBAR_FOUND. It is recommended to use the original case version. +# +# As in the simple mode, if through are all valid, +# _FOUND will be set to TRUE. # After REQUIRED_VARS the variables which are required for this package are listed. # Following VERSION_VAR the name of the variable can be specified which holds # the version of the package which has been found. If this is done, this version @@ -35,7 +42,7 @@ # which has been actually found, both if the version is ok or not. # If the package supports components, use the HANDLE_COMPONENTS option to enable # handling them. In this case, find_package_handle_standard_args() will report -# which components have been found and which are missing, and the _FOUND +# which components have been found and which are missing, and the _FOUND # variable will be set to FALSE if any of the required components (i.e. not the # ones listed after OPTIONAL_COMPONENTS) are missing. # Use the option CONFIG_MODE if your FindXXX.cmake module is a wrapper for @@ -137,8 +144,8 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in # new extended or in the "old" mode: - set(options CONFIG_MODE HANDLE_COMPONENTS) - set(oneValueArgs FAIL_MESSAGE VERSION_VAR) + set(options CONFIG_MODE HANDLE_COMPONENTS) + set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR) set(multiValueArgs REQUIRED_VARS) set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) @@ -183,22 +190,32 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) string(TOUPPER ${_NAME} _NAME_UPPER) string(TOLOWER ${_NAME} _NAME_LOWER) + if(FPHSA_FOUND_VAR) + if("${FPHSA_FOUND_VAR}" MATCHES "^${_NAME}_FOUND$" OR "${FPHSA_FOUND_VAR}" MATCHES "^${_NAME_UPPER}_FOUND$") + set(_FOUND_VAR ${FPHSA_FOUND_VAR}) + else() + message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_NAME}_FOUND\" and \"${_NAME_UPPER}_FOUND\" are valid names.") + endif() + else() + set(_FOUND_VAR ${_NAME_UPPER}_FOUND) + endif() + # collect all variables which were not found, so they can be printed, so the # user knows better what went wrong (#6375) set(MISSING_VARS "") set(DETAILS "") # check if all passed variables are valid - unset(${_NAME_UPPER}_FOUND) + unset(${_FOUND_VAR}) foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) if(NOT ${_CURRENT_VAR}) - set(${_NAME_UPPER}_FOUND FALSE) + set(${_FOUND_VAR} FALSE) set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") else() set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") endif() endforeach() - if(NOT "${${_NAME_UPPER}_FOUND}" STREQUAL "FALSE") - set(${_NAME_UPPER}_FOUND TRUE) + if(NOT "${${_FOUND_VAR}}" STREQUAL "FALSE") + set(${_FOUND_VAR} TRUE) endif() # component handling @@ -222,7 +239,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") if(${_NAME}_FIND_REQUIRED_${comp}) - set(${_NAME_UPPER}_FOUND FALSE) + set(${_FOUND_VAR} FALSE) set(MISSING_VARS "${MISSING_VARS} ${comp}") endif() @@ -276,12 +293,12 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) if(VERSION_OK) set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") else() - set(${_NAME_UPPER}_FOUND FALSE) + set(${_FOUND_VAR} FALSE) endif() # print the result: - if (${_NAME_UPPER}_FOUND) + if (${_FOUND_VAR}) FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") else () @@ -297,6 +314,6 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) endif () - set(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE) + set(${_FOUND_VAR} ${${_FOUND_VAR}} PARENT_SCOPE) endfunction() -- cgit v1.2.1