find_package: add documentation for OPTIONAL_COMPONENTS

This patch adds documentation for OPTIONAL_COMPONENTS to cmFindPackage.cxx,
and also extends Modules/readme.txt significantly with regard to how
components should be handled.

Alex
This commit is contained in:
Alex Neundorf 2012-03-18 17:26:24 +01:00 committed by Brad King
parent cdabde82c2
commit 34108cd3b3
2 changed files with 31 additions and 12 deletions

View File

@ -119,16 +119,30 @@ able to find the package. If the
REQUIRED option is given to the command it will set the variable REQUIRED option is given to the command it will set the variable
XXX_FIND_REQUIRED to true before loading the FindXXX.cmake module. If XXX_FIND_REQUIRED to true before loading the FindXXX.cmake module. If
this variable is set the module should issue a FATAL_ERROR if the this variable is set the module should issue a FATAL_ERROR if the
package cannot be found. For each package-specific component, say package cannot be found.
YYY, listed after the REQUIRED option a variable XXX_FIND_REQUIRED_YYY
to true. The set of components listed after either the REQUIRED
option or the COMPONENTS option will be specified in a
XXX_FIND_COMPONENTS variable. This can be used by the FindXXX.cmake
module to determine which sub-components of the package must be found.
If neither the QUIET nor REQUIRED options are given then the If neither the QUIET nor REQUIRED options are given then the
FindXXX.cmake module should look for the package and complain without FindXXX.cmake module should look for the package and complain without
error if the module is not found. error if the module is not found.
A package can be provide sub-components.
Those components can be listed after the COMPONENTS (or REQUIRED)
or OPTIONAL_COMPONENTS keywords. The set of all listed components will be
specified in a XXX_FIND_COMPONENTS variable.
For each package-specific component, say Yyy, a variable XXX_FIND_REQUIRED_Yyy
will be set to true if it listed after COMPONENTS and it will be set to false
if it was listed after OPTIONAL_COMPONENTS.
Using those variables a FindXXX.cmake module and also a XXXConfig.cmake package
configuration file can determine whether and which components have been requested,
and whether they were requested as required or as optional.
For each of the requested components a XXX_Yyy_FOUND variable should be set
accordingly.
The per-package XXX_FOUND variable should be only set to true if all requested
required components have been found. A missing optional component should not
keep the XXX_FOUND variable from being set to true.
If the package provides XXX_INCLUDE_DIRS and XXX_LIBRARIES variables, the include
dirs and libraries for all components which were requested and which have been
found should be added to those two variables.
To get this behaviour you can use the FIND_PACKAGE_HANDLE_STANDARD_ARGS() To get this behaviour you can use the FIND_PACKAGE_HANDLE_STANDARD_ARGS()
macro, as an example see FindJPEG.cmake. macro, as an example see FindJPEG.cmake.

View File

@ -90,6 +90,7 @@ void cmFindPackageCommand::GenerateDocumentation()
this->CommandDocumentation = this->CommandDocumentation =
" find_package(<package> [version] [EXACT] [QUIET] [MODULE]\n" " find_package(<package> [version] [EXACT] [QUIET] [MODULE]\n"
" [[REQUIRED|COMPONENTS] [components...]]\n" " [[REQUIRED|COMPONENTS] [components...]]\n"
" [OPTIONAL_COMPONENTS components...]\n"
" [NO_POLICY_SCOPE])\n" " [NO_POLICY_SCOPE])\n"
"Finds and loads settings from an external project. " "Finds and loads settings from an external project. "
"<package>_FOUND will be set to indicate whether the package was found. " "<package>_FOUND will be set to indicate whether the package was found. "
@ -99,9 +100,13 @@ void cmFindPackageCommand::GenerateDocumentation()
"The MODULE option disables the second signature documented below. " "The MODULE option disables the second signature documented below. "
"The REQUIRED option stops processing with an error message if the " "The REQUIRED option stops processing with an error message if the "
"package cannot be found." "package cannot be found."
"A package-specific list of components may be listed after the " "\n"
"REQUIRED option or after the COMPONENTS option if no REQUIRED " "A package-specific list of required components may be listed after the "
"option is given. " "COMPONENTS option or directly after the REQUIRED option. "
"Additional optional components may be listed after OPTIONAL_COMPONENTS. "
"Available components and their influence on whether a package is "
"considered to be found are defined by the target package."
"\n"
"The [version] argument requests a version with which the package found " "The [version] argument requests a version with which the package found "
"should be compatible (format is major[.minor[.patch[.tweak]]]). " "should be compatible (format is major[.minor[.patch[.tweak]]]). "
"The EXACT option requests that the version be matched exactly. " "The EXACT option requests that the version be matched exactly. "