[CMake] find_package components required or not

Alexander Neundorf a.neundorf-work at gmx.net
Wed Aug 21 16:55:49 EDT 2013


On Thursday 15 August 2013, Lars Lars wrote:
> Hello,
> 
> The find_package macro provides the keywords "REQUIRED" and "COMPONENTS".
> 
> 
> 
> The docs state: "The REQUIRED option stops processing with an error message
> if the package cannot be found. A package-specific list of components may
> be listed after the REQUIRED option or after the COMPONENTS option if no
> REQUIRED option is given."
> 
> When using find_package and the "REQUIRED" keyword, are all components
> required?
> 
> When using find_package and the "COMPONENTS" keywords, are all components
> required?
> 
> It would be nice if the docs could state this information.

From readme.txt, which is installed along the Find-modules:

"A package can 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."

Maybe some of that should be included in the find_package() documentation.
But as you see, in the end it is up to the Find-module/Config-file to follow 
that convention.

Alex



More information about the CMake mailing list