FPHSA(): add HANDLE_COMPONENTS option
if the HANDLE_COMPONENTS is used, FPHSA() now also checks all required COMPONENTS, i.e. all elements from <name>_FIND_COMPONENTS for which <name>_FIND_REQUIRED_<comp> is true, and sets <name>_FOUND only to true if all have been found. As discussed on cmake-developers. Alex
This commit is contained in:
parent
34108cd3b3
commit
b15c0b418b
|
@ -20,6 +20,7 @@
|
|||
# The second mode is more powerful and also supports version checking:
|
||||
# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [REQUIRED_VARS <var1>...<varN>]
|
||||
# [VERSION_VAR <versionvar>]
|
||||
# [HANDLE_COMPONENTS]
|
||||
# [CONFIG_MODE]
|
||||
# [FAIL_MESSAGE "Custom failure message"] )
|
||||
#
|
||||
|
@ -32,6 +33,11 @@
|
|||
# in the find_package() call. The EXACT keyword is also handled. The default
|
||||
# messages include information about the required version and the version
|
||||
# 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 <NAME>_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
|
||||
# a find_package(... NO_MODULE) call. In this case VERSION_VAR will be set
|
||||
# to <NAME>_VERSION and the macro will automatically check whether the
|
||||
|
@ -128,7 +134,7 @@ 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)
|
||||
SET(options CONFIG_MODE HANDLE_COMPONENTS)
|
||||
SET(oneValueArgs FAIL_MESSAGE VERSION_VAR)
|
||||
SET(multiValueArgs REQUIRED_VARS)
|
||||
SET(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
|
||||
|
@ -189,6 +195,36 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
|
|||
ENDIF(NOT ${_CURRENT_VAR})
|
||||
ENDFOREACH(_CURRENT_VAR)
|
||||
|
||||
# component handling
|
||||
UNSET(FOUND_COMPONENTS_MSG)
|
||||
UNSET(MISSING_COMPONENTS_MSG)
|
||||
|
||||
IF(FPHSA_HANDLE_COMPONENTS)
|
||||
FOREACH(comp ${${_NAME}_FIND_COMPONENTS})
|
||||
IF(${_NAME}_${comp}_FOUND)
|
||||
|
||||
IF(NOT DEFINED FOUND_COMPONENTS_MSG)
|
||||
SET(FOUND_COMPONENTS_MSG "found components: ")
|
||||
ENDIF()
|
||||
SET(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}")
|
||||
|
||||
ELSE()
|
||||
|
||||
IF(NOT DEFINED MISSING_COMPONENTS_MSG)
|
||||
SET(MISSING_COMPONENTS_MSG "missing components: ")
|
||||
ENDIF()
|
||||
SET(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}")
|
||||
|
||||
IF(${_NAME}_FIND_REQUIRED_${comp})
|
||||
SET(${_NAME_UPPER}_FOUND FALSE)
|
||||
SET(MISSING_VARS "${MISSING_VARS} ${comp}")
|
||||
ENDIF()
|
||||
|
||||
ENDIF()
|
||||
ENDFOREACH(comp)
|
||||
SET(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}")
|
||||
SET(DETAILS "${DETAILS}[c${COMPONENT_MSG}]")
|
||||
ENDIF(FPHSA_HANDLE_COMPONENTS)
|
||||
|
||||
# version handling:
|
||||
SET(VERSION_MSG "")
|
||||
|
@ -240,7 +276,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
|
|||
|
||||
# print the result:
|
||||
IF (${_NAME_UPPER}_FOUND)
|
||||
FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}")
|
||||
FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}")
|
||||
ELSE (${_NAME_UPPER}_FOUND)
|
||||
|
||||
IF(FPHSA_CONFIG_MODE)
|
||||
|
|
|
@ -37,6 +37,12 @@ FIND_PACKAGE(VersionTestB 1.2)
|
|||
FIND_PACKAGE(VersionTestC 1.2.3)
|
||||
FIND_PACKAGE(VersionTestD 1.2.3.4)
|
||||
|
||||
|
||||
FIND_PACKAGE(LotsOfComponents COMPONENTS AComp OPTIONAL_COMPONENTS BComp CComp)
|
||||
IF(NOT LOTSOFCOMPONENTS_FOUND)
|
||||
MESSAGE(SEND_ERROR "LotsOfComponents not found !")
|
||||
ENDIF()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Test system package registry if possible.
|
||||
SET(CMakeTestSystemPackage "")
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
set(LOC_FOO TRUE)
|
||||
|
||||
set(LotsOfComponents_AComp_FOUND TRUE)
|
||||
set(LotsOfComponents_BComp_FOUND FALSE)
|
||||
set(LotsOfComponents_CComp_FOUND TRUE)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(LotsOfComponents REQUIRED_VARS LOC_FOO
|
||||
HANDLE_COMPONENTS)
|
Loading…
Reference in New Issue