[CMake] Find package with version numbers

Alexander Neundorf a.neundorf-work at gmx.net
Wed Dec 14 17:11:45 EST 2011


On Wednesday 14 December 2011, Robert Dailey wrote:
> Is there any example of how to write a find module for find_package() that
> utilizes version numbers? How is the version number passed into the
> Find*.cmake module? The documentation on this is very confusing and
> discusses creating a version.cmake file. I looked in the CMake modules
> directory for an example but there are no version files...
> 
> I'm creating a find module for the Microsoft Platform SDK:
> FindMSPlatformSDK.cmake. I need to be able to call it like so:
> 
> find_package( MSPlatformSDK 7.0 )

See the readme file in the cmake modules directory.

In the Find-module, you have access to 
<name_of_the_package>_FIND_VERSION_(MAJOR|MINOR|PATCH) etc. variables which 
you can check.

If you determine the version of the found package, you can then simply put the 
found version number into a variable, and use the new-style 
find_package_handle_standard_args(... VERSION_VAR ...) macro to evaluate it, 
it will fail if it is not good.

For creating a FooConfigVersion.cmake file (when installing your own library), 
you may use the WriteBasicConfigVersionFile.cmake (since cmake 2.8.6) which 
writes a basic version file for you, which you can install along with your 
library.

Alex


More information about the CMake mailing list