Okay, here's my patch. It worked on my system. I tested with the versions I have installed: VS 2008 and VS 2013, and it worked great.

Fairly simple. Updated the docs [sufficiently, I think]. Thanks, Brad, for your direction.

Let me know your feedback.

Thanks

On 06/02/2015 11:45 AM, Brad King wrote:
On 06/01/2015 07:35 PM, Davy Durham wrote:
My plan is for it to simply pull a directory property called,
"VS_STARTUP_PROJECT".  However, I don't see how to access directory
properties from cmGlobalVisualStudioGenerator.  They seem to be
available from a cmLocalGenerator but not cmGlobalGenerator.
The WriteSLNFile method takes a "root" cmLocalGenerator.
You can call root->GetMakefile()->GetProperty("...") to get
the property for the solution file rooted at that directory.
It looks like some of the code paths may already thread the
"root" down to where you need it.  Otherwise you'll have to
add it to some method signatures.

Thanks,
-Brad


 Help/manual/cmake-properties.7.rst         |  1 +
 Help/prop_dir/VS_STARTUP_PROJECT.rst       | 12 +++++++++++
 Source/cmGlobalVisualStudio6Generator.cxx  |  2 +-
 Source/cmGlobalVisualStudio71Generator.cxx |  2 +-
 Source/cmGlobalVisualStudio7Generator.cxx  |  2 +-
 Source/cmGlobalVisualStudio8Generator.cxx  |  2 +-
 Source/cmGlobalVisualStudioGenerator.cxx   | 34 +++++++++++++++++++++++++-----
 Source/cmGlobalVisualStudioGenerator.h     |  9 ++++++--
 Source/cmVisualStudio10TargetGenerator.cxx |  2 +-
 9 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 615254e..5f2e65d 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -75,6 +75,7 @@ Properties on Directories
    /prop_dir/VARIABLES
    /prop_dir/VS_GLOBAL_SECTION_POST_section
    /prop_dir/VS_GLOBAL_SECTION_PRE_section
+   /prop_dir/VS_STARTUP_PROJECT
 
 .. _`Target Properties`:
 
diff --git a/Help/prop_dir/VS_STARTUP_PROJECT.rst b/Help/prop_dir/VS_STARTUP_PROJECT.rst
new file mode 100644
index 0000000..edd4832
--- /dev/null
+++ b/Help/prop_dir/VS_STARTUP_PROJECT.rst
@@ -0,0 +1,12 @@
+VS_STARTUP_PROJECT
+------------------
+
+Specify the default startup project in a Visual Studio solution.
+
+The property must be set to the name of an existing target.  This
+will cause that project to be listed first in the generated solution
+file causing Visual Studio to make it the startup project if the
+solution has never been opened before.
+
+If this property is not specified, then the "ALL_BUILD" project
+will be the default.
diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx
index 632141a..66925b9 100644
--- a/Source/cmGlobalVisualStudio6Generator.cxx
+++ b/Source/cmGlobalVisualStudio6Generator.cxx
@@ -218,7 +218,7 @@ void cmGlobalVisualStudio6Generator
   TargetDependSet projectTargets;
   TargetDependSet originalTargets;
   this->GetTargetSets(projectTargets, originalTargets, root, generators);
-  OrderedTargetDependSet orderedProjectTargets(projectTargets);
+  OrderedTargetDependSet orderedProjectTargets(projectTargets, this->GetStartupProjectName(root));
 
   for(OrderedTargetDependSet::const_iterator
         tt = orderedProjectTargets.begin();
diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx
index 1ab4c9c..4b50d40 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, this->GetStartupProjectName(root));
 
   this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
 
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index 4dd54d0..351ffca 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -570,7 +570,7 @@ void cmGlobalVisualStudio7Generator
   TargetDependSet projectTargets;
   TargetDependSet originalTargets;
   this->GetTargetSets(projectTargets, originalTargets, root, generators);
-  OrderedTargetDependSet orderedProjectTargets(projectTargets);
+  OrderedTargetDependSet orderedProjectTargets(projectTargets, this->GetStartupProjectName(root));
 
   this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
 
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index a3ebc61..ee87acf 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -447,7 +447,7 @@ void cmGlobalVisualStudio8Generator::WriteProjectDepends(
   std::ostream& fout, const std::string&, const char*, cmTarget const& t)
 {
   TargetDependSet const& unordered = this->GetTargetDirectDepends(t);
-  OrderedTargetDependSet depends(unordered);
+  OrderedTargetDependSet depends(unordered, this->GetStartupProjectName(NULL));
   for(OrderedTargetDependSet::const_iterator i = depends.begin();
       i != depends.end(); ++i)
     {
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 585d19a..1e66fd4 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -507,6 +507,22 @@ cmGlobalVisualStudioGenerator::GetUtilityDepend(cmTarget const* target)
 }
 
 //----------------------------------------------------------------------------
+std::string
+cmGlobalVisualStudioGenerator::GetStartupProjectName(const cmLocalGenerator* root) const
+{
+  if (root) {
+    const char* n = root->GetMakefile()->GetProperty("VS_STARTUP_PROJECT");
+      if (n && strcmp(n, "") != 0) {
+        // should we verify that this target even exists or report error?
+        return n;
+      }
+  }
+
+  // default, if not specified
+  return this->GetAllTargetName();
+}
+
+//----------------------------------------------------------------------------
 #include <windows.h>
 
 //----------------------------------------------------------------------------
@@ -841,16 +857,22 @@ cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target)
 }
 
 //----------------------------------------------------------------------------
+cmGlobalVisualStudioGenerator::TargetCompare
+::TargetCompare(const std::string& FirstProject_)
+: FirstProject(FirstProject_)
+{
+}
+
 bool
 cmGlobalVisualStudioGenerator::TargetCompare
 ::operator()(cmTarget const* l, cmTarget const* r) const
 {
-  // Make sure ALL_BUILD is first so it is the default active project.
-  if(r->GetName() == "ALL_BUILD")
+  // Make sure the user-specified firstProject is first so it is the default active project.
+  if(r->GetName() == FirstProject)
     {
     return false;
     }
-  if(l->GetName() == "ALL_BUILD")
+  if(l->GetName() == FirstProject)
     {
     return true;
     }
@@ -859,14 +881,16 @@ cmGlobalVisualStudioGenerator::TargetCompare
 
 //----------------------------------------------------------------------------
 cmGlobalVisualStudioGenerator::OrderedTargetDependSet
-::OrderedTargetDependSet(TargetDependSet const& targets)
+::OrderedTargetDependSet(TargetDependSet const& targets, const std::string& firstProject)
+: std::multiset<cmTargetDepend, TargetCompare>(TargetCompare(firstProject))
 {
   this->insert(targets.begin(), targets.end());
 }
 
 //----------------------------------------------------------------------------
 cmGlobalVisualStudioGenerator::OrderedTargetDependSet
-::OrderedTargetDependSet(TargetSet const& targets)
+::OrderedTargetDependSet(TargetSet const& targets, const std::string& firstProject)
+: std::multiset<cmTargetDepend, TargetCompare>(TargetCompare(firstProject))
 {
   this->insert(targets.begin(), targets.end());
 }
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
index 69b4564..9e3f5d0 100644
--- a/Source/cmGlobalVisualStudioGenerator.h
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -91,6 +91,8 @@ public:
   class TargetSet: public std::set<cmTarget const*> {};
   struct TargetCompare
   {
+    const std::string FirstProject;
+    TargetCompare(const std::string& FirstProject_);
     bool operator()(cmTarget const* l, cmTarget const* r) const;
   };
   class OrderedTargetDependSet;
@@ -102,6 +104,9 @@ public:
                                       const std::string& config) const;
 
   void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+
+  std::string GetStartupProjectName(const cmLocalGenerator* root) const;
+
 protected:
   virtual void Generate();
 
@@ -149,8 +154,8 @@ class cmGlobalVisualStudioGenerator::OrderedTargetDependSet:
 public:
   typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
   typedef cmGlobalVisualStudioGenerator::TargetSet TargetSet;
-  OrderedTargetDependSet(TargetDependSet const&);
-  OrderedTargetDependSet(TargetSet const&);
+  OrderedTargetDependSet(TargetDependSet const&, const std::string&);
+  OrderedTargetDependSet(TargetSet const&, const std::string&);
 };
 
 #endif
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 5dfdb14..8a0dc65 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -2670,7 +2670,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
     = this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
   typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
     OrderedTargetDependSet;
-  OrderedTargetDependSet depends(unordered);
+  OrderedTargetDependSet depends(unordered, this->GlobalGenerator->GetStartupProjectName(NULL));
   this->WriteString("<ItemGroup>\n", 1);
   for( OrderedTargetDependSet::const_iterator i = depends.begin();
        i != depends.end(); ++i)
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to