[cmake-developers] How to handle package Config.cmake files with dependencies ?

Alexander Neundorf neundorf at kde.org
Sat Mar 10 07:27:40 EST 2012


On Wednesday 07 March 2012, Michael Hertling wrote:
> On 02/27/2012 10:05 PM, Brad King wrote:
> > On 2/27/2012 3:37 PM, Michael Wild wrote:
> >> On 02/27/2012 09:15 PM, Alexander Neundorf wrote:
> >>> When the FooConfig.cmake has been found, Foo_FOUND is set to TRUE:
> >>>   // Set a variable marking whether the package was found.
> >>>   
> >>>    std::string foundVar = this->Name;
> >>>    foundVar += "_FOUND";
> >>> 
> >>> This means it is true in all cases that the Config.cmake file has been
> >>> found (and the version was compatible).
> > 
> > The find_package command is acting as a primitive like find_library from
> > the point of view of setting Foo_DIR, and that can be tested directly to
> > see if the config file was found.  That leaves room to change the way
> > we set Foo_FOUND.  We could add a policy that in NEW behavior unsets
> > Foo_FOUND completely before loading FooConfig.  After FooConfig has been
> > loaded it detects whether Foo_FOUND is now defined.  If set, use that
> > value.  If not set, set it to true as it is now.  That will give the
> > FooConfig file a chance to set the result.
> 
> Some FooConfig.cmake authors might use FPHSA(Foo "..." ...) because

Do you mean using FPHSA inside a Config file ?
Now this really shouldn't be done.
Config files should be as standalone as possible.
Also, the output will be messed up: there will be the error message from 
cmFindPackage.cxx, and additionally the output from FPHSA.
FPHSA is intended to be used in Find-modules.
Also the CONFIG mode of FPHSA is intended to be used in a Find-module:

FindFoo.cmake:

find_package(Foo NO_MODULE QUIET)
fphsa(Foo CONFIG_MODE)


It probably does not even work when used inside a Config file.


> of its messaging capabilities respecting REQUIRED/QUIET, and rely on
> FIND_PACKAGE() returning with Foo_FOUND==TRUE even if FPHSA() has set

If this is done somewhere, I'd say it's a bug.
fphsa() has two purposes: set FOO_FOUND and produce a message.

If you don't want that, don't use it.

> this variable to FALSE. Note that there is still no convention which
> could deprecate this kind of FPHSA()'s usage in config files.

There is, first sentence from the documentation:
 
"FIND_PACKAGE_HANDLE_STANDARD_ARGS(<name> ... )
This function is intended to be used in FindXXX.cmake modules files."

Alex



More information about the cmake-developers mailing list