[cmake-developers] find_package() in Config-mode and required version numbers
Brad King
brad.king at kitware.com
Wed Aug 25 17:50:04 EDT 2010
On 08/25/2010 04:59 PM, Alexander Neundorf wrote:
> Now to find_package(NO_MODULE), i.e. in config-mode.
> This fails when a version is specified but no version information could be
> found:
>
> --------------------------
> CMake Warning at FindAutomoc4.cmake:51 (find_package):
> Could not find a configuration file for package Automoc4.
[snip]
> I think this can be improved a lot, question is, how ?
Yes, this was discussed on the user list recently:
http://www.cmake.org/pipermail/cmake/2010-August/038732.html
> I think in this case it should state that it found Automoc4Config.cmake, and
> also which version it found, and that the version was not good enough, and
> fail.
It should not accept bad versions (see below), but it can record the
list of config files that it finds along the way as each is rejected.
If ultimately a suitable version is not found then the error message
can replay the list already recorded.
The place to record the list of attempted versions is in the method
cmFindPackageCommand::FindConfigFile when the FileExists returns
true but before the call to CheckVersion.
> --------------------
> If it found a Automoc4Config.cmake but no Automoc4ConfigVersion.cmake,
> I would prefer to print a warning, but still accept the package.
Absolutely not.
(1) It might be a wrong version, and it is perfectly possible to find
a correct version later in the search path. Consider a package that
in older versions did not provide a package version file but newer
versions do. Furthermore, consider when both are installed but the
older one happens to come first in the search path. In my call to
find_package I specify a version that is new enough that I know the
package version file will be present. In the behavior you propose
the old version of the package will be found incorrectly and also
block the newer one from being found.
(2) Package developers may not realize they need to distribute a package
version file because a versioned find appears to work without it. I
really want package developers to provide version files. Anything that
decreases motivation for this is unacceptable. Currently a versioned
find will not work without the version file, so package developers will
discover they need one during testing.
> Otherwise it would behave different than in non-config mode, and in non-config
> mode it must accept a package where the version is unknown.
The config-mode is all about providing precise and complete information
to the caller. Just because the module mode is not always capable of
doing this does not mean the config mode should be made weaker to match.
> --------------------
> If I wrap the find_package(NO_MODULE) in a normal find-module, with the QUIET
> NO_MODULE options, I don't get much information out of it, except that it
> failed.
Sure, this is something to address.
> I'd like to be able to get some result information out of find_package(),
> which I can then use in FPHSA(). Maybe something like
>
> find_package(Foo QUIET NO_MODULE
> FOUND_CONFIG_FILE foundFile
> FOUND_VERSION foundVersion
> IGNORE_ERRORS)
>
> find_package_handle_standard_args(Foo REQUIRED_VARS foundFile
> VERSION_VAR foundVersion)
Isn't this just:
find_package(Foo QUIET NO_MODULE) # Propagates version automatically!
find_package_handle_standard_args(Foo REQUIRED_VARS Foo_CONFIG
VERSION_VAR Foo_VERSION)
already (except for the list of improper versions discovered)?
> (The "IGNORE_ERRORS" would be necessary so it doesn't abort, but
> the error handling is left to FPHSA().
This is not needed. It does not abort when REQUIRED is not given.
It does not print anything when QUIET is given.
> With this, FPHSA() would print:
>
> -- Could NOT find Foo: Found version "1.0.0", but required is at
> least "1.2.3" (found /opt/foo/lib/cmake/Foo/FooConfig.cmake)
>
> IMO this would be a reasonable error message.
All that's missing is a way for the QUIET mode to give enough
information to the caller to report a more detailed error message.
We need an option to retrieve the list of bad versions rejected
during its search (there can be more than one). Perhaps it is
simplest to just always report the list of config files considered
whether one is accepted or not:
find_package(Foo QUIET NO_MODULE)
message("considered: ${Foo_CONSIDERED_CONFIGS}")
message("considered: ${Foo_CONSIDERED_VERSIONS}")
The two lists are the same length. Each entry in the _CONFIGS
list is the file name. Each entry in the _VERSIONS list is
either "unknown" or the version number reported by the version
file.
-Brad
More information about the cmake-developers
mailing list