[CMake] find_package Module/Config mode and nontrivial package version checks

Brad King brad.king at kitware.com
Fri Oct 5 07:45:48 EDT 2018


On 10/04/2018 02:36 PM, Joachim Wuttke wrote:
> What then about user code that ought to check
> for version compatibility? Module mode only offers a check
> for an EXACT version string, and does not terminate if
> that condition is not met [3].

Module mode is only selected if there is a Find<PakcageName>.cmake
file available.  Otherwise Config mode is used anyway.  For a given
project's call only one of the modes can be used: the find module
is either present or it is not.  If the find module is available
it is used and becomes responsible for enforcing the version check.
Many of CMake's upstream find modules now support that.

> Users who need a newer-than
> or same-major version check, or a strict enforcment of an
> exact-version check, are advised to prefer packages that use
> CMakePackageConfigHelpers to generate FooConfig[Version].cmake
> files. These files, however, are ignored unless Config mode
> is chosen.

In module mode it is up to the find module to do the appropriate
version comparisons.  The FindPackageHandleStandardArgs module:

  https://cmake.org/cmake/help/v3.13/module/FindPackageHandleStandardArgs.html

provides some help with that.  If it doesn't offer the kind of
version comparison needed then it could be added as an option or
the find module could do its own version checking.

-Brad


More information about the CMake mailing list