FPHSA: Always populate the ExactCase_FOUND variable (#15412).

The UPPERCASE name was inconsistent with config-packages, the
find_dependency macro, and even FPHSA itself, which expects
components to be specified with names matching ExactCase.

The FOUND_VAR was only permitted to have two possible values, and
now both are set for compatibility.  Document it as obsolete, and
adjust the code for the same.  Users of the variable should just
remove it.
This commit is contained in:
Stephen Kelly 2015-02-23 22:23:11 +01:00 committed by Brad King
parent cdc53b62c2
commit d1a6d15bcd
5 changed files with 48 additions and 37 deletions

View File

@ -0,0 +1,10 @@
FPHSA-ExactCase-name
--------------------
* The :module:`FindPackageHandleStandardArgs` module
``FIND_PACKAGE_HANDLE_STANDARD_ARGS`` function now
always populates the both ``<PackageName>_FOUND``
and ``<UPPERCASE_NAME>_FOUND`` variables (the latter
for backwards compatibility). The ``FOUND_VAR``
option is now ignored except to enforce its allowed
values.

View File

@ -8,9 +8,9 @@
# #
# This function is intended to be used in FindXXX.cmake modules files. # This function is intended to be used in FindXXX.cmake modules files.
# It handles the REQUIRED, QUIET and version-related arguments to # It handles the REQUIRED, QUIET and version-related arguments to
# find_package(). It also sets the <packagename>_FOUND variable. The # find_package(PackageName). It also sets the <PackageName>_FOUND
# package is considered found if all variables <var1>... listed contain # variable. The package is considered found if all variables <var1>...
# valid results, e.g. valid filepaths. # listed contain valid results, e.g. valid filepaths.
# #
# There are two modes of this function. The first argument in both # There are two modes of this function. The first argument in both
# modes is the name of the Find-module where it is called (in original # modes is the name of the Find-module where it is called (in original
@ -24,7 +24,7 @@
# (DEFAULT_MSG|"Custom failure message") <var1>...<varN> ) # (DEFAULT_MSG|"Custom failure message") <var1>...<varN> )
# #
# If the variables <var1> to <varN> are all valid, then # If the variables <var1> to <varN> are all valid, then
# <UPPERCASED_NAME>_FOUND will be set to TRUE. If DEFAULT_MSG is given # <PackageName>_FOUND will be set to TRUE. If DEFAULT_MSG is given
# as second argument, then the function will generate itself useful # as second argument, then the function will generate itself useful
# success and error messages. You can also supply a custom error # success and error messages. You can also supply a custom error
# message for the failure case. This is not recommended. # message for the failure case. This is not recommended.
@ -41,16 +41,12 @@
# [CONFIG_MODE] # [CONFIG_MODE]
# [FAIL_MESSAGE "Custom failure message"] ) # [FAIL_MESSAGE "Custom failure message"] )
# #
# In this mode, the name of the result-variable can be set either to # The FOUND_VAR option is obsolete. ``FIND_PACKAGE_HANDLE_STANDARD_ARGS``
# either <UPPERCASED_NAME>_FOUND or <OriginalCase_Name>_FOUND using the # always populates ``<PackageName>_FOUND``. For backward compatibility,
# FOUND_VAR option. Other names for the result-variable are not # it also always populates ``<UPPERCASE_NAME>_FOUND``.
# 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. If the FOUND_VAR option is not
# used, the default is <UPPERCASED_NAME>_FOUND.
# #
# As in the simple mode, if <var1> through <varN> are all valid, # As in the simple mode, if <var1> through <varN> are all valid,
# <packagename>_FOUND will be set to TRUE. After REQUIRED_VARS the # <PackageName>_FOUND will be set to TRUE. After REQUIRED_VARS the
# variables which are required for this package are listed. Following # variables which are required for this package are listed. Following
# VERSION_VAR the name of the variable can be specified which holds the # 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 of the package which has been found. If this is done, this
@ -61,7 +57,7 @@
# version is ok or not. If the package supports components, use the # version is ok or not. If the package supports components, use the
# HANDLE_COMPONENTS option to enable handling them. In this case, # HANDLE_COMPONENTS option to enable handling them. In this case,
# find_package_handle_standard_args() will report which components have # find_package_handle_standard_args() will report which components have
# been found and which are missing, and the <packagename>_FOUND variable # been found and which are missing, and the <PackageName>_FOUND variable
# will be set to FALSE if any of the required components (i.e. not the # 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 # ones listed after OPTIONAL_COMPONENTS) are missing. Use the option
# CONFIG_MODE if your FindXXX.cmake module is a wrapper for a # CONFIG_MODE if your FindXXX.cmake module is a wrapper for a
@ -81,7 +77,7 @@
# #
# #
# LibXml2 is considered to be found, if both LIBXML2_LIBRARY and # LibXml2 is considered to be found, if both LIBXML2_LIBRARY and
# LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to # LIBXML2_INCLUDE_DIR are valid. Then also LibXml2_FOUND is set to
# TRUE. If it is not found and REQUIRED was used, it fails with # TRUE. If it is not found and REQUIRED was used, it fails with
# FATAL_ERROR, independent whether QUIET was used or not. If it is # FATAL_ERROR, independent whether QUIET was used or not. If it is
# found, success will be reported, including the content of <var1>. On # found, success will be reported, including the content of <var1>. On
@ -92,16 +88,14 @@
# :: # ::
# #
# find_package_handle_standard_args(LibXslt # find_package_handle_standard_args(LibXslt
# FOUND_VAR LibXslt_FOUND
# REQUIRED_VARS LibXslt_LIBRARIES LibXslt_INCLUDE_DIRS # REQUIRED_VARS LibXslt_LIBRARIES LibXslt_INCLUDE_DIRS
# VERSION_VAR LibXslt_VERSION_STRING) # VERSION_VAR LibXslt_VERSION_STRING)
# #
# In this case, LibXslt is considered to be found if the variable(s) # In this case, LibXslt is considered to be found if the variable(s)
# listed after REQUIRED_VAR are all valid, i.e. LibXslt_LIBRARIES and # listed after REQUIRED_VAR are all valid, i.e. LibXslt_LIBRARIES and
# LibXslt_INCLUDE_DIRS in this case. The result will then be stored in # LibXslt_INCLUDE_DIRS in this case. Also the version of LibXslt will be
# LibXslt_FOUND . Also the version of LibXslt will be checked by using # checked by using the version contained in LibXslt_VERSION_STRING. Since
# the version contained in LibXslt_VERSION_STRING. Since no # no FAIL_MESSAGE is given, the default messages will be printed.
# FAIL_MESSAGE is given, the default messages will be printed.
# #
# Another example for mode 2: # Another example for mode 2:
# #
@ -111,9 +105,8 @@
# find_package_handle_standard_args(Automoc4 CONFIG_MODE) # find_package_handle_standard_args(Automoc4 CONFIG_MODE)
# #
# In this case, FindAutmoc4.cmake wraps a call to find_package(Automoc4 # In this case, FindAutmoc4.cmake wraps a call to find_package(Automoc4
# NO_MODULE) and adds an additional search directory for automoc4. Here # NO_MODULE) and adds an additional search directory for automoc4. The
# the result will be stored in AUTOMOC4_FOUND. The following # following FIND_PACKAGE_HANDLE_STANDARD_ARGS() call produces a proper
# FIND_PACKAGE_HANDLE_STANDARD_ARGS() call produces a proper
# success/error message. # success/error message.
#============================================================================= #=============================================================================
@ -239,17 +232,21 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
set(MISSING_VARS "") set(MISSING_VARS "")
set(DETAILS "") set(DETAILS "")
# check if all passed variables are valid # check if all passed variables are valid
unset(${_FOUND_VAR}) set(FPHSA_FOUND_${_NAME} TRUE)
foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS})
if(NOT ${_CURRENT_VAR}) if(NOT ${_CURRENT_VAR})
set(${_FOUND_VAR} FALSE) set(FPHSA_FOUND_${_NAME} FALSE)
set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
else() else()
set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
endif() endif()
endforeach() endforeach()
if(NOT "${${_FOUND_VAR}}" STREQUAL "FALSE") if(FPHSA_FOUND_${_NAME})
set(${_FOUND_VAR} TRUE) set(${_NAME}_FOUND TRUE)
set(${_NAME_UPPER}_FOUND TRUE)
else()
set(${_NAME}_FOUND FALSE)
set(${_NAME_UPPER}_FOUND FALSE)
endif() endif()
# component handling # component handling
@ -273,7 +270,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}")
if(${_NAME}_FIND_REQUIRED_${comp}) if(${_NAME}_FIND_REQUIRED_${comp})
set(${_FOUND_VAR} FALSE) set(${_NAME}_FOUND FALSE)
set(MISSING_VARS "${MISSING_VARS} ${comp}") set(MISSING_VARS "${MISSING_VARS} ${comp}")
endif() endif()
@ -356,12 +353,12 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
if(VERSION_OK) if(VERSION_OK)
set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]")
else() else()
set(${_FOUND_VAR} FALSE) set(${_NAME}_FOUND FALSE)
endif() endif()
# print the result: # print the result:
if (${_FOUND_VAR}) if (${_NAME}_FOUND)
FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}")
else () else ()
@ -377,6 +374,6 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
endif () endif ()
set(${_FOUND_VAR} ${${_FOUND_VAR}} PARENT_SCOPE) set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
endfunction() endfunction()

View File

@ -45,12 +45,18 @@ endif()
find_package(SomePackage) find_package(SomePackage)
if(NOT SomePackage_FOUND) if(NOT SomePackage_FOUND)
message(SEND_ERROR "SomePackage with FOUND_VAR SomePackage_FOUND not found !") message(SEND_ERROR "SomePackage not found !")
endif()
if(NOT SOMEPACKAGE_FOUND)
message(SEND_ERROR "SomePackage compatibility name SOMEPACKAGE_FOUND not set!")
endif() endif()
find_package(UpperCasePackage) find_package(UpperCasePackage)
if(NOT UpperCasePackage_FOUND)
message(SEND_ERROR "UpperCasePackage not found!")
endif()
if(NOT UPPERCASEPACKAGE_FOUND) if(NOT UPPERCASEPACKAGE_FOUND)
message(SEND_ERROR "UpperCasePackage with FOUND_VAR UPPERCASEPACKAGE_FOUND not found !") message(SEND_ERROR "SomePackage compatibility name SOMEPACKAGE_FOUND not set!")
endif() endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@ -2,5 +2,4 @@ set(SOP_FOO TRUE)
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(SomePackage REQUIRED_VARS SOP_FOO find_package_handle_standard_args(SomePackage REQUIRED_VARS SOP_FOO)
FOUND_VAR SomePackage_FOUND )

View File

@ -2,5 +2,4 @@ set(UCP_FOO TRUE)
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(UpperCasePackage REQUIRED_VARS UCP_FOO find_package_handle_standard_args(UpperCasePackage REQUIRED_VARS UCP_FOO)
FOUND_VAR UPPERCASEPACKAGE_FOUND )