[cmake-developers] find_package() in Config-mode and required version numbers

Alexander Neundorf neundorf at kde.org
Wed Aug 25 16:59:06 EDT 2010


Hi,

for find_package() it is possible to specify a minimum required version number 
of the package:
find_package(Foo 1.2.3)

Short version of the question: what do we do if in this case Foo is found, but 
the version number is unknown ?

What find_package_handle_standard_args() does in this case is to accept the 
package anyway.
In the first version it did reject the package in this case, but for "normal" 
Find-module this resulted in too many packages which were not found anymore 
suddenly (because e.g. in some find-modules the version is determined via 
pkg-config, so it failed in all cases where the package was found without 
pkg-config).

In the second version of fphsa() it did accept the package then, but print a 
warning:
"WARNING: Required version is "1.2.3", but version of Foo is unknown"

In the 3rd (and current version) it doesn't print that warning anymore but 
just accepts the package. Actually I liked the version with the warning more, 
but there were people who thought it is actually an error message and were 
confused, so I removed it.

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.

  Set Automoc4_DIR to the directory containing a CMake configuration file for
  Automoc4.  The file will have one of the following names:

    Automoc4Config.cmake
    automoc4-config.cmake

Call Stack (most recent call first):
  CMakeLists.txt:5 (find_package)
--------------------------

I think this can be improved a lot, question is, how ?

What is says is actually wrong. It did find a Automoc4Config.cmake file and 
also a Automoc4ConfigVersion.cmake file, but the version was not good.

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. 

--------------------
If it found a Automoc4Config.cmake but no Automoc4ConfigVersion.cmake, I would 
prefer to print a warning, but still accept the package.

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.

--------------------
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.
This is what fphsa() can print for automoc4 then:
-- Did not find automoc4 (Automoc4Config.cmake, part of kdesupport).
      (missing:  AUTOMOC4_EXECUTABLE)  (Required is at least version "6.9")

This is clearly also not good.
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)

(The "IGNORE_ERRORS" would be necessary so it doesn't abort, but the error 
handling is left to FPHSA().
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.

What do you think ?


Alex



More information about the cmake-developers mailing list