[cmake-developers] Adding argument "OPTIONAL" to find_package() and add_subdirectory
Alexander Neundorf
neundorf at kde.org
Thu Jun 9 02:58:32 EDT 2011
On Wednesday 08 June 2011, Brad King wrote:
> On 6/8/2011 2:08 PM, Alexander Neundorf wrote:
> > This would make the options available for cmake-based projects more
> > consistent.
> > This issue comes up regularly from new users.
>
> The option() command adds options. The add_subdirectory command
> adds subdirectories. The find_package command finds packages.
> These are well-defined primitives. I don't want to change this.
>
> http://en.wikipedia.org/wiki/Law_of_Demeter
>
> > So, I don't see a reason why such an option should not be the default
> > behaviour and why I should rely on an external extension.
>
> With that goal in mind I see no reason not to do this in a module
> that comes with CMake:
>
> include(OptionalFindPackage)
> optional_find_package(XYZ)
But I still don't see a reason why I should not use optional_find_package()
and use find_package(...without REQUIRED) instead. And there are good reasons
to use the optional one always if the package is not REQUIRED.
This wish comes mainly from packagers, not from the developers themselves.
I am sure packagers would be happy if they had one consistent way to disable
every package any cmake checks for with a standardized option.
Implementation could look something like
cmFindPackage::cmFindPackage()
{
if (! mf->IsOn(DISABLE_FIND_PACKAGE_<name>)
{
cacheVars = getAllCacheVars();
doNormalFinding();
newCacheVars = getAllCacheVars();
addedCacheVars = newCacheVars - cacheVars;
FIND_PACKAGE_<name>_CACHE_VARS = addedCacheVars;
put FIND_PACKAGE_<name>_CACHE_VARS in the cache
}
else // it is disabled
{
get FIND_PACKAGE_<name>_CACHE_VARS from cache
remove all variables listed there from cache
set <name>_FOUND to FALSE
}
}
We could put this functionality into the to-be-created extra-cmake-modules
package, or how it will be called, but after some thinking I thought it
benefits cmake much more if this option would be always available for all non-
REQUIRED find_package() calls without the developer having to care about it.
Alex
More information about the cmake-developers
mailing list