1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 03:48:02 +08:00

find_package: Fix reporting of rejected CPS files' version

The logic to extract the version of a CPS file into the location used to
record files that were considered but rejected was happening too late,
resulting in rejected files unnecessarily reporting their version as
"unknown". Fix this by filling the variable sooner.
This commit is contained in:
Matthew Woehlke
2025-01-31 14:00:32 -05:00
parent 8137cf2822
commit 35a7ed125b
4 changed files with 9 additions and 5 deletions

View File

@@ -2718,7 +2718,10 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
cmPackageInfoReader::Read(config_file);
if (reader && reader->GetName() == this->Name) {
cm::optional<std::string> cpsVersion = reader->GetVersion();
if (cpsVersion) {
bool const hasVersion = cpsVersion.has_value();
if (hasVersion) {
version = std::move(*cpsVersion);
// TODO: Implement version check for CPS
result = true;
} else {
@@ -2752,8 +2755,8 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
result = false;
}
if (result && cpsVersion) {
this->VersionFound = (version = std::move(*cpsVersion));
if (result && hasVersion) {
this->VersionFound = version;
std::vector<unsigned> const& versionParts = reader->ParseVersion();
this->VersionFoundCount = static_cast<unsigned>(versionParts.size());

View File

@@ -5,7 +5,7 @@ CMake Error at MissingComponent.cmake:[0-9]+ \(find_package\):
The following configuration files were considered but not accepted:
(
[^
]*/Tests/RunCMake/find_package-CPS/cps/[Cc]omponent[Tt]est\.cps, version: unknown)+
]*/Tests/RunCMake/find_package-CPS/cps/[Cc]omponent[Tt]est\.cps, version: 1\.0)+
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)

View File

@@ -5,7 +5,7 @@ CMake Error in cps/[Tt]ransitive[Mm]issing\.cps:
The following configuration files were considered but not accepted:
(
[^
]*/Tests/RunCMake/find_package-CPS/cps/[Cc]omponent[Tt]est\.cps, version: unknown)+
]*/Tests/RunCMake/find_package-CPS/cps/[Cc]omponent[Tt]est\.cps, version: 1\.0)+
Call Stack \(most recent call first\):
MissingTransitiveComponent\.cmake:[0-9]+ \(find_package\)

View File

@@ -1,6 +1,7 @@
{
"cps_version": "0.13",
"name": "ComponentTest",
"version": "1.0",
"cps_path": "@prefix@/cps",
"components": {}
}