find_package Module/Config mode and nontrivial package version checks

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

find_package Module/Config mode and nontrivial package version checks

j1wuttke
The find_package command docs [1,2] recommend that user code
should generally look for packages using the Module mode
signature. 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]. 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.

Is this summary correct? Shouldn't then the general recommendation
of Module mode be qualified?

- Joachim

[1] https://cmake.org/cmake/help/v3.12/command/find_package.html
[2] https://gitlab.kitware.com/cmake/cmake/merge_requests/2446
[3] https://stackoverflow.com/questions/52633455



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: find_package Module/Config mode and nontrivial package version checks

Brad King
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
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: find_package Module/Config mode and nontrivial package version checks

j1wuttke
> 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.

Thank you, Brad.

Find modules are written in so many different styles that it is
difficult to choose the right one as template. Could you possibly
indicate one or two find modules that represent current best
practice?

- Joachim


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

smime.p7s (6K) Download Attachment