mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
find_package: Add support of version range
This enhancement is the first step for solving issue #21107
This commit is contained in:

committed by
Marc Chevrier

parent
09095dbcd2
commit
d7df81067b
@@ -34,14 +34,29 @@ Additional optional components may be listed after
|
||||
whether a package is considered to be found are defined by the target
|
||||
package.
|
||||
|
||||
.. _FIND_PACKAGE_VERSION_FORMAT:
|
||||
|
||||
The ``[version]`` argument requests a version with which the package found
|
||||
should be compatible (format is ``major[.minor[.patch[.tweak]]]``). The
|
||||
``EXACT`` option requests that the version be matched exactly. If no
|
||||
``[version]`` and/or component list is given to a recursive invocation
|
||||
should be compatible. There are two possible forms in which it may be
|
||||
specified:
|
||||
|
||||
* A single version with the format ``major[.minor[.patch[.tweak]]]``.
|
||||
* A version range with the format ``versionMin...[<]versionMax`` where
|
||||
``versionMin`` and ``versionMax`` have the same format as the single
|
||||
version. By default, both end points are included. By specifying ``<``,
|
||||
the upper end point will be excluded.
|
||||
|
||||
The ``EXACT`` option requests that the version be matched exactly. This option
|
||||
is incompatible with the specification of a version range.
|
||||
|
||||
If no ``[version]`` and/or component list is given to a recursive invocation
|
||||
inside a find-module, the corresponding arguments are forwarded
|
||||
automatically from the outer call (including the ``EXACT`` flag for
|
||||
``[version]``). Version support is currently provided only on a
|
||||
package-by-package basis (see the `Version Selection`_ section below).
|
||||
When a version range is specified but the package is only designed to expect
|
||||
a single version, the package will ignore the upper end point of the range and
|
||||
only take the single version at the lower end of the range into account.
|
||||
|
||||
See the :command:`cmake_policy` command documentation for discussion
|
||||
of the ``NO_POLICY_SCOPE`` option.
|
||||
@@ -140,10 +155,10 @@ outlined below will find them without requiring use of additional options.
|
||||
Version Selection
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
When the ``[version]`` argument is given Config mode will only find a
|
||||
When the ``[version]`` argument is given, Config mode will only find a
|
||||
version of the package that claims compatibility with the requested
|
||||
version (format is ``major[.minor[.patch[.tweak]]]``). If the ``EXACT``
|
||||
option is given only a version of the package claiming an exact match
|
||||
version (see :ref:`format specification <FIND_PACKAGE_VERSION_FORMAT>`). If the
|
||||
``EXACT`` option is given, only a version of the package claiming an exact match
|
||||
of the requested version may be found. CMake does not establish any
|
||||
convention for the meaning of version numbers. Package version
|
||||
numbers are checked by "version" files provided by the packages
|
||||
@@ -160,31 +175,78 @@ version file is loaded in a nested scope in which the following
|
||||
variables have been defined:
|
||||
|
||||
``PACKAGE_FIND_NAME``
|
||||
the ``<PackageName>``
|
||||
The ``<PackageName>``
|
||||
``PACKAGE_FIND_VERSION``
|
||||
full requested version string
|
||||
Full requested version string
|
||||
``PACKAGE_FIND_VERSION_MAJOR``
|
||||
major version if requested, else 0
|
||||
Major version if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MINOR``
|
||||
minor version if requested, else 0
|
||||
Minor version if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_PATCH``
|
||||
patch version if requested, else 0
|
||||
Patch version if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_TWEAK``
|
||||
tweak version if requested, else 0
|
||||
Tweak version if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_COUNT``
|
||||
number of version components, 0 to 4
|
||||
Number of version components, 0 to 4
|
||||
|
||||
When a version range is specified, the above version variables will hold
|
||||
values based on the lower end of the version range. This is to preserve
|
||||
compatibility with packages that have not been implemented to expect version
|
||||
ranges. In addition, the version range will be described by the following
|
||||
variables:
|
||||
|
||||
``PACKAGE_FIND_VERSION_RANGE``
|
||||
Full requested version range string
|
||||
``PACKAGE_FIND_VERSION_RANGE_MIN``
|
||||
This specifies whether the lower end point of the version range should be
|
||||
included or excluded. Currently, the only supported value for this variable
|
||||
is ``INCLUDE``.
|
||||
``PACKAGE_FIND_VERSION_RANGE_MAX``
|
||||
This specifies whether the upper end point of the version range should be
|
||||
included or excluded. The supported values for this variable are
|
||||
``INCLUDE`` and ``EXCLUDE``.
|
||||
|
||||
``PACKAGE_FIND_VERSION_MIN``
|
||||
Full requested version string of the lower end point of the range
|
||||
``PACKAGE_FIND_VERSION_MIN_MAJOR``
|
||||
Major version of the lower end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MIN_MINOR``
|
||||
Minor version of the lower end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MIN_PATCH``
|
||||
Patch version of the lower end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MIN_TWEAK``
|
||||
Tweak version of the lower end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MIN_COUNT``
|
||||
Number of version components of the lower end point, 0 to 4
|
||||
|
||||
``PACKAGE_FIND_VERSION_MAX``
|
||||
Full requested version string of the upper end point of the range
|
||||
``PACKAGE_FIND_VERSION_MAX_MAJOR``
|
||||
Major version of the upper end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MAX_MINOR``
|
||||
Minor version of the upper end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MAX_PATCH``
|
||||
Patch version of the upper end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MAX_TWEAK``
|
||||
Tweak version of the upper end point if requested, else 0
|
||||
``PACKAGE_FIND_VERSION_MAX_COUNT``
|
||||
Number of version components of the upper end point, 0 to 4
|
||||
|
||||
Regardless of whether a single version or a version range is specified, the
|
||||
variable ``PACKAGE_FIND_VERSION_COMPLETE`` will be defined and will hold
|
||||
the full requested version string as specified.
|
||||
|
||||
The version file checks whether it satisfies the requested version and
|
||||
sets these variables:
|
||||
|
||||
``PACKAGE_VERSION``
|
||||
full provided version string
|
||||
Full provided version string
|
||||
``PACKAGE_VERSION_EXACT``
|
||||
true if version is exact match
|
||||
True if version is exact match
|
||||
``PACKAGE_VERSION_COMPATIBLE``
|
||||
true if version is compatible
|
||||
True if version is compatible
|
||||
``PACKAGE_VERSION_UNSUITABLE``
|
||||
true if unsuitable as any version
|
||||
True if unsuitable as any version
|
||||
|
||||
These variables are checked by the ``find_package`` command to determine
|
||||
whether the configuration file provides an acceptable version. They
|
||||
@@ -192,17 +254,17 @@ are not available after the ``find_package`` call returns. If the version
|
||||
is acceptable the following variables are set:
|
||||
|
||||
``<PackageName>_VERSION``
|
||||
full provided version string
|
||||
Full provided version string
|
||||
``<PackageName>_VERSION_MAJOR``
|
||||
major version if provided, else 0
|
||||
Major version if provided, else 0
|
||||
``<PackageName>_VERSION_MINOR``
|
||||
minor version if provided, else 0
|
||||
Minor version if provided, else 0
|
||||
``<PackageName>_VERSION_PATCH``
|
||||
patch version if provided, else 0
|
||||
Patch version if provided, else 0
|
||||
``<PackageName>_VERSION_TWEAK``
|
||||
tweak version if provided, else 0
|
||||
Tweak version if provided, else 0
|
||||
``<PackageName>_VERSION_COUNT``
|
||||
number of version components, 0 to 4
|
||||
Number of version components, 0 to 4
|
||||
|
||||
and the corresponding package configuration file is loaded.
|
||||
When multiple package configuration files are available whose version files
|
||||
@@ -391,31 +453,77 @@ defines variables to provide information about the call arguments (and
|
||||
restores their original state before returning):
|
||||
|
||||
``CMAKE_FIND_PACKAGE_NAME``
|
||||
the ``<PackageName>`` which is searched for
|
||||
The ``<PackageName>`` which is searched for
|
||||
``<PackageName>_FIND_REQUIRED``
|
||||
true if ``REQUIRED`` option was given
|
||||
True if ``REQUIRED`` option was given
|
||||
``<PackageName>_FIND_QUIETLY``
|
||||
true if ``QUIET`` option was given
|
||||
True if ``QUIET`` option was given
|
||||
``<PackageName>_FIND_VERSION``
|
||||
full requested version string
|
||||
Full requested version string
|
||||
``<PackageName>_FIND_VERSION_MAJOR``
|
||||
major version if requested, else 0
|
||||
Major version if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MINOR``
|
||||
minor version if requested, else 0
|
||||
Minor version if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_PATCH``
|
||||
patch version if requested, else 0
|
||||
Patch version if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_TWEAK``
|
||||
tweak version if requested, else 0
|
||||
Tweak version if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_COUNT``
|
||||
number of version components, 0 to 4
|
||||
Number of version components, 0 to 4
|
||||
``<PackageName>_FIND_VERSION_EXACT``
|
||||
true if ``EXACT`` option was given
|
||||
True if ``EXACT`` option was given
|
||||
``<PackageName>_FIND_COMPONENTS``
|
||||
list of requested components
|
||||
List of requested components
|
||||
``<PackageName>_FIND_REQUIRED_<c>``
|
||||
true if component ``<c>`` is required,
|
||||
True if component ``<c>`` is required,
|
||||
false if component ``<c>`` is optional
|
||||
|
||||
When a version range is specified, the above version variables will hold
|
||||
values based on the lower end of the version range. This is to preserve
|
||||
compatibility with packages that have not been implemented to expect version
|
||||
ranges. In addition, the version range will be described by the following
|
||||
variables:
|
||||
|
||||
``<PackageName>_FIND_VERSION_RANGE``
|
||||
Full requested version range string
|
||||
``<PackageName>_FIND_VERSION_RANGE_MIN``
|
||||
This specifies whether the lower end point of the version range is
|
||||
included or excluded. Currently, ``INCLUDE`` is the only supported value.
|
||||
``<PackageName>_FIND_VERSION_RANGE_MAX``
|
||||
This specifies whether the upper end point of the version range is
|
||||
included or excluded. The possible values for this variable are
|
||||
``INCLUDE`` or ``EXCLUDE``.
|
||||
|
||||
``<PackageName>_FIND_VERSION_MIN``
|
||||
Full requested version string of the lower end point of the range
|
||||
``<PackageName>_FIND_VERSION_MIN_MAJOR``
|
||||
Major version of the lower end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MIN_MINOR``
|
||||
Minor version of the lower end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MIN_PATCH``
|
||||
Patch version of the lower end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MIN_TWEAK``
|
||||
Tweak version of the lower end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MIN_COUNT``
|
||||
Number of version components of the lower end point, 0 to 4
|
||||
|
||||
``<PackageName>_FIND_VERSION_MAX``
|
||||
Full requested version string of the upper end point of the range
|
||||
``<PackageName>_FIND_VERSION_MAX_MAJOR``
|
||||
Major version of the upper end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MAX_MINOR``
|
||||
Minor version of the upper end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MAX_PATCH``
|
||||
Patch version of the upper end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MAX_TWEAK``
|
||||
Tweak version of the upper end point if requested, else 0
|
||||
``<PackageName>_FIND_VERSION_MAX_COUNT``
|
||||
Number of version components of the upper end point, 0 to 4
|
||||
|
||||
Regardless of whether a single version or a version range is specified, the
|
||||
variable ``<PackageName>_FIND_VERSION_COMPLETE`` will be defined and will hold
|
||||
the full requested version string as specified.
|
||||
|
||||
In Module mode the loaded find module is responsible to honor the
|
||||
request detailed by these variables; see the find module for details.
|
||||
In Config mode ``find_package`` handles ``REQUIRED``, ``QUIET``, and
|
||||
|
4
Help/release/dev/find_package-version_range.rst
Normal file
4
Help/release/dev/find_package-version_range.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
find_package-version_range
|
||||
--------------------------
|
||||
|
||||
* The :command:`find_package` command learned to handle a version range.
|
@@ -49,6 +49,11 @@ cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::Builds(
|
||||
cmFindPackageCommand::PathLabel
|
||||
cmFindPackageCommand::PathLabel::SystemRegistry("SYSTEM_PACKAGE_REGISTRY");
|
||||
|
||||
const cm::string_view cmFindPackageCommand::VERSION_ENDPOINT_INCLUDED(
|
||||
"INCLUDE");
|
||||
const cm::string_view cmFindPackageCommand::VERSION_ENDPOINT_EXCLUDED(
|
||||
"EXCLUDE");
|
||||
|
||||
struct StrverscmpGreater
|
||||
{
|
||||
bool operator()(const std::string& lhs, const std::string& rhs) const
|
||||
@@ -90,6 +95,8 @@ void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin,
|
||||
|
||||
cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status)
|
||||
: cmFindCommon(status)
|
||||
, VersionRangeMin(VERSION_ENDPOINT_INCLUDED)
|
||||
, VersionRangeMax(VERSION_ENDPOINT_INCLUDED)
|
||||
{
|
||||
this->CMakePathName = "PACKAGE";
|
||||
this->DebugMode = false;
|
||||
@@ -242,7 +249,8 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
||||
DoingHints
|
||||
};
|
||||
Doing doing = DoingNone;
|
||||
cmsys::RegularExpression version("^[0-9.]+$");
|
||||
cmsys::RegularExpression versionRegex(
|
||||
R"V(^([0-9]+(\.[0-9]+)*)(\.\.\.(<?)([0-9]+(\.[0-9]+)*))?$)V");
|
||||
bool haveVersion = false;
|
||||
std::set<unsigned int> configArgs;
|
||||
std::set<unsigned int> moduleArgs;
|
||||
@@ -345,9 +353,9 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
||||
return false;
|
||||
}
|
||||
this->Configs.push_back(args[i]);
|
||||
} else if (!haveVersion && version.find(args[i])) {
|
||||
} else if (!haveVersion && versionRegex.find(args[i])) {
|
||||
haveVersion = true;
|
||||
this->Version = args[i];
|
||||
this->VersionComplete = args[i];
|
||||
} else {
|
||||
this->SetError(
|
||||
cmStrCat("called with invalid argument \"", args[i], "\""));
|
||||
@@ -386,23 +394,23 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
||||
}
|
||||
|
||||
// Ignore EXACT with no version.
|
||||
if (this->Version.empty() && this->VersionExact) {
|
||||
if (this->VersionComplete.empty() && this->VersionExact) {
|
||||
this->VersionExact = false;
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::AUTHOR_WARNING,
|
||||
"Ignoring EXACT since no version is requested.");
|
||||
}
|
||||
|
||||
if (this->Version.empty() || components.empty()) {
|
||||
if (this->VersionComplete.empty() || components.empty()) {
|
||||
// Check whether we are recursing inside "Find<name>.cmake" within
|
||||
// another find_package(<name>) call.
|
||||
std::string mod = cmStrCat(this->Name, "_FIND_MODULE");
|
||||
if (this->Makefile->IsOn(mod)) {
|
||||
if (this->Version.empty()) {
|
||||
if (this->VersionComplete.empty()) {
|
||||
// Get version information from the outer call if necessary.
|
||||
// Requested version string.
|
||||
std::string ver = cmStrCat(this->Name, "_FIND_VERSION");
|
||||
this->Version = this->Makefile->GetSafeDefinition(ver);
|
||||
std::string ver = cmStrCat(this->Name, "_FIND_VERSION_COMPLETE");
|
||||
this->VersionComplete = this->Makefile->GetSafeDefinition(ver);
|
||||
|
||||
// Whether an exact version is required.
|
||||
std::string exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
|
||||
@@ -415,32 +423,46 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->Version.empty()) {
|
||||
// Try to parse the version number and store the results that were
|
||||
// successfully parsed.
|
||||
unsigned int parsed_major;
|
||||
unsigned int parsed_minor;
|
||||
unsigned int parsed_patch;
|
||||
unsigned int parsed_tweak;
|
||||
this->VersionCount =
|
||||
sscanf(this->Version.c_str(), "%u.%u.%u.%u", &parsed_major,
|
||||
&parsed_minor, &parsed_patch, &parsed_tweak);
|
||||
switch (this->VersionCount) {
|
||||
case 4:
|
||||
this->VersionTweak = parsed_tweak;
|
||||
CM_FALLTHROUGH;
|
||||
case 3:
|
||||
this->VersionPatch = parsed_patch;
|
||||
CM_FALLTHROUGH;
|
||||
case 2:
|
||||
this->VersionMinor = parsed_minor;
|
||||
CM_FALLTHROUGH;
|
||||
case 1:
|
||||
this->VersionMajor = parsed_major;
|
||||
CM_FALLTHROUGH;
|
||||
default:
|
||||
break;
|
||||
// fill various parts of version specification
|
||||
if (!this->VersionComplete.empty()) {
|
||||
if (!versionRegex.find(this->VersionComplete)) {
|
||||
this->SetError("called with invalid version specification");
|
||||
return false;
|
||||
}
|
||||
|
||||
this->Version = versionRegex.match(1);
|
||||
this->VersionMax = versionRegex.match(5);
|
||||
if (versionRegex.match(4) == "<"_s) {
|
||||
this->VersionRangeMax = VERSION_ENDPOINT_EXCLUDED;
|
||||
}
|
||||
if (!this->VersionMax.empty()) {
|
||||
this->VersionRange = this->VersionComplete;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->VersionExact && !this->VersionRange.empty()) {
|
||||
this->SetError("EXACT cannot be specified with a version range.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse the version number and store the results that were
|
||||
// successfully parsed.
|
||||
auto parseVersion = [](const std::string& version, unsigned int& major,
|
||||
unsigned int& minor, unsigned int& patch,
|
||||
unsigned int& tweak) -> unsigned int {
|
||||
return sscanf(version.c_str(), "%u.%u.%u.%u", &major, &minor, &patch,
|
||||
&tweak);
|
||||
};
|
||||
|
||||
if (!this->Version.empty()) {
|
||||
this->VersionCount =
|
||||
parseVersion(this->Version, this->VersionMajor, this->VersionMinor,
|
||||
this->VersionPatch, this->VersionTweak);
|
||||
}
|
||||
if (!this->VersionMax.empty()) {
|
||||
this->VersionMaxCount = parseVersion(
|
||||
this->VersionMax, this->VersionMaxMajor, this->VersionMaxMinor,
|
||||
this->VersionMaxPatch, this->VersionMaxTweak);
|
||||
}
|
||||
|
||||
std::string disableFindPackageVar =
|
||||
@@ -647,23 +669,49 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components)
|
||||
this->AddFindDefinition(req, "1"_s);
|
||||
}
|
||||
|
||||
if (!this->VersionComplete.empty()) {
|
||||
std::string req = cmStrCat(this->Name, "_FIND_VERSION_COMPLETE");
|
||||
this->AddFindDefinition(req, this->VersionComplete);
|
||||
}
|
||||
|
||||
// Tell the module that is about to be read what version of the
|
||||
// package has been requested.
|
||||
auto addDefinition = [this](const std::string& variable,
|
||||
cm::string_view value) {
|
||||
this->AddFindDefinition(variable, value);
|
||||
};
|
||||
|
||||
if (!this->Version.empty()) {
|
||||
// Tell the module that is about to be read what version of the
|
||||
// package has been requested.
|
||||
auto addDefinition = [this](const std::string& variable,
|
||||
cm::string_view value) {
|
||||
this->AddFindDefinition(variable, value);
|
||||
};
|
||||
std::string ver = cmStrCat(this->Name, "_FIND_VERSION");
|
||||
this->SetVersionVariables(addDefinition, ver, this->Version,
|
||||
auto prefix = cmStrCat(this->Name, "_FIND_VERSION"_s);
|
||||
this->SetVersionVariables(addDefinition, prefix, this->Version,
|
||||
this->VersionCount, this->VersionMajor,
|
||||
this->VersionMinor, this->VersionPatch,
|
||||
this->VersionTweak);
|
||||
|
||||
// Tell the module whether an exact version has been requested.
|
||||
std::string exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
|
||||
auto exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
|
||||
this->AddFindDefinition(exact, this->VersionExact ? "1"_s : "0"_s);
|
||||
}
|
||||
if (!this->VersionRange.empty()) {
|
||||
auto prefix = cmStrCat(this->Name, "_FIND_VERSION_MIN"_s);
|
||||
this->SetVersionVariables(addDefinition, prefix, this->Version,
|
||||
this->VersionCount, this->VersionMajor,
|
||||
this->VersionMinor, this->VersionPatch,
|
||||
this->VersionTweak);
|
||||
|
||||
prefix = cmStrCat(this->Name, "_FIND_VERSION_MAX"_s);
|
||||
this->SetVersionVariables(addDefinition, prefix, this->VersionMax,
|
||||
this->VersionMaxCount, this->VersionMaxMajor,
|
||||
this->VersionMaxMinor, this->VersionMaxPatch,
|
||||
this->VersionMaxTweak);
|
||||
|
||||
auto id = cmStrCat(this->Name, "_FIND_VERSION_RANGE");
|
||||
this->AddFindDefinition(id, this->VersionRange);
|
||||
id = cmStrCat(this->Name, "_FIND_VERSION_RANGE_MIN");
|
||||
this->AddFindDefinition(id, this->VersionRangeMin);
|
||||
id = cmStrCat(this->Name, "_FIND_VERSION_RANGE_MAX");
|
||||
this->AddFindDefinition(id, this->VersionRangeMax);
|
||||
}
|
||||
}
|
||||
|
||||
void cmFindPackageCommand::AddFindDefinition(const std::string& var,
|
||||
@@ -873,7 +921,9 @@ bool cmFindPackageCommand::HandlePackageMode(
|
||||
e << "Could not find a configuration file for package \"" << this->Name
|
||||
<< "\" that "
|
||||
<< (this->VersionExact ? "exactly matches" : "is compatible with")
|
||||
<< " requested version \"" << this->Version << "\".\n"
|
||||
<< " requested version "
|
||||
<< (this->VersionRange.empty() ? "" : "range ") << "\""
|
||||
<< this->VersionComplete << "\".\n"
|
||||
<< "The following configuration files were considered but not "
|
||||
"accepted:\n";
|
||||
|
||||
@@ -883,9 +933,9 @@ bool cmFindPackageCommand::HandlePackageMode(
|
||||
}
|
||||
} else {
|
||||
std::string requestedVersionString;
|
||||
if (!this->Version.empty()) {
|
||||
if (!this->VersionComplete.empty()) {
|
||||
requestedVersionString =
|
||||
cmStrCat(" (requested version ", this->Version, ')');
|
||||
cmStrCat(" (requested version ", this->VersionComplete, ')');
|
||||
}
|
||||
|
||||
if (this->UseConfigFiles) {
|
||||
@@ -1174,7 +1224,9 @@ void cmFindPackageCommand::AppendSuccessInformation()
|
||||
std::string versionInfoPropName =
|
||||
cmStrCat("_CMAKE_", this->Name, "_REQUIRED_VERSION");
|
||||
std::string versionInfo;
|
||||
if (!this->Version.empty()) {
|
||||
if (!this->VersionRange.empty()) {
|
||||
versionInfo = this->VersionRange;
|
||||
} else if (!this->Version.empty()) {
|
||||
versionInfo =
|
||||
cmStrCat(this->VersionExact ? "==" : ">=", ' ', this->Version);
|
||||
}
|
||||
@@ -1717,6 +1769,8 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
|
||||
|
||||
// Set the input variables.
|
||||
this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name);
|
||||
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COMPLETE",
|
||||
this->VersionComplete);
|
||||
|
||||
auto addDefinition = [this](const std::string& variable,
|
||||
cm::string_view value) {
|
||||
@@ -1726,6 +1780,23 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
|
||||
this->Version, this->VersionCount,
|
||||
this->VersionMajor, this->VersionMinor,
|
||||
this->VersionPatch, this->VersionTweak);
|
||||
if (!this->VersionRange.empty()) {
|
||||
this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MIN",
|
||||
this->Version, this->VersionCount,
|
||||
this->VersionMajor, this->VersionMinor,
|
||||
this->VersionPatch, this->VersionTweak);
|
||||
this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MAX",
|
||||
this->VersionMax, this->VersionMaxCount,
|
||||
this->VersionMaxMajor, this->VersionMaxMinor,
|
||||
this->VersionMaxPatch, this->VersionMaxTweak);
|
||||
|
||||
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE",
|
||||
this->VersionComplete);
|
||||
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MIN",
|
||||
this->VersionRangeMin);
|
||||
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MAX",
|
||||
this->VersionRangeMax);
|
||||
}
|
||||
|
||||
// Load the version check file. Pass NoPolicyScope because we do
|
||||
// our own policy push/pop independent of CMP0011.
|
||||
|
@@ -158,14 +158,27 @@ private:
|
||||
|
||||
std::map<std::string, cmPolicies::PolicyID> DeprecatedFindModules;
|
||||
|
||||
static const cm::string_view VERSION_ENDPOINT_INCLUDED;
|
||||
static const cm::string_view VERSION_ENDPOINT_EXCLUDED;
|
||||
|
||||
std::string Name;
|
||||
std::string Variable;
|
||||
std::string VersionComplete;
|
||||
std::string VersionRange;
|
||||
cm::string_view VersionRangeMin;
|
||||
cm::string_view VersionRangeMax;
|
||||
std::string Version;
|
||||
unsigned int VersionMajor = 0;
|
||||
unsigned int VersionMinor = 0;
|
||||
unsigned int VersionPatch = 0;
|
||||
unsigned int VersionTweak = 0;
|
||||
unsigned int VersionCount = 0;
|
||||
std::string VersionMax;
|
||||
unsigned int VersionMaxMajor = 0;
|
||||
unsigned int VersionMaxMinor = 0;
|
||||
unsigned int VersionMaxPatch = 0;
|
||||
unsigned int VersionMaxTweak = 0;
|
||||
unsigned int VersionMaxCount = 0;
|
||||
bool VersionExact = false;
|
||||
std::string FileFound;
|
||||
std::string VersionFound;
|
||||
|
82
Tests/RunCMake/find_package/FindVersionRange.cmake
Normal file
82
Tests/RunCMake/find_package/FindVersionRange.cmake
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
if (NOT VersionRange_FIND_VERSION_COMPLETE STREQUAL VersionRange_SPECIFIED_VERSION_COMPLETE)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_COMPLETE: ${VersionRange_FIND_VERSION_COMPLETE}")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_FIND_VERSION VERSION_EQUAL "1.2.3.4")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION: ${VersionRange_FIND_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MAJOR VERSION_EQUAL "1")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MAJOR: ${VersionRange_FIND_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MINOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MINOR: ${VersionRange_FIND_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_PATCH VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_PATCH: ${VersionRange_FIND_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_TWEAK VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_TWEAK: ${VersionRange_FIND_VERSION_TWEAK}")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_FIND_VERSION_RANGE STREQUAL VersionRange_SPECIFIED_VERSION_RANGE)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_RANGE: ${VersionRange_FIND_VERSION_RANGE}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_RANGE_MIN: ${VersionRange_FIND_VERSION_RANGE_MIN}")
|
||||
endif()
|
||||
if (VersionRange_FIND_VERSION_RANGE MATCHES "<[0-9.]+$")
|
||||
if (NOT VersionRange_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_RANGE_MAX: ${VersionRange_FIND_VERSION_RANGE_MAX}")
|
||||
endif()
|
||||
else()
|
||||
if (NOT VersionRange_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_RANGE_MAX: ${VersionRange_FIND_VERSION_RANGE_MAX}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_FIND_VERSION_MIN VERSION_EQUAL "1.2.3.4")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MIN: ${VersionRange_FIND_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MIN_MAJOR VERSION_EQUAL "1")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MIN_MAJOR: ${VersionRange_FIND_VERSION_MIN_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MIN_MINOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MIN_MINOR: ${VersionRange_FIND_VERSION_MIN_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MIN_PATCH VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MIN_PATCH: ${VersionRange_FIND_VERSION_MIN_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MIN_TWEAK VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MIN_TWEAK: ${VersionRange_FIND_VERSION_MIN_TWEAK}")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_FIND_VERSION_MAX VERSION_EQUAL VersionRange_SPECIFIED_VERSION_MAX)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MAX: ${VersionRange_FIND_VERSION_MAX}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MAX_MAJOR VERSION_EQUAL VersionRange_SPECIFIED_VERSION_MAX_MAJOR)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MAX_MAJOR: ${VersionRange_FIND_VERSION_MAX_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MAX_MINOR VERSION_EQUAL VersionRange_SPECIFIED_VERSION_MAX_MINOR)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_FIND_VERSION_MAX_MINOR: ${VersionRange_FIND_VERSION_MAX_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MAX_PATCH VERSION_EQUAL VersionRange_SPECIFIED_VERSION_MAX_PATCH)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_VERSION_FIND_MAX_PATCH: ${VersionRange_FIND_VERSION_MAX_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_FIND_VERSION_MAX_TWEAK VERSION_EQUAL VersionRange_SPECIFIED_VERSION_MAX_TWEAK)
|
||||
message (SEND_ERROR "Wrong value for VersionRange_VERSION_FIND_MAX_TWEAK: ${VersionRange_FIND_VERSION_MAX_TWEAK}")
|
||||
endif()
|
||||
|
||||
if ((VersionRange_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE"
|
||||
AND "2.3.4.5" VERSION_LESS_EQUAL VersionRange_FIND_VERSION_MAX)
|
||||
OR (VersionRange_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"
|
||||
AND "2.3.4.5" VERSION_LESS VersionRange_FIND_VERSION_MAX))
|
||||
set (VersionRange_FOUND TRUE)
|
||||
set (VersionRange_VERSION 2.3.4.5)
|
||||
set (VersionRange_VERSION_MAJOR 2)
|
||||
set (VersionRange_VERSION_MINOR 3)
|
||||
set (VersionRange_VERSION_PATCH 4)
|
||||
set (VersionRange_VERSION_TWEAK 5)
|
||||
else()
|
||||
set (VersionRange_FOUND FALSE)
|
||||
endif()
|
@@ -29,6 +29,15 @@ run_cmake(WrongVersionConfig)
|
||||
run_cmake(CMP0084-OLD)
|
||||
run_cmake(CMP0084-WARN)
|
||||
run_cmake(CMP0084-NEW)
|
||||
run_cmake(WrongVersionRange)
|
||||
run_cmake(VersionRangeWithEXACT)
|
||||
run_cmake(VersionRange)
|
||||
run_cmake(VersionRange2)
|
||||
run_cmake(VersionRange3)
|
||||
run_cmake(VersionRangeConfig)
|
||||
run_cmake(VersionRangeConfig2)
|
||||
run_cmake(VersionRangeConfigStd)
|
||||
run_cmake(VersionRangeConfigStd2)
|
||||
if(UNIX)
|
||||
run_cmake(SetFoundResolved)
|
||||
endif()
|
||||
|
32
Tests/RunCMake/find_package/VersionRange.cmake
Normal file
32
Tests/RunCMake/find_package/VersionRange.cmake
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
set (VersionRange_SPECIFIED_VERSION_COMPLETE 1.2.3.4...5.6.7.8)
|
||||
set (VersionRange_SPECIFIED_VERSION_RANGE 1.2.3.4...5.6.7.8)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX 5.6.7.8)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_MAJOR 5)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_MINOR 6)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_PATCH 7)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_TWEAK 8)
|
||||
|
||||
find_package (VersionRange ${VersionRange_SPECIFIED_VERSION_RANGE})
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
32
Tests/RunCMake/find_package/VersionRange2.cmake
Normal file
32
Tests/RunCMake/find_package/VersionRange2.cmake
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
set (VersionRange_SPECIFIED_VERSION_COMPLETE 1.2.3.4...<5.6.7.8)
|
||||
set (VersionRange_SPECIFIED_VERSION_RANGE 1.2.3.4...<5.6.7.8)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX 5.6.7.8)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_MAJOR 5)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_MINOR 6)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_PATCH 7)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_TWEAK 8)
|
||||
|
||||
find_package (VersionRange ${VersionRange_SPECIFIED_VERSION_RANGE})
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
44
Tests/RunCMake/find_package/VersionRange3.cmake
Normal file
44
Tests/RunCMake/find_package/VersionRange3.cmake
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
# show the effect of the exclusion or inclusion of the upper endpoint
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
set (VersionRange_SPECIFIED_VERSION_COMPLETE 1.2.3.4...<2.3.4.5)
|
||||
set (VersionRange_SPECIFIED_VERSION_RANGE 1.2.3.4...<2.3.4.5)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX 2.3.4.5)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_MAJOR 2)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_MINOR 3)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_PATCH 4)
|
||||
set (VersionRange_SPECIFIED_VERSION_MAX_TWEAK 5)
|
||||
|
||||
find_package (VersionRange ${VersionRange_SPECIFIED_VERSION_RANGE})
|
||||
|
||||
if (VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange found unexpectedly.")
|
||||
endif()
|
||||
|
||||
|
||||
set (VersionRange_SPECIFIED_VERSION_COMPLETE 1.2.3.4...2.3.4.5)
|
||||
set (VersionRange_SPECIFIED_VERSION_RANGE 1.2.3.4...2.3.4.5)
|
||||
|
||||
find_package (VersionRange ${VersionRange_SPECIFIED_VERSION_RANGE})
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
@@ -0,0 +1,74 @@
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION_COMPLETE STREQUAL "1.2.3.4...5.6.7.8"
|
||||
AND NOT PACKAGE_FIND_VERSION_COMPLETE STREQUAL "1.2.3.4...<5.6.7.8")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_COMPLETE: ${PACKAGE_FIND_VERSION_COMPLETE}")
|
||||
endif()
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION VERSION_EQUAL "1.2.3.4")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION: ${PACKAGE_FIND_VERSION}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MAJOR VERSION_EQUAL "1")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAJOR: ${PACKAGE_FIND_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MINOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MINOR: ${PACKAGE_FIND_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_PATCH VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_PATCH: ${PACKAGE_FIND_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_TWEAK VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_TWEAK: ${PACKAGE_FIND_VERSION_TWEAK}")
|
||||
endif()
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION_RANGE STREQUAL "1.2.3.4...5.6.7.8"
|
||||
AND NOT PACKAGE_FIND_VERSION_RANGE STREQUAL "1.2.3.4...<5.6.7.8")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_RANGE: ${PACKAGE_FIND_VERSION_RANGE}")
|
||||
endif()
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_RANGE_MIN: ${PACKAGE_FIND_VERSION_RANGE_MIN}")
|
||||
endif()
|
||||
if (PACKAGE_FIND_VERSION_RANGE MATCHES "<[0-9.]+$")
|
||||
if (NOT PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_RANGE_MAX: ${PACKAGE_FIND_VERSION_RANGE_MAX}")
|
||||
endif()
|
||||
else()
|
||||
if (NOT PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_RANGE_MAX: ${PACKAGE_FIND_VERSION_RANGE_MAX}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION_MIN VERSION_EQUAL "1.2.3.4")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MIN: ${PACKAGE_FIND_VERSION_MIN}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR VERSION_EQUAL "1")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MIN_MAJOR: ${PACKAGE_FIND_VERSION_MIN_MAJOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MIN_MINOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MIN_MINOR: ${PACKAGE_FIND_VERSION_MIN_MINOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MIN_PATCH VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MIN_PATCH: ${PACKAGE_FIND_VERSION_MIN_PATCH}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MIN_TWEAK VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MIN_TWEAK: ${PACKAGE_FIND_VERSION_MIN_TWEAK}")
|
||||
endif()
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION_MAX VERSION_EQUAL "5.6.7.8")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAX: ${PACKAGE_FIND_VERSION_MAX}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MAX_MAJOR VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAX_MAJOR: ${PACKAGE_FIND_VERSION_MAX_MAJOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MAX_MINOR VERSION_EQUAL "6")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAX_MINOR: ${PACKAGE_FIND_VERSION_MAX_MINOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MAX_PATCH VERSION_EQUAL "7")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAXPATCH: ${PACKAGE_FIND_VERSION_MAX_PATCH}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MAX_TWEAK VERSION_EQUAL "8")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAX_TWEAK: ${PACKAGE_FIND_VERSION_MAX_TWEAK}")
|
||||
endif()
|
||||
|
||||
set (PACKAGE_VERSION 2.3.4.5)
|
||||
set (PACKAGE_VERSION_COMPATIBLE TRUE)
|
23
Tests/RunCMake/find_package/VersionRangeConfig.cmake
Normal file
23
Tests/RunCMake/find_package/VersionRangeConfig.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(VersionRange 1.2.3.4...5.6.7.8 CONFIG NAMES VersionRangeCfg)
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found in CONFIG mode.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
23
Tests/RunCMake/find_package/VersionRangeConfig2.cmake
Normal file
23
Tests/RunCMake/find_package/VersionRangeConfig2.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(VersionRange 1.2.3.4...<5.6.7.8 CONFIG NAMES VersionRangeCfg)
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found in CONFIG mode.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
23
Tests/RunCMake/find_package/VersionRangeConfigStd.cmake
Normal file
23
Tests/RunCMake/find_package/VersionRangeConfigStd.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(VersionRange 1.2.3.4 CONFIG NAMES VersionRangeStd)
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found in CONFIG mode.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
23
Tests/RunCMake/find_package/VersionRangeConfigStd2.cmake
Normal file
23
Tests/RunCMake/find_package/VersionRangeConfigStd2.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(VersionRange 1.2.3.4...5.6.7.8 CONFIG NAMES VersionRangeStd)
|
||||
|
||||
if (NOT VersionRange_FOUND)
|
||||
message (FATAL_ERROR "Package VersionRange not found in CONFIG mode.")
|
||||
endif()
|
||||
|
||||
if (NOT VersionRange_VERSION VERSION_EQUAL "2.3.4.5")
|
||||
message (SEND_ERROR "Wrong version : ${VersionRange_VERSION}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MAJOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong major version : ${VersionRange_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_MINOR VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong minor version : ${VersionRange_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_PATCH VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong patch version : ${VersionRange_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT VersionRange_VERSION_TWEAK VERSION_EQUAL "5")
|
||||
message (SEND_ERROR "Wrong tweak version : ${VersionRange_VERSION_TWEAK}")
|
||||
endif()
|
@@ -0,0 +1,24 @@
|
||||
|
||||
if (NOT PACKAGE_FIND_VERSION VERSION_EQUAL "1.2.3.4")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION: ${PACKAGE_FIND_VERSION}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MAJOR VERSION_EQUAL "1")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MAJOR: ${PACKAGE_FIND_VERSION_MAJOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_MINOR VERSION_EQUAL "2")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_MINOR: ${PACKAGE_FIND_VERSION_MINOR}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_PATCH VERSION_EQUAL "3")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_PATCH: ${PACKAGE_FIND_VERSION_PATCH}")
|
||||
endif()
|
||||
if (NOT PACKAGE_FIND_VERSION_TWEAK VERSION_EQUAL "4")
|
||||
message (SEND_ERROR "Wrong value for PACKAGE_FIND_VERSION_TWEAK: ${PACKAGE_FIND_VERSION_TWEAK}")
|
||||
endif()
|
||||
|
||||
set (PACKAGE_VERSION 2.3.4.5)
|
||||
|
||||
if (PACKAGE_FIND_VERSION VERSION_LESS_EQUAL PACKAGE_VERSION)
|
||||
set (PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
else()
|
||||
set (PACKAGE_VERSION_UNSUITABLE TRUE)
|
||||
endif()
|
@@ -0,0 +1 @@
|
||||
1
|
@@ -0,0 +1,2 @@
|
||||
CMake Error at VersionRangeWithEXACT.cmake:[0-9]+ \(find_package\):
|
||||
find_package EXACT cannot be specified with a version range.
|
1
Tests/RunCMake/find_package/VersionRangeWithEXACT.cmake
Normal file
1
Tests/RunCMake/find_package/VersionRangeWithEXACT.cmake
Normal file
@@ -0,0 +1 @@
|
||||
find_package(VersionRange 1.2...3.4 EXACT)
|
1
Tests/RunCMake/find_package/WrongVersionRange-result.txt
Normal file
1
Tests/RunCMake/find_package/WrongVersionRange-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
28
Tests/RunCMake/find_package/WrongVersionRange-stderr.txt
Normal file
28
Tests/RunCMake/find_package/WrongVersionRange-stderr.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
CMake Error at WrongVersionRange.cmake:[0-9]+ \(find_package\):
|
||||
find_package called with invalid argument "1\.2\.\.\."
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
||||
|
||||
|
||||
CMake Error at WrongVersionRange.cmake:[0-9]+ \(find_package\):
|
||||
find_package called with invalid argument "\.\.\.1\.2"
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
||||
|
||||
|
||||
CMake Error at WrongVersionRange.cmake:[0-9]+ \(find_package\):
|
||||
find_package called with invalid argument "1\.2\.\.\.\.2\.3"
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
||||
|
||||
|
||||
CMake Error at WrongVersionRange.cmake:[0-9]+ \(find_package\):
|
||||
find_package called with invalid argument "1\.2\.\.\.>2\.3"
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
||||
|
||||
|
||||
CMake Error at WrongVersionRange.cmake:[0-9]+ \(find_package\):
|
||||
find_package called with invalid argument "1\.2>\.\.\.2\.3"
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
9
Tests/RunCMake/find_package/WrongVersionRange.cmake
Normal file
9
Tests/RunCMake/find_package/WrongVersionRange.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
find_package(VersionRange 1.2...)
|
||||
|
||||
find_package(VersionRange ...1.2)
|
||||
|
||||
find_package(VersionRange 1.2....2.3)
|
||||
|
||||
find_package(VersionRange 1.2...>2.3)
|
||||
|
||||
find_package(VersionRange 1.2>...2.3)
|
Reference in New Issue
Block a user