summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-09-03 18:51:55 (GMT)
committerBrad King <brad.king@kitware.com>2020-09-04 13:31:06 (GMT)
commitc4e296a60910c641a07695d1a9782912bce45d5c (patch)
tree53b0305890b4ab3d2fda351c56494425ad67ffd9 /Source/cmGlobalGenerator.cxx
parentb03bc81d62c68c664990bbb4b8b92d23fe9673a8 (diff)
downloadCMake-c4e296a60910c641a07695d1a9782912bce45d5c.zip
CMake-c4e296a60910c641a07695d1a9782912bce45d5c.tar.gz
CMake-c4e296a60910c641a07695d1a9782912bce45d5c.tar.bz2
cmGlobalGenerator: Compute a global target ordering respecting dependencies
Move this up from `cmGlobalXCodeGenerator`. It will be useful for all generators.
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r--Source/cmGlobalGenerator.cxx46
1 files changed, 46 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 74360b8..8688b1b 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1471,6 +1471,7 @@ bool cmGlobalGenerator::Compute()
if (!this->ComputeTargetDepends()) {
return false;
}
+ this->ComputeTargetOrder();
if (this->CheckTargetsForType()) {
return false;
@@ -1581,6 +1582,50 @@ bool cmGlobalGenerator::ComputeTargetDepends()
return true;
}
+std::vector<cmGeneratorTarget*>
+cmGlobalGenerator::GetLocalGeneratorTargetsInOrder(cmLocalGenerator* lg) const
+{
+ std::vector<cmGeneratorTarget*> gts;
+ cm::append(gts, lg->GetGeneratorTargets());
+ std::sort(gts.begin(), gts.end(),
+ [this](cmGeneratorTarget const* l, cmGeneratorTarget const* r) {
+ return this->TargetOrderIndex.at(l) <
+ this->TargetOrderIndex.at(r);
+ });
+ return gts;
+}
+
+void cmGlobalGenerator::ComputeTargetOrder()
+{
+ size_t index = 0;
+ auto const& lgens = this->GetLocalGenerators();
+ for (auto const& lgen : lgens) {
+ const auto& targets = lgen->GetGeneratorTargets();
+ for (const auto& gt : targets) {
+ this->ComputeTargetOrder(gt.get(), index);
+ }
+ }
+ assert(index == this->TargetOrderIndex.size());
+}
+
+void cmGlobalGenerator::ComputeTargetOrder(cmGeneratorTarget const* gt,
+ size_t& index)
+{
+ std::map<cmGeneratorTarget const*, size_t>::value_type value(gt, 0);
+ auto insertion = this->TargetOrderIndex.insert(value);
+ if (!insertion.second) {
+ return;
+ }
+ auto entry = insertion.first;
+
+ auto& deps = this->GetTargetDirectDepends(gt);
+ for (auto& d : deps) {
+ this->ComputeTargetOrder(d, index);
+ }
+
+ entry->second = index++;
+}
+
bool cmGlobalGenerator::QtAutoGen()
{
#ifndef CMAKE_BOOTSTRAP
@@ -1760,6 +1805,7 @@ void cmGlobalGenerator::ClearGeneratorMembers()
this->GeneratorTargetSearchIndex.clear();
this->MakefileSearchIndex.clear();
this->LocalGeneratorSearchIndex.clear();
+ this->TargetOrderIndex.clear();
this->ProjectMap.clear();
this->RuleHashes.clear();
this->DirectoryContentMap.clear();