[cmake-developers] find_package without REQUIRED can cause fatal error now

Brad King brad.king at kitware.com
Mon Jul 30 10:58:12 EDT 2012


On 07/30/2012 10:41 AM, David Cole wrote:
> Seems like "message(FATAL_ERROR/SEND_ERROR" needs to know whether it's
> in the middle of a find_package( OPTIONAL ) call or not.
> 
> What would happen if the only line of code in a project config file is:
> 
>   message(FATAL_ERROR "not implemented yet")
> 
> And then somebody did a find_package(OPTIONAL on that package?
> 
> The contents of hand-written project config files are arbitrary, and
> we can't stop people from putting FATAL_ERRORs in them. So we should
> deal with it generically internal to CMake somehow.

One could also have:

 $ cat lib/cmake/myproj/MyProjConfig.cmake
 Oops, this is not a CMake language file.  Uh oh.

and find_package could deal with it only by sandboxing the entire
load process.  This problem was not created by Alex's check.  His
check is only one instance of the conditions for the underlying
problem.

Sandboxing the entire operation is not achievable in our
current CMake language implementation.  It's not even fully
possible because the scripts could always do things that are
externally visible and not reversible like execute_process.

I'm not sure sandboxing any and all errors inside package
configuration files is the right thing either.  As a user
expecting find_package to locate a particular installation
that I do not know is corrupted I might bang my head against
the desk wondering why CMake is ignoring it.  We would have
to dump the entire output from the attempted/failed load as
a warning.

What do we do after such failure?  Ignore the instance and
continue to search for another one?  Consider the package
to be not found?  The answer should be consistent with what
happens since this change:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=16c0c737

when a package config file sets <package>_FOUND to FALSE.

-Brad



More information about the cmake-developers mailing list