Automatic recording of required packages...

Alexander Neundorf neundorf at kde.org
Mon Nov 8 21:08:42 CET 2010


On Monday 08 November 2010, David Faure wrote:
> On Wednesday 03 November 2010, Alexander Neundorf wrote:
> > -- Package FOO was not found !
> > and then cmake continues.
> > Let's say now it hits a place which would trigger the error "variable is
> > set  to NOTFOUND but used".
> > What should it do ?
> > Ignore it, since a find_package() failed ?
> > This would mean also ignoring it if it is for an unrelated variable from
> > another find-module.
> > Would you think that's ok ?
>
> If the summary at the end of the build says "the following required
> packages were not found: FOO, BAR", then the user will have to install
> these before he can run configure again, and finally see (if it's still
> there) the error about an unrelated variable. So I would say this is ok,
> yes -- but I can see how this is only ok when the "summary at end of build"
> is shown. This is exactly why I was saying cmake should do that
> automatically, so that people can't forget to do it :-)
>
> > But also other things can go wrong when skipping the "REQUIRED" argument:
> > find_package(FLEX)
> > execute_process(COMMAND ${FLEX_EXECUTABLE} -some -weird -arguments)
>
> Well, this already goes wrong, nothing new there. It's just that fixing
> this can either be done by adding REQUIRED and stopping there, or by adding
> an if() and showing errors at the end.

Yes, but with the above suggestion I would expect that cmake also catches this 
case somehow if FLEX_EXECUTABLE hasn't been found. If it doesn't, you have to 
add code to handle the failure case nevertheless. And then I would consider 
this as inconsistent behaviour from the cmake:

find_package(Foo)

if (FOO_FOUND) # necessary because cmake doesn't catch the error here
   execute_process(COMMAND ${FOO_EXECUTABLE} ...)
endif()

add_executable(blub main.cpp)

# no if() necessary because here cmake catches the error
target_link_libraries(blub ${FOO_LIBRARY})


The idea in cmake behind the REQUIRED keyword is more or less like the 
following: if a package is mandatory, add REQUIRED to find_package(), and 
then you can be sure that the stuff exists later on.
If it is not required, don't use REQUIRED, but add code which handles the case 
that it hasn't been found.

What we are discussing here is to add code for handling the case that a 
required package hasn't been found.
This seems like unnecessary work for the ones writing the cmake files.
It saves work for those who just want to build the software later on, _if_ 
this is done properly.

Alex


More information about the Kde-buildsystem mailing list