mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
install: Allow installing targets created in another directory
Previously, `install(TARGETS)` would only accept targets created in the same directory scope. Relax this restriction by searching the global scope when determining whether or not a target exists. Fixes: #14444
This commit is contained in:
@@ -362,7 +362,12 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||
return false;
|
||||
}
|
||||
// Lookup this target in the current directory.
|
||||
if (cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt)) {
|
||||
cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt);
|
||||
if (!target) {
|
||||
// If no local target has been found, find it in the global scope.
|
||||
target = this->Makefile->GetGlobalGenerator()->FindTarget(tgt, true);
|
||||
}
|
||||
if (target) {
|
||||
// Found the target. Check its type.
|
||||
if (target->GetType() != cmStateEnums::EXECUTABLE &&
|
||||
target->GetType() != cmStateEnums::STATIC_LIBRARY &&
|
||||
@@ -381,8 +386,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||
} else {
|
||||
// Did not find the target.
|
||||
std::ostringstream e;
|
||||
e << "TARGETS given target \"" << tgt
|
||||
<< "\" which does not exist in this directory.";
|
||||
e << "TARGETS given target \"" << tgt << "\" which does not exist.";
|
||||
this->SetError(e.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -440,7 +440,13 @@ std::string cmInstallTargetGenerator::GetInstallFilename(
|
||||
|
||||
void cmInstallTargetGenerator::Compute(cmLocalGenerator* lg)
|
||||
{
|
||||
// Lookup this target in the current directory.
|
||||
this->Target = lg->FindLocalNonAliasGeneratorTarget(this->TargetName);
|
||||
if (!this->Target) {
|
||||
// If no local target has been found, find it in the global scope.
|
||||
this->Target =
|
||||
lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
|
||||
}
|
||||
}
|
||||
|
||||
void cmInstallTargetGenerator::AddTweak(std::ostream& os, Indent indent,
|
||||
|
||||
Reference in New Issue
Block a user