[cmake-developers] Adding argument "OPTIONAL" to find_package() and add_subdirectory

Alexander Neundorf neundorf at kde.org
Sun Jun 5 18:44:54 EDT 2011


On Sunday, June 05, 2011 11:50:50 PM Eric Noulard wrote:
> 2011/6/4 Alexander Neundorf <neundorf at kde.org>:
> > Hi,
> > 
> > again from the KDE sprint...
> > 
> > 1) We have a macro
> > macro_optional_find_package().
> > The purpose is to be able to build without a specific package even if
> > that package is installed and would actually be found by the
> > find_package() call.
> > 
> > Basically this is a wrapper around find_package(), but additionally it
> > adds an option WITH_Foo, which is enabled by default.
> > If disabled, the actual find_package() is not executed, and the variables
> > FOO_FOUND/INCLUDES/LIBRARIES are reset to empty, so that even if the
> > package hasn't been searched this time, results from previous runs are
> > discarded.
> > 
> > What do you think about adding this as a built-in feature to
> > find_package(), i.e. add a argument OPTIONAL to find_package(), then
> > probably also a "COMMENT".
> 
> I'm not sure about this feature and since we already have REQUIRED why
> would be the meaning of OPTIONAL?

Using OPTIONAL and REQUIRED together should be considered an error.
OPTIONAL means you can disable the searching so that it will also not be 
"found" even if it is actually installed.

> May be some syntax like
> 
> find_package(Foo IF <VarName>) would be clearer.
> 
> find_package(Foo IF  BUILD_WITH_Foo)
> 
> would create option BUILD_WITH_Foo
> (default value would the value of BUILD_WITH_Foo_Default var or ON if
> it is not defined)
> and the search of the package will be done iff the option is ON.

Maybe.
I thought OPTIONAL would be good since it hints at "OPTION", and it is an 
option which is created for disabling it.
Could also be "OPTION" instead of "OPTIONAL".

...
> > Both have been proven useful, the one for find_package() especially for
> > packagers.
> 
> Agreed, the feature is nice I use similar thing with hand-crafted
> option in some project.

Alex



More information about the cmake-developers mailing list