Commit e7f7c2e2 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmLocalGenerator: Convert two recursive methods to loops.

parent c5cb3a73
......@@ -2853,41 +2853,71 @@ std::string cmLocalGenerator::Convert(RelativeRoot remote,
//----------------------------------------------------------------------------
std::string cmLocalGenerator::FindRelativePathTopSource()
{
// Relative path conversion within a single tree managed by CMake is
// safe. We can use our parent relative path top if and only if
// this is a subdirectory of that top.
if(cmLocalGenerator* parent = this->GetParent())
cmLocalGenerator* gen = this;
std::vector<cmLocalGenerator*> gens;
gens.push_back(gen);
while (true)
{
std::string parentTop = parent->FindRelativePathTopSource();
if(cmSystemTools::IsSubDirectory(
this->StateSnapshot.GetCurrentSourceDirectory(), parentTop))
gen = gen->GetParent();
if (gen)
{
return parentTop;
gens.push_back(gen);
}
else
{
break;
}
}
std::string result = gens.front()->StateSnapshot.GetCurrentSourceDirectory();
for (std::vector<cmLocalGenerator*>::const_iterator it = gens.begin() + 1;
it != gens.end(); ++it)
{
std::string currentSource =
(*it)->StateSnapshot.GetCurrentSourceDirectory();
if(cmSystemTools::IsSubDirectory(result, currentSource))
{
result = currentSource;
}
}
// Otherwise this directory itself is the new top.
return this->StateSnapshot.GetCurrentSourceDirectory();
return result;
}
//----------------------------------------------------------------------------
std::string cmLocalGenerator::FindRelativePathTopBinary()
{
// Relative path conversion within a single tree managed by CMake is
// safe. We can use our parent relative path top if and only if
// this is a subdirectory of that top.
if(cmLocalGenerator* parent = this->GetParent())
cmLocalGenerator* gen = this;
std::vector<cmLocalGenerator*> gens;
gens.push_back(gen);
while (true)
{
std::string parentTop = parent->FindRelativePathTopBinary();
if(cmSystemTools::IsSubDirectory(
this->StateSnapshot.GetCurrentBinaryDirectory(), parentTop))
gen = gen->GetParent();
if (gen)
{
return parentTop;
gens.push_back(gen);
}
else
{
break;
}
}
std::string result = gens.front()->StateSnapshot.GetCurrentBinaryDirectory();
for (std::vector<cmLocalGenerator*>::const_iterator it = gens.begin() + 1;
it != gens.end(); ++it)
{
std::string currentBinary =
(*it)->StateSnapshot.GetCurrentBinaryDirectory();
if(cmSystemTools::IsSubDirectory(result, currentBinary))
{
result = currentBinary;
}
}
// Otherwise this directory itself is the new top.
return this->StateSnapshot.GetCurrentBinaryDirectory();
return result;
}
//----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment