From 0ae545ebad1b6b2a6c851205854b887d19c8da59 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 3 Oct 2008 10:41:15 -0400 Subject: ENH: Add UNSUITABLE result to package version test Package version test files may now declare that they are unsuitable for use with the project testing them. This is important when the version being tested does not provide a compatible ABI with the project target environment. --- Source/cmFindPackageCommand.cxx | 21 ++++++++++++++------- .../lib/zot/zot-config-version.cmake | 10 ++++++++++ Tests/FindPackageTest/lib/zot/zot-config.cmake | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 Tests/FindPackageTest/lib/zot/zot-config-version.cmake create mode 100644 Tests/FindPackageTest/lib/zot/zot-config.cmake diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 61595df..bb47a36 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -190,6 +190,7 @@ cmFindPackageCommand::cmFindPackageCommand() " PACKAGE_VERSION = full provided version string\n" " PACKAGE_VERSION_EXACT = true if version is exact match\n" " PACKAGE_VERSION_COMPATIBLE = true if version is compatible\n" + " PACKAGE_VERSION_UNSUITABLE = true if unsuitable as any version\n" "These variables are checked by the find_package command to determine " "whether the configuration file provides an acceptable version. " "They are not available after the find_package call returns. " @@ -1273,6 +1274,7 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file) // Clear the output variables. this->Makefile->RemoveDefinition("PACKAGE_VERSION"); + this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE"); this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE"); this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT"); @@ -1293,16 +1295,21 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file) this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COUNT", buf); // Load the version check file. - bool found = false; + bool suitable = false; if(this->ReadListFile(version_file.c_str())) { // Check the output variables. - found = this->Makefile->IsOn("PACKAGE_VERSION_EXACT"); - if(!found && !this->VersionExact) + bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT"); + bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE"); + if(!okay && !this->VersionExact) { - found = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE"); + okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE"); } - if(found || this->Version.empty()) + + // The package is suitable if the version is okay and not + // explicitly unsuitable. + suitable = !unsuitable && (okay || this->Version.empty()); + if(suitable) { // Get the version found. this->VersionFound = @@ -1332,8 +1339,8 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file) // Restore the original scope. this->Makefile->PopScope(); - // Succeed if the version was found or no version was requested. - return found || this->Version.empty(); + // Succeed if the version is suitable. + return suitable; } //---------------------------------------------------------------------------- diff --git a/Tests/FindPackageTest/lib/zot/zot-config-version.cmake b/Tests/FindPackageTest/lib/zot/zot-config-version.cmake new file mode 100644 index 0000000..2a6be86 --- /dev/null +++ b/Tests/FindPackageTest/lib/zot/zot-config-version.cmake @@ -0,0 +1,10 @@ +# This version should never, ever be used. +SET(PACKAGE_VERSION_UNSUITABLE 1) +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) + diff --git a/Tests/FindPackageTest/lib/zot/zot-config.cmake b/Tests/FindPackageTest/lib/zot/zot-config.cmake new file mode 100644 index 0000000..442b8a4 --- /dev/null +++ b/Tests/FindPackageTest/lib/zot/zot-config.cmake @@ -0,0 +1,2 @@ +# Test config file that is unsuitable. +MESSAGE(FATAL_ERROR "Unsuitable version of zot was found") -- cgit v0.12