diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-05-04 20:38:52 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-05-14 18:36:28 (GMT) |
commit | e7f7c2e208a62c60e4a20ef115ba47a2ff7194a1 (patch) | |
tree | f5ed48deb0ad0a1778f6e436487ded4aadb55883 /Source | |
parent | c5cb3a734dd6d2472f10379d45dcec7ce03293d9 (diff) | |
download | CMake-e7f7c2e208a62c60e4a20ef115ba47a2ff7194a1.zip CMake-e7f7c2e208a62c60e4a20ef115ba47a2ff7194a1.tar.gz CMake-e7f7c2e208a62c60e4a20ef115ba47a2ff7194a1.tar.bz2 |
cmLocalGenerator: Convert two recursive methods to loops.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f3ad60a..1099f0f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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; } //---------------------------------------------------------------------------- |