Commit 994262e5 authored by Brad King's avatar Brad King

ENH: Improve find_package version numbering

Make the number of version components specified explicitly available.
Set variables for unspecified version components to "0" instead of
leaving them unset.  This simplifies version number handling for find-
and config-modules.  Also support a fourth "tweak" version component
since some packages use them.
parent 4eaac32d
......@@ -67,20 +67,25 @@ line.
A FindXXX.cmake module will typically be loaded by the command
FIND_PACKAGE(XXX [major[.minor[.patch]]] [EXACT]
FIND_PACKAGE(XXX [major[.minor[.patch[.tweak]]]] [EXACT]
[QUIET] [REQUIRED [components...]])
If any version numbers are given to the command it will set the
variable XXX_FIND_VERSION to contain the whole version. The variables
XXX_FIND_VERSION_MAJOR, XXX_FIND_VERSION_MINOR, and
XXX_FIND_VERSION_PATCH will be set to contain the corresponding
portions of the version number. The variable XXX_FIND_VERSION_EXACT
will indicate whether an exact version is requested.
following variables before loading the module:
XXX_FIND_VERSION = full requested version string
XXX_FIND_VERSION_MAJOR = major version if requested, else 0
XXX_FIND_VERSION_MINOR = minor version if requested, else 0
XXX_FIND_VERSION_PATCH = patch version if requested, else 0
XXX_FIND_VERSION_TWEAK = tweak version if requested, else 0
XXX_FIND_VERSION_COUNT = number of version components, 0 to 4
XXX_FIND_VERSION_EXACT = true if EXACT option was given
If the find module supports versioning it should locate a version of
the package that is compatible with the version requested. If a
compatible version of the package cannot be found the module should
not report success. The version of the package found should be stored
in the version variables named above.
in "XXX_VERSION..." version variables docmented by the module.
If the QUIET option is given to the command it will set the variable
XXX_FIND_QUIETLY to true before loading the FindXXX.cmake module. If
......
This diff is collapsed.
......@@ -111,6 +111,7 @@ private:
unsigned int VersionMajor;
unsigned int VersionMinor;
unsigned int VersionPatch;
unsigned int VersionTweak;
unsigned int VersionCount;
bool VersionExact;
cmStdString FileFound;
......@@ -118,6 +119,7 @@ private:
unsigned int VersionFoundMajor;
unsigned int VersionFoundMinor;
unsigned int VersionFoundPatch;
unsigned int VersionFoundTweak;
unsigned int VersionFoundCount;
bool Quiet;
bool Required;
......
......@@ -27,6 +27,7 @@ LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(VersionTestA 1)
FIND_PACKAGE(VersionTestB 1.2)
FIND_PACKAGE(VersionTestC 1.2.3)
FIND_PACKAGE(VersionTestD 1.2.3.4)
#-----------------------------------------------------------------------------
......
......@@ -4,9 +4,15 @@ ENDIF(NOT "${VersionTestA_FIND_VERSION}" STREQUAL "1")
IF(NOT "${VersionTestA_FIND_VERSION_MAJOR}" STREQUAL "1")
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_MAJOR=${VersionTestA_FIND_VERSION_MAJOR} is not 1")
ENDIF(NOT "${VersionTestA_FIND_VERSION_MAJOR}" STREQUAL "1")
IF(DEFINED VersionTestA_FIND_VERSION_MINOR)
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_MINOR should not be defined")
ENDIF(DEFINED VersionTestA_FIND_VERSION_MINOR)
IF(DEFINED VersionTestA_FIND_VERSION_PATCH)
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_PATCH should not be defined")
ENDIF(DEFINED VersionTestA_FIND_VERSION_PATCH)
IF(NOT "${VersionTestA_FIND_VERSION_MINOR}" STREQUAL "0")
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_MINOR=${VersionTestA_FIND_VERSION_MINOR} is not 0")
ENDIF(NOT "${VersionTestA_FIND_VERSION_MINOR}" STREQUAL "0")
IF(NOT "${VersionTestA_FIND_VERSION_PATCH}" STREQUAL "0")
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_PATCH=${VersionTestA_FIND_VERSION_PATCH} is not 0")
ENDIF(NOT "${VersionTestA_FIND_VERSION_PATCH}" STREQUAL "0")
IF(NOT "${VersionTestA_FIND_VERSION_TWEAK}" STREQUAL "0")
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_TWEAK=${VersionTestA_FIND_VERSION_TWEAK} is not 0")
ENDIF(NOT "${VersionTestA_FIND_VERSION_TWEAK}" STREQUAL "0")
IF(NOT "${VersionTestA_FIND_VERSION_COUNT}" STREQUAL "1")
MESSAGE(SEND_ERROR "VersionTestA_FIND_VERSION_COUNT=${VersionTestA_FIND_VERSION_COUNT} is not 1")
ENDIF(NOT "${VersionTestA_FIND_VERSION_COUNT}" STREQUAL "1")
......@@ -7,6 +7,12 @@ ENDIF(NOT "${VersionTestB_FIND_VERSION_MAJOR}" STREQUAL "1")
IF(NOT "${VersionTestB_FIND_VERSION_MINOR}" STREQUAL "2")
MESSAGE(SEND_ERROR "VersionTestB_FIND_VERSION_MINOR=${VersionTestB_FIND_VERSION_MINOR} is not 2")
ENDIF(NOT "${VersionTestB_FIND_VERSION_MINOR}" STREQUAL "2")
IF(DEFINED VersionTestB_FIND_VERSION_PATCH)
MESSAGE(SEND_ERROR "VersionTestB_FIND_VERSION_PATCH should not be defined")
ENDIF(DEFINED VersionTestB_FIND_VERSION_PATCH)
IF(NOT "${VersionTestB_FIND_VERSION_PATCH}" STREQUAL "0")
MESSAGE(SEND_ERROR "VersionTestB_FIND_VERSION_PATCH=${VersionTestB_FIND_VERSION_PATCH} is not 0")
ENDIF(NOT "${VersionTestB_FIND_VERSION_PATCH}" STREQUAL "0")
IF(NOT "${VersionTestB_FIND_VERSION_TWEAK}" STREQUAL "0")
MESSAGE(SEND_ERROR "VersionTestB_FIND_VERSION_TWEAK=${VersionTestB_FIND_VERSION_TWEAK} is not 0")
ENDIF(NOT "${VersionTestB_FIND_VERSION_TWEAK}" STREQUAL "0")
IF(NOT "${VersionTestB_FIND_VERSION_COUNT}" STREQUAL "2")
MESSAGE(SEND_ERROR "VersionTestB_FIND_VERSION_COUNT=${VersionTestB_FIND_VERSION_COUNT} is not 2")
ENDIF(NOT "${VersionTestB_FIND_VERSION_COUNT}" STREQUAL "2")
......@@ -10,3 +10,9 @@ ENDIF(NOT "${VersionTestC_FIND_VERSION_MINOR}" STREQUAL "2")
IF(NOT "${VersionTestC_FIND_VERSION_PATCH}" STREQUAL "3")
MESSAGE(SEND_ERROR "VersionTestC_FIND_VERSION_PATCH=${VersionTestC_FIND_VERSION_PATCH} is not 3")
ENDIF(NOT "${VersionTestC_FIND_VERSION_PATCH}" STREQUAL "3")
IF(NOT "${VersionTestC_FIND_VERSION_TWEAK}" STREQUAL "0")
MESSAGE(SEND_ERROR "VersionTestC_FIND_VERSION_TWEAK=${VersionTestC_FIND_VERSION_TWEAK} is not 0")
ENDIF(NOT "${VersionTestC_FIND_VERSION_TWEAK}" STREQUAL "0")
IF(NOT "${VersionTestC_FIND_VERSION_COUNT}" STREQUAL "3")
MESSAGE(SEND_ERROR "VersionTestC_FIND_VERSION_COUNT=${VersionTestC_FIND_VERSION_COUNT} is not 3")
ENDIF(NOT "${VersionTestC_FIND_VERSION_COUNT}" STREQUAL "3")
IF(NOT "${VersionTestD_FIND_VERSION}" STREQUAL "1.2.3.4")
MESSAGE(SEND_ERROR "VersionTestD_FIND_VERSION=${VersionTestD_FIND_VERSION} is not 1.2.3.4")
ENDIF(NOT "${VersionTestD_FIND_VERSION}" STREQUAL "1.2.3.4")
IF(NOT "${VersionTestD_FIND_VERSION_MAJOR}" STREQUAL "1")
MESSAGE(SEND_ERROR "VersionTestD_FIND_VERSION_MAJOR=${VersionTestD_FIND_VERSION_MAJOR} is not 1")
ENDIF(NOT "${VersionTestD_FIND_VERSION_MAJOR}" STREQUAL "1")
IF(NOT "${VersionTestD_FIND_VERSION_MINOR}" STREQUAL "2")
MESSAGE(SEND_ERROR "VersionTestD_FIND_VERSION_MINOR=${VersionTestD_FIND_VERSION_MINOR} is not 2")
ENDIF(NOT "${VersionTestD_FIND_VERSION_MINOR}" STREQUAL "2")
IF(NOT "${VersionTestD_FIND_VERSION_PATCH}" STREQUAL "3")
MESSAGE(SEND_ERROR "VersionTestD_FIND_VERSION_PATCH=${VersionTestD_FIND_VERSION_PATCH} is not 3")
ENDIF(NOT "${VersionTestD_FIND_VERSION_PATCH}" STREQUAL "3")
IF(NOT "${VersionTestD_FIND_VERSION_TWEAK}" STREQUAL "4")
MESSAGE(SEND_ERROR "VersionTestD_FIND_VERSION_TWEAK=${VersionTestD_FIND_VERSION_TWEAK} is not 4")
ENDIF(NOT "${VersionTestD_FIND_VERSION_TWEAK}" STREQUAL "4")
IF(NOT "${VersionTestD_FIND_VERSION_COUNT}" STREQUAL "4")
MESSAGE(SEND_ERROR "VersionTestD_FIND_VERSION_COUNT=${VersionTestD_FIND_VERSION_COUNT} is not 4")
ENDIF(NOT "${VersionTestD_FIND_VERSION_COUNT}" STREQUAL "4")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment