From 03bfe71ae055ed9e5dbeb619967ee44e5f555459 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Sep 2015 10:14:49 -0400 Subject: VS: Refactor target ordering logic Refactor cmGlobalVisualStudioGenerator::TargetCompare to store the name of the target that should come first instead of hard-coding "ALL_BUILD". Update client sites to specify "ALL_BUILD" when ordering for .sln files and an empty string otherwise (in cases when "ALL_BUILD" should not be encountered anyway). --- Source/cmGlobalVisualStudio6Generator.cxx | 2 +- Source/cmGlobalVisualStudio71Generator.cxx | 2 +- Source/cmGlobalVisualStudio7Generator.cxx | 2 +- Source/cmGlobalVisualStudio8Generator.cxx | 2 +- Source/cmGlobalVisualStudioGenerator.cxx | 18 ++++++++++++------ Source/cmGlobalVisualStudioGenerator.h | 12 +++++++++--- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx index df49948..14de698 100644 --- a/Source/cmGlobalVisualStudio6Generator.cxx +++ b/Source/cmGlobalVisualStudio6Generator.cxx @@ -217,7 +217,7 @@ void cmGlobalVisualStudio6Generator TargetDependSet projectTargets; TargetDependSet originalTargets; this->GetTargetSets(projectTargets, originalTargets, root, generators); - OrderedTargetDependSet orderedProjectTargets(projectTargets); + OrderedTargetDependSet orderedProjectTargets(projectTargets, "ALL_BUILD"); for(OrderedTargetDependSet::const_iterator tt = orderedProjectTargets.begin(); diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 607642c..b913afc 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -94,7 +94,7 @@ void cmGlobalVisualStudio71Generator TargetDependSet projectTargets; TargetDependSet originalTargets; this->GetTargetSets(projectTargets, originalTargets, root, generators); - OrderedTargetDependSet orderedProjectTargets(projectTargets); + OrderedTargetDependSet orderedProjectTargets(projectTargets, "ALL_BUILD"); this->WriteTargetsToSolution(fout, root, orderedProjectTargets); diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 0175062..05da022 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -568,7 +568,7 @@ void cmGlobalVisualStudio7Generator TargetDependSet projectTargets; TargetDependSet originalTargets; this->GetTargetSets(projectTargets, originalTargets, root, generators); - OrderedTargetDependSet orderedProjectTargets(projectTargets); + OrderedTargetDependSet orderedProjectTargets(projectTargets, "ALL_BUILD"); this->WriteTargetsToSolution(fout, root, orderedProjectTargets); diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 28f0425..70c00e9 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -449,7 +449,7 @@ void cmGlobalVisualStudio8Generator::WriteProjectDepends( { cmGeneratorTarget* gt = this->GetGeneratorTarget(&t); TargetDependSet const& unordered = this->GetTargetDirectDepends(gt); - OrderedTargetDependSet depends(unordered); + OrderedTargetDependSet depends(unordered, std::string()); for(OrderedTargetDependSet::const_iterator i = depends.begin(); i != depends.end(); ++i) { diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 2bf04b4..e7cc8ff 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -864,28 +864,34 @@ bool cmGlobalVisualStudioGenerator::TargetCompare ::operator()(cmGeneratorTarget const* l, cmGeneratorTarget const* r) const { - // Make sure ALL_BUILD is first so it is the default active project. - if(r->GetName() == "ALL_BUILD") + // Make sure a given named target is ordered first, + // e.g. to set ALL_BUILD as the default active project. + // When the empty string is named this is a no-op. + if (r->GetName() == this->First) { return false; } - if(l->GetName() == "ALL_BUILD") + if (l->GetName() == this->First) { return true; } - return strcmp(l->GetName().c_str(), r->GetName().c_str()) < 0; + return l->GetName() < r->GetName(); } //---------------------------------------------------------------------------- cmGlobalVisualStudioGenerator::OrderedTargetDependSet -::OrderedTargetDependSet(TargetDependSet const& targets) +::OrderedTargetDependSet(TargetDependSet const& targets, + std::string const& first): + derived(TargetCompare(first)) { this->insert(targets.begin(), targets.end()); } //---------------------------------------------------------------------------- cmGlobalVisualStudioGenerator::OrderedTargetDependSet -::OrderedTargetDependSet(TargetSet const& targets) +::OrderedTargetDependSet(TargetSet const& targets, + std::string const& first): + derived(TargetCompare(first)) { for (TargetSet::const_iterator it = targets.begin(); it != targets.end(); ++it) diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 64440ad..c940eb3 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -89,8 +89,11 @@ public: virtual bool TargetsWindowsCE() const { return false; } class TargetSet: public std::set {}; - struct TargetCompare + class TargetCompare { + std::string First; + public: + TargetCompare(std::string const& first): First(first) {} bool operator()(cmGeneratorTarget const* l, cmGeneratorTarget const* r) const; }; @@ -151,11 +154,14 @@ class cmGlobalVisualStudioGenerator::OrderedTargetDependSet: public std::multiset { + typedef std::multiset + derived; public: typedef cmGlobalGenerator::TargetDependSet TargetDependSet; typedef cmGlobalVisualStudioGenerator::TargetSet TargetSet; - OrderedTargetDependSet(TargetDependSet const&); - OrderedTargetDependSet(TargetSet const&); + OrderedTargetDependSet(TargetDependSet const&, std::string const& first); + OrderedTargetDependSet(TargetSet const&, std::string const& first); }; #endif diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index cb5048d..b91ae11 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2849,7 +2849,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() = this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget); typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet OrderedTargetDependSet; - OrderedTargetDependSet depends(unordered); + OrderedTargetDependSet depends(unordered, std::string()); this->WriteString("\n", 1); for( OrderedTargetDependSet::const_iterator i = depends.begin(); i != depends.end(); ++i) -- cgit v0.12 From 40c7b4612341e4230516ef32a97449051379790a Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Sep 2015 10:20:44 -0400 Subject: VS: Fix rebuild with regeneration after input CMake code change (#15754) When using "cmake --build ." or "MSBuild ALL_BUILD.vcxproj" to drive the build the dependencies in the .sln file are not considered. This means that ProjectReference elements in .vcxproj files are used to order targets. We must ensure that the ZERO_CHECK target is listed as the first dependency of every target so that when it causes regeneration of the build files then MSBuild has not yet loaded the updated files. --- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index b91ae11..92403e3 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2849,7 +2849,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() = this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget); typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet OrderedTargetDependSet; - OrderedTargetDependSet depends(unordered, std::string()); + OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET); this->WriteString("\n", 1); for( OrderedTargetDependSet::const_iterator i = depends.begin(); i != depends.end(); ++i) -- cgit v0.12