[cmake-developers] Package Config files with COMPONENTS

Brad King brad.king at kitware.com
Tue Mar 13 16:55:38 EDT 2012


On Tue, Mar 13, 2012 at 4:43 PM, Alexander Neundorf <neundorf at kde.org> wrote:
> We could also not set <pkg>_FIND_REQUIRED_<component>, or set it to "0" (which
> would mean it is not required).

Even better.  One can loop over the_FIND_COMPONENTS list and then test
the variable to see if it is really required or not.

> Are there any compatibility issue to take into account ?
> Until now, there never was a OPTIONAL_COMPONENT, so every call to
> find_package(COMPONENTS ...) will work as before.

I don't think there is a compatibility concern.  A loop like the above
would just consider every component required when the package is
loaded by an older project that does not use the new keyword.

> If somebody adds a OPTIONAL_COMPONENTS, this will add component entries to the
> FIND_COMPONENTS variable which have now _FIND_REQUIRED_ set to 0.
> The Find-module or Config-file may not be prepared to handle this.

I do not think that is a problem.  The calling project should only use
this option if the package to be found documents that it supports
optional components.  This is the same as passing only components
documented by the package as known.

> What is actually the purpose of the _FIND_REQUIRED_ variable ?
> It currently doesn't add any information compared to the list
> _FIND_COMPONENTS. Are you aware of any uses of this variable ?

_FIND_REQUIRED_ came first.  The entire feature was first added here:

  http://www.cmake.org/Bug/view.php?id=2771
  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9f625bea

The _FIND_COMPONENTS list was added later because it is more convenient.

> The argument parsing in cmFindPackage still has to decide what to do if a
> component appears multiple times.
> Error out ?
> REQUIRED always has priority over OPTIONAL ?
> Last one wins ?

I think error is best.  It's better to be explicit so authors do not
assume ether way.

-Brad



More information about the cmake-developers mailing list