Commit 41c2895b authored by Brad King's avatar Brad King 💬

ENH: Added version support to Config mode of find_package command.

  - Added EXACT option to request an exact version.
  - Enforce version using check provided by package.
  - Updated FindPackageTest to test versioning in config mode.
parent 404db881
......@@ -67,19 +67,20 @@ line.
A FindXXX.cmake module will typically be loaded by the command
FIND_PACKAGE(XXX [major[.minor[.patch]]]
FIND_PACKAGE(XXX [major[.minor[.patch]]] [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. 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.
portions of the version number. The variable XXX_FIND_VERSION_EXACT
will indicate whether an exact version is requested.
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.
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.
......@@ -80,12 +80,16 @@ private:
bool FindFrameworkConfig();
bool FindAppBundleConfig();
bool ReadListFile(const char* f);
void StoreVersionFound();
void AddUserPath(std::string const& p);
void ComputePrefixes();
bool SearchDirectory(std::string const& dir);
bool CheckDirectory(std::string const& dir);
bool FindConfigFile(std::string const& dir, std::string& file);
bool FindConfigFileToLoad(std::string const& dir, std::string& file);
bool CheckVersion(std::string const& config_file);
bool CheckVersionFile(std::string const& version_file);
bool SearchPrefix(std::string const& prefix);
bool SearchFrameworkPrefix(std::string const& prefix_in);
bool SearchAppBundlePrefix(std::string const& prefix_in);
......@@ -100,7 +104,13 @@ private:
unsigned int VersionMinor;
unsigned int VersionPatch;
unsigned int VersionCount;
bool VersionExact;
cmStdString FileFound;
cmStdString VersionFound;
unsigned int VersionFoundMajor;
unsigned int VersionFoundMinor;
unsigned int VersionFoundPatch;
unsigned int VersionFoundCount;
bool Quiet;
bool Required;
bool Compatibility_1_6;
......
......@@ -32,7 +32,10 @@ FIND_PACKAGE(VersionTestC 1.2.3)
#SET(CMAKE_FIND_DEBUG_MODE 1)
# For purposes of the test wipe out previous find results.
SET(PACKAGES foo Foo Bar TFramework Tframework TApp Tapp Special)
SET(PACKAGES
foo Foo Bar TFramework Tframework TApp Tapp Special
VersionedA VersionedB
)
FOREACH(p ${PACKAGES})
SET(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
ENDFOREACH(p)
......@@ -51,6 +54,8 @@ FIND_PACKAGE(Tframework)
FIND_PACKAGE(TApp)
FIND_PACKAGE(Tapp CONFIGS tapp-config.cmake)
FIND_PACKAGE(Special NAMES Suffix SuffixTest PATH_SUFFIXES test)
FIND_PACKAGE(VersionedA 2 NAMES zot)
FIND_PACKAGE(VersionedB 3.1 EXACT NAMES zot)
# Expected locations at which packages should be found.
SET(foo_EXPECTED "lib/foo-1.2/foo-config.cmake")
......@@ -65,6 +70,8 @@ SET(TApp_EXPECTED
"TApp.app/Contents/Resources/TAppConfig.cmake")
SET(Tapp_EXPECTED
"TApp.app/Contents/Resources/cmake/tapp-config.cmake")
SET(VersionedA_EXPECTED "lib/zot-2.0/zot-config.cmake")
SET(VersionedB_EXPECTED "lib/zot-3.1/zot-config.cmake")
# Check the results.
FOREACH(p ${PACKAGES})
......@@ -88,3 +95,43 @@ FOREACH(p ${PACKAGES})
MESSAGE(SEND_ERROR "Package ${p} not found!")
ENDIF(${p}_FOUND)
ENDFOREACH(p)
# Check that version information was extracted.
IF(NOT "${VersionedA_VERSION}" STREQUAL "2.0")
MESSAGE(SEND_ERROR
"Package VersionedA is version [${VersionedA_VERSION}], not [2.0]")
ENDIF(NOT "${VersionedA_VERSION}" STREQUAL "2.0")
IF(NOT "${VersionedA_VERSION_MAJOR}" STREQUAL "2")
MESSAGE(SEND_ERROR
"Package VersionedA is major version [${VersionedA_VERSION_MAJOR}], not [2]")
ENDIF(NOT "${VersionedA_VERSION_MAJOR}" STREQUAL "2")
IF(NOT "${VersionedA_VERSION_MINOR}" STREQUAL "0")
MESSAGE(SEND_ERROR
"Package VersionedA is minor version [${VersionedA_VERSION_MINOR}], not [0]")
ENDIF(NOT "${VersionedA_VERSION_MINOR}" STREQUAL "0")
IF(NOT "${VersionedB_VERSION}" STREQUAL "3.1")
MESSAGE(SEND_ERROR
"Package VersionedB is version [${VersionedB_VERSION}], not [3.1]")
ENDIF(NOT "${VersionedB_VERSION}" STREQUAL "3.1")
IF(NOT "${VersionedB_VERSION_MAJOR}" STREQUAL "3")
MESSAGE(SEND_ERROR
"Package VersionedB is major version [${VersionedB_VERSION_MAJOR}], not [3]")
ENDIF(NOT "${VersionedB_VERSION_MAJOR}" STREQUAL "3")
IF(NOT "${VersionedB_VERSION_MINOR}" STREQUAL "1")
MESSAGE(SEND_ERROR
"Package VersionedB is minor version [${VersionedB_VERSION_MINOR}], not [1]")
ENDIF(NOT "${VersionedB_VERSION_MINOR}" STREQUAL "1")
IF(NOT "${Special_VERSION}" STREQUAL "1.2")
MESSAGE(SEND_ERROR
"Package Special is version [${Special_VERSION}], not [1.2]")
ENDIF(NOT "${Special_VERSION}" STREQUAL "1.2")
IF(NOT "${Special_VERSION_MAJOR}" STREQUAL "1")
MESSAGE(SEND_ERROR
"Package Special is major version [${Special_VERSION_MAJOR}], not [1]")
ENDIF(NOT "${Special_VERSION_MAJOR}" STREQUAL "1")
IF(NOT "${Special_VERSION_MINOR}" STREQUAL "2")
MESSAGE(SEND_ERROR
"Package Special is minor version [${Special_VERSION_MINOR}], not [2]")
ENDIF(NOT "${Special_VERSION_MINOR}" STREQUAL "2")
SET(PACKAGE_VERSION 1.2)
IF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
SET(PACKAGE_VERSION_COMPATIBLE 1)
IF("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 2)
SET(PACKAGE_VERSION_EXACT 1)
ENDIF("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 2)
ENDIF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
SET(PACKAGE_VERSION 2.0)
IF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 2)
SET(PACKAGE_VERSION_COMPATIBLE 1)
ENDIF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 2)
SET(PACKAGE_VERSION 3.0)
IF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
SET(PACKAGE_VERSION_COMPATIBLE 1)
ENDIF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
SET(PACKAGE_VERSION 3.1)
IF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
SET(PACKAGE_VERSION_COMPATIBLE 1)
IF("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 1)
SET(PACKAGE_VERSION_EXACT 1)
ENDIF("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 1)
ENDIF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 3)
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