Choosing whether a dependency is optional or required.

Andreas Pakulat apaku at gmx.de
Sat Jan 29 16:15:56 CET 2011


On 29.01.11 11:32:01, Raphael Kubo da Costa wrote:
> I've recently committed a patch to Kopete's Yahoo! protocol that makes
> libjasper required when the protocol is built.
> 
> As I can see, the other Kopete protocols usually check for their
> dependencies in the top-level CMakeLists.txt with
> 
>   macro_optional_find_package(Foo)
>   macro_log_feature(... FALSE ...) # FALSE for the required parameter
> 
> and then, in protocols/CMakeLists.txt they do something along these
> lines:
> 
>   if (WITH_someprotocol AND FOO_FOUND)
>     add_subdirectory(someprotocol)
>   else (WITH_someprotocol AND FOO_FOUND)
>     message(STATUS "Not building someprotocol")
>   endif (WITH_someprotocol AND FOO_FOUND)
> 
> The "Not building" messages are shown right before the list of optional
> and required dependencies which have been found/not found, and Foo is
> shown as an optional dependency which could not be found.
> 
> On the other hand, in the patch I've applied the checking is done
> differently:
> 
>   # protocols/CMakeLists.txt
>   if (WITH_someprotocol)
>     add_subdirectory(someprotocol)
>   endif (WITH_someprotocol)
> 
>   # protocols/someprotocol/CMakeLists.txt
>   find_package(Foo)
>   macro_optional_find_package(... TRUE ...)
> 
> So Foo is listed as a required dependency when the protocol is built.
> 
> In the end, what's the way to go here with regards to considering these
> protocol dependencies required or optional? And is find_package
> preferred here in case we make the dependency required?

Well, there's no policy on this in general I believe. Basically you and
your team need to decide wether specifying WITH_XXX and not having the
dependencies is an error or not. If you decide that its no error, then
the first way would be correct, if you decide otherwise your way would
be better.

Also the default setting of the WITH_XXX options makes a difference
here, as a user I think ideal would be:

check for dependencies
if dependency-found, set WITH_XXX to true (not using FORCE though so I
can still disable) else set WITH_XX to false (again not with FORCE)
if WITH_XXX is set to true, consider it an error if the dependencies are
not found and log it with macro_optional_find_package( ... TRUE ... ).

Andreas

-- 
You will be reincarnated as a toad; and you will be much happier.


More information about the Kde-buildsystem mailing list