[CMake] FIND_PACKAGE, version check

Eric Noulard eric.noulard at gmail.com
Tue Jan 9 10:33:11 EST 2007


2007/1/9, Pierre <pierre.php at gmail.com>:
> Hello,
>
> Being new to this list and cmake, I first like to thank you for cmake,
> it is a pleasure to work with it.
>
> In an attempt to use CMake in libgd (http://libgd.org), I was looking
> for a way to use the versions argument in find_package. For example, I
> have to do something like:
>
> FIND_PACKAGE(Freetype 2.2) or FIND_PACKAGE(Freetype 2.2.1)
>
> I checked the various Find* function in cmake (2.4.3) or the various
> other projects like KDE but they don't seem to check the version
> informations in the cmake Find* macros. My idea was to provide
> FOO_VERSION(_(MAJOR|MINOR|PATH), is it the way to go?

I  don't know the "WAY to go" but I did something similar
for checking version.

You may find it useful to know that if you
SET(FOO_MINIMAL_VERSION "3.4.7")
EXEC_PROGRAM(${FOO_CONFIG_PROGRAM}
    ARGS "--version"
    OUTPUT_VARIABLE FOO_VERSION)

you may easily check for "sufficient" version with something like

IF (FOO_VERSION STRGREATER FOO_MINIMAL_VERSION)
    MESSAGE(STATUS "Be happy with foo ${FOO_VERSION})
ELSE (FOO_VERSION STRGREATER FOO_MINIMAL_VERSION)
    MESSAGE(ERROR "Unable to use version ${FOO_VERSION} of foo...")
ENDIF

-- 
Erk


More information about the CMake mailing list