[CMake] Component support in FindPackageHandleStandardArgs

Alexander Neundorf a.neundorf-work at gmx.net
Tue Jan 18 14:54:42 EST 2011


On Monday 13 December 2010, Johannes Zarl wrote:
> Hello list,
>
> During a recent discussion about find_package modules and components,
> the question came up how to best use FindPackageHandleStandardArgs
> (FPHSA) with components.
>
> One solution that currently works is to call FPHSA several times with
> the qualified component name as "package name":
>
> # Handle "core" package:
> FPHSA(XXX DEFAULT_MSG XXX_LIBRARY XXX_INCLUDE_DIR)
>
> # Handle explicitly requested component YYY:
> # Set up (or not) XXX_YYY_LIBRARY, XXX_YYY_INCLUDE_DIR
> SET(XXX_YYY_FIND_REQUIRED ${XXX_FIND_REQUIRED})
> SET(XXX_YYY_FIND_QUIETLY ${XXX_FIND_QUIETLY})
> FPHSA(XXX_YYY DEFAULT_MSG XXX_YYY_LIBRARY XXX_YYY_INCLUDE_DIR )
>
> # Handle non-requested component ZZZ:
> # Set up (or not) XXX_ZZZ_LIBRARY, XXX_ZZZ_INCLUDE_DIR
> SET(XXX_ZZZ_FIND_REQUIRED FALSE)
> SET(XXX_ZZZ_FIND_QUIETLY TRUE)
> FPHSA(XXX_ZZZ DEFAULT_MSG XXX_ZZZ_LIBRARY XXX_ZZZ_INCLUDE_DIR )
>
> IMO, the "new" syntax of FPHSA could easily extended to handle components
> as well:
>
> FPHSA(NAME [REQUIRED_VARS <var1>...<varN>]
>      [COMPONENTS
>         [COMPONENT <cname> <cvar1>..<cvarN> [COMPONENT <cname>
> <cvar1>..<cvarN>[..]]] [[NO_]CHECK_REQUESTED_COMPONENTS]
>      ]
>      [VERSION_VAR   <versionvar>
>      [CONFIG_MODE]
>      [FAIL_MESSAGE "Custom failure message"] )
>
> The component description begins with the keyword COMPONENTS, and has an
> entry for each component (which starts with COMPONENT, followed by the
> component name (without the package-name prefix), and then lists all
> variables required by the component. Components are checked after
> REQUIRED_VARS, in order of their occurrence.
>
> If CHECK_REQUESTED_COMPONENTS is set (=default), FPHSA also checks if any
> other components have been requested by the user in the find_package
> command.
>
> The three FPHSA calls from above could be written using this syntax as:
> FPHSA(XXX REQUIRED_VARS XXX_LIBRARY XXX_INCLUDE_DIR
>   COMPONENTS
>     COMPONENT YYY XXX_YYY_LIBRARY XXX_YYY_INCLUDE_DIR
>     COMPONENT ZZZ XXX_ZZZ_LIBRARY XXX_ZZZ_INCLUDE_DIR )
>
> The attached patch implements this syntax for FPHSA.
>
> Is this a desirable extension to FPHSA?

Can you please add that to http://public.kitware.com/Bug/view.php?id=5920

I'm not sure the current version of CMakeParseArguments.cmake supports listing 
the same keyword multiple times.

Thanks
Alex


More information about the CMake mailing list