mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 03:48:02 +08:00
find_package: Add minimal support for CPS multiple inclusion
Do not try to load a CPS file if we've already loaded the same file. This only works if the current `find_package` call selects the same file as the previous most recent call, and if the user has not meddled with the `<name>_CONFIG` variable. Issue: #26731
This commit is contained in:

committed by
Brad King

parent
7167236ba3
commit
b498611902
@@ -1522,6 +1522,7 @@ bool cmFindPackageCommand::HandlePackageMode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string const fileVar = cmStrCat(this->Name, "_CONFIG");
|
||||||
std::string const foundVar = cmStrCat(this->Name, "_FOUND");
|
std::string const foundVar = cmStrCat(this->Name, "_FOUND");
|
||||||
std::string const notFoundMessageVar =
|
std::string const notFoundMessageVar =
|
||||||
cmStrCat(this->Name, "_NOT_FOUND_MESSAGE");
|
cmStrCat(this->Name, "_NOT_FOUND_MESSAGE");
|
||||||
@@ -1552,7 +1553,15 @@ bool cmFindPackageCommand::HandlePackageMode(
|
|||||||
if (this->CpsReader) {
|
if (this->CpsReader) {
|
||||||
// The package has been found.
|
// The package has been found.
|
||||||
found = true;
|
found = true;
|
||||||
|
|
||||||
|
// Don't read a CPS file if we've already read it.
|
||||||
|
cmValue const& previousFileFound =
|
||||||
|
this->Makefile->GetDefinition(fileVar);
|
||||||
|
if (previousFileFound.Compare(this->FileFound) == 0) {
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
result = this->ReadPackage();
|
result = this->ReadPackage();
|
||||||
|
}
|
||||||
} else if (this->ReadListFile(this->FileFound, DoPolicyScope)) {
|
} else if (this->ReadListFile(this->FileFound, DoPolicyScope)) {
|
||||||
// The package has been found.
|
// The package has been found.
|
||||||
found = true;
|
found = true;
|
||||||
@@ -1725,7 +1734,6 @@ bool cmFindPackageCommand::HandlePackageMode(
|
|||||||
this->Makefile->AddDefinition(foundVar, found ? "1" : "0");
|
this->Makefile->AddDefinition(foundVar, found ? "1" : "0");
|
||||||
|
|
||||||
// Set a variable naming the configuration file that was found.
|
// Set a variable naming the configuration file that was found.
|
||||||
std::string const fileVar = cmStrCat(this->Name, "_CONFIG");
|
|
||||||
if (found) {
|
if (found) {
|
||||||
this->Makefile->AddDefinition(fileVar, this->FileFound);
|
this->Makefile->AddDefinition(fileVar, this->FileFound);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -54,6 +54,12 @@ endfunction()
|
|||||||
find_package(Sample CONFIG)
|
find_package(Sample CONFIG)
|
||||||
test_version(Sample "2.10.11" 3 2 10 11 0)
|
test_version(Sample "2.10.11" 3 2 10 11 0)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Test finding a package more than once.
|
||||||
|
|
||||||
|
find_package(Repeat REQUIRED)
|
||||||
|
find_package(Repeat REQUIRED)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Test some more complicated version parsing.
|
# Test some more complicated version parsing.
|
||||||
|
|
||||||
|
10
Tests/FindPackageCpsTest/cps/Repeat.cps
Normal file
10
Tests/FindPackageCpsTest/cps/Repeat.cps
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"cps_version": "0.13",
|
||||||
|
"name": "Repeat",
|
||||||
|
"cps_path": "@prefix@/cps",
|
||||||
|
"components": {
|
||||||
|
"Repeat": {
|
||||||
|
"type": "interface"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user