Merge topic 'fix-cps-cmake-deps'
c3d279841b
find_package: CPS component requirements != CMake components
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10427
This commit is contained in:
commit
d84881dce6
@ -1545,6 +1545,7 @@ bool cmFindPackageCommand::HandlePackageMode(
|
||||
bool result = true;
|
||||
bool found = false;
|
||||
bool configFileSetFOUNDFalse = false;
|
||||
std::vector<std::string> missingTargets;
|
||||
|
||||
if (fileFound) {
|
||||
if (this->Makefile->IsDefinitionSet(foundVar) &&
|
||||
@ -1579,6 +1580,17 @@ bool cmFindPackageCommand::HandlePackageMode(
|
||||
notFoundMessage =
|
||||
this->Makefile->GetSafeDefinition(notFoundMessageVar);
|
||||
}
|
||||
|
||||
// Check whether the required targets are defined.
|
||||
if (found && !this->RequiredTargets.empty()) {
|
||||
for (std::string const& t : this->RequiredTargets) {
|
||||
std::string qualifiedTarget = cmStrCat(this->Name, "::"_s, t);
|
||||
if (!this->Makefile->FindImportedTarget(qualifiedTarget)) {
|
||||
missingTargets.emplace_back(std::move(qualifiedTarget));
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// The configuration file is invalid.
|
||||
result = false;
|
||||
@ -1615,10 +1627,18 @@ bool cmFindPackageCommand::HandlePackageMode(
|
||||
if (!notFoundMessage.empty()) {
|
||||
e << " Reason given by package: \n" << notFoundMessage << "\n";
|
||||
}
|
||||
}
|
||||
// If there are files in ConsideredConfigs, it means that FooConfig.cmake
|
||||
// have been found, but they didn't have appropriate versions.
|
||||
else if (!this->ConsideredConfigs.empty()) {
|
||||
} else if (!missingTargets.empty()) {
|
||||
e << "Found package configuration file:\n"
|
||||
" "
|
||||
<< this->FileFound
|
||||
<< "\n"
|
||||
"but the following required targets were not found:\n"
|
||||
" "
|
||||
<< cmJoin(cmMakeRange(missingTargets), ", "_s);
|
||||
} else if (!this->ConsideredConfigs.empty()) {
|
||||
// If there are files in ConsideredConfigs, it means that
|
||||
// FooConfig.cmake have been found, but they didn't have appropriate
|
||||
// versions.
|
||||
auto duplicate_end = cmRemoveDuplicates(this->ConsideredConfigs);
|
||||
e << "Could not find a configuration file for package \"" << this->Name
|
||||
<< "\" that "
|
||||
@ -1933,7 +1953,7 @@ bool cmFindPackageCommand::ReadPackage()
|
||||
return false;
|
||||
}
|
||||
|
||||
auto const hasComponentsRequested =
|
||||
bool const hasComponentsRequested =
|
||||
!this->RequiredComponents.empty() || !this->OptionalComponents.empty();
|
||||
|
||||
cmMakefile::CallRAII scope{ this->Makefile, this->FileFound, this->Status };
|
||||
@ -2024,8 +2044,9 @@ bool cmFindPackageCommand::FindPackageDependencies(
|
||||
fp.VersionPatch, fp.VersionTweak);
|
||||
|
||||
fp.Components = cmJoin(cmMakeRange(dep.Components), ";"_s);
|
||||
fp.RequiredComponents =
|
||||
fp.OptionalComponents =
|
||||
std::set<std::string>{ dep.Components.begin(), dep.Components.end() };
|
||||
fp.RequiredTargets = fp.OptionalComponents;
|
||||
|
||||
// TODO set hints
|
||||
|
||||
@ -2823,10 +2844,14 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
|
||||
}
|
||||
|
||||
// Verify that all required components are available.
|
||||
std::set<std::string> requiredComponents = this->RequiredComponents;
|
||||
requiredComponents.insert(this->RequiredTargets.begin(),
|
||||
this->RequiredTargets.end());
|
||||
|
||||
std::vector<std::string> missingComponents;
|
||||
std::set_difference(this->RequiredComponents.begin(),
|
||||
this->RequiredComponents.end(),
|
||||
allComponents.begin(), allComponents.end(),
|
||||
std::set_difference(requiredComponents.begin(),
|
||||
requiredComponents.end(), allComponents.begin(),
|
||||
allComponents.end(),
|
||||
std::back_inserter(missingComponents));
|
||||
if (!missingComponents.empty()) {
|
||||
result = false;
|
||||
@ -2863,6 +2888,7 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
|
||||
}
|
||||
this->CpsReader = std::move(reader);
|
||||
this->CpsAppendices = std::move(appendices);
|
||||
this->RequiredComponents = std::move(requiredComponents);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -264,6 +264,7 @@ private:
|
||||
std::string Components;
|
||||
std::set<std::string> RequiredComponents;
|
||||
std::set<std::string> OptionalComponents;
|
||||
std::set<std::string> RequiredTargets;
|
||||
std::string DebugBuffer;
|
||||
|
||||
struct ConfigName
|
||||
|
@ -1728,6 +1728,15 @@ std::string const& cmMakefile::GetCurrentBinaryDirectory() const
|
||||
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
|
||||
}
|
||||
|
||||
cmTarget* cmMakefile::FindImportedTarget(std::string const& name) const
|
||||
{
|
||||
auto const i = this->ImportedTargets.find(name);
|
||||
if (i != this->ImportedTargets.end()) {
|
||||
return i->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<cmTarget*> cmMakefile::GetImportedTargets() const
|
||||
{
|
||||
std::vector<cmTarget*> tgts;
|
||||
|
@ -477,6 +477,8 @@ public:
|
||||
}
|
||||
std::vector<cmTarget*> GetImportedTargets() const;
|
||||
|
||||
cmTarget* FindImportedTarget(std::string const& name) const;
|
||||
|
||||
cmTarget* FindLocalNonAliasTarget(std::string const& name) const;
|
||||
|
||||
/** Find a target to use in place of the given name. The target
|
||||
|
@ -3,8 +3,12 @@
|
||||
"name": "Bar",
|
||||
"cps_path": "@prefix@/cps",
|
||||
"requires": {
|
||||
"Dep1": null,
|
||||
"Dep2": null
|
||||
"Dep1": {
|
||||
"components": [ "Target" ]
|
||||
},
|
||||
"Dep2": {
|
||||
"components": [ "Target" ]
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"Target1": {
|
||||
|
@ -0,0 +1,11 @@
|
||||
CMake Error in cps/[Tt]ransitive[Mm]issing[Cc][Mm]ake\.cps:
|
||||
Found package configuration file:
|
||||
(
|
||||
[^
|
||||
]*/Tests/RunCMake/find_package-CPS/cmake/cmaketestpackage-config.cmake)+
|
||||
|
||||
but the following required targets were not found:[
|
||||
]+CMakeTestPackage::DoesNotExist
|
||||
Call Stack \(most recent call first\):
|
||||
MissingTransitiveComponentCMake\.cmake:[0-9]+ \(find_package\)
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
include(Setup.cmake)
|
||||
|
||||
###############################################################################
|
||||
# Test depending on components of another package which are unavailable.
|
||||
find_package(TransitiveMissingCMake REQUIRED)
|
@ -0,0 +1 @@
|
||||
1
|
@ -1,4 +1,4 @@
|
||||
CMake Error in cps/[Tt]ransitive[Mm]issing\.cps:
|
||||
CMake Error in cps/[Tt]ransitive[Mm]issing[Cc][Pp][Ss]\.cps:
|
||||
Could not find a configuration file for package "ComponentTest" that is
|
||||
compatible with requested version ""\.
|
||||
|
||||
@ -8,10 +8,11 @@ CMake Error in cps/[Tt]ransitive[Mm]issing\.cps:
|
||||
]*/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\)
|
||||
MissingTransitiveComponentCPS\.cmake:[0-9]+ \(find_package\)
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
||||
+
|
||||
CMake Error at MissingTransitiveComponent\.cmake:[0-9]+ \(find_package\):
|
||||
find_package could not find ComponentTest, required by TransitiveMissing\.
|
||||
CMake Error at MissingTransitiveComponentCPS\.cmake:[0-9]+ \(find_package\):
|
||||
find_package could not find ComponentTest, required by
|
||||
TransitiveMissingCPS\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
@ -4,4 +4,4 @@ include(Setup.cmake)
|
||||
|
||||
###############################################################################
|
||||
# Test depending on components of another package which are unavailable.
|
||||
find_package(TransitiveMissing REQUIRED)
|
||||
find_package(TransitiveMissingCPS REQUIRED)
|
@ -27,5 +27,6 @@ run_cmake(VersionLimit4)
|
||||
run_cmake(MissingTransitiveDependency)
|
||||
run_cmake(MissingComponent)
|
||||
run_cmake(MissingComponentDependency)
|
||||
run_cmake(MissingTransitiveComponent)
|
||||
run_cmake(MissingTransitiveComponentCPS)
|
||||
run_cmake(MissingTransitiveComponentCMake)
|
||||
run_cmake(MissingTransitiveComponentDependency)
|
||||
|
@ -0,0 +1 @@
|
||||
# Test config file.
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "TransitiveMissingCMake",
|
||||
"cps_path": "@prefix@/cps",
|
||||
"requires": {
|
||||
"CMakeTestPackage": {
|
||||
"components": [ "DoesNotExist" ]
|
||||
}
|
||||
},
|
||||
"components": {}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "TransitiveMissing",
|
||||
"name": "TransitiveMissingCPS",
|
||||
"cps_path": "@prefix@/cps",
|
||||
"requires": {
|
||||
"ComponentTest": {
|
Loading…
Reference in New Issue
Block a user