[cmake-commits] hoffman committed cmGlobalGenerator.cxx 1.220 1.221 cmGlobalGenerator.h 1.103 1.104 cmGlobalUnixMakefileGenerator3.cxx 1.123 1.124 cmGlobalVisualStudio71Generator.cxx 1.46 1.47 cmGlobalVisualStudio71Generator.h 1.16 1.17 cmGlobalVisualStudio7Generator.cxx 1.96 1.97 cmGlobalVisualStudio7Generator.h 1.43 1.44 cmLocalVisualStudio7Generator.cxx 1.216 1.217 cmLocalVisualStudio7Generator.h 1.49 1.50

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Jan 30 12:04:40 EST 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv31553/Source

Modified Files:
	cmGlobalGenerator.cxx cmGlobalGenerator.h 
	cmGlobalUnixMakefileGenerator3.cxx 
	cmGlobalVisualStudio71Generator.cxx 
	cmGlobalVisualStudio71Generator.h 
	cmGlobalVisualStudio7Generator.cxx 
	cmGlobalVisualStudio7Generator.h 
	cmLocalVisualStudio7Generator.cxx 
	cmLocalVisualStudio7Generator.h 
Log Message:
ENH: fix for bug 3218 dependant projects are written out automatically if they are in the project.  Also fix bug 5829, remove hard coded CMAKE_CONFIGURATION_TYPES from vs 7 generator


Index: cmLocalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.cxx,v
retrieving revision 1.216
retrieving revision 1.217
diff -u -d -r1.216 -r1.217
--- cmLocalVisualStudio7Generator.cxx	29 Jan 2008 22:30:34 -0000	1.216
+++ cmLocalVisualStudio7Generator.cxx	30 Jan 2008 17:04:38 -0000	1.217
@@ -419,6 +419,7 @@
   // Check for specific options.
   bool UsingUnicode();
 
+  bool IsDebug();
   // Write options to output.
   void OutputPreprocessorDefinitions(std::ostream& fout,
                                      const char* prefix,
@@ -667,7 +668,7 @@
     }
 
   this->OutputTargetRules(fout, configName, target, libName);
-  this->OutputBuildTool(fout, configName, target);
+  this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
   fout << "\t\t</Configuration>\n";
 }
 
@@ -689,7 +690,8 @@
 
 void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
                                                     const char* configName,
-                                                    cmTarget &target)
+                                                    cmTarget &target,
+                                                    bool isDebug)
 {
   std::string temp;
   std::string extraLinkOptions;
@@ -802,8 +804,7 @@
     temp += targetNamePDB;
     fout << "\t\t\t\tProgramDataBaseFile=\"" <<
       this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
-    if(strcmp(configName, "Debug") == 0
-       || strcmp(configName, "RelWithDebInfo") == 0)
+    if(isDebug)
       {
       fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
       }
@@ -869,8 +870,7 @@
     fout << "\t\t\t\tProgramDataBaseFile=\""
          << target.GetDirectory(configName) << "/" << targetNamePDB
          << "\"\n";
-    if(strcmp(configName, "Debug") == 0
-       || strcmp(configName, "RelWithDebInfo") == 0)
+    if(isDebug)
       {
       fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
       }
@@ -1813,6 +1813,12 @@
   this->FlagMap[flag] = value;
 }
 
+
+bool cmLocalVisualStudio7GeneratorOptions::IsDebug()
+{
+  return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
+}
+
 //----------------------------------------------------------------------------
 bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
 {

Index: cmLocalVisualStudio7Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- cmLocalVisualStudio7Generator.h	29 Jan 2008 22:30:34 -0000	1.49
+++ cmLocalVisualStudio7Generator.h	30 Jan 2008 17:04:38 -0000	1.50
@@ -96,7 +96,7 @@
   void OutputTargetRules(std::ostream& fout, const char* configName, 
                          cmTarget &target, const char *libName);
   void OutputBuildTool(std::ostream& fout, const char* configName,
-                       cmTarget& t);
+                       cmTarget& t, bool debug);
   void OutputLibraryDirectories(std::ostream& fout,
                                 std::vector<std::string> const& dirs);
   void OutputModuleDefinitionFile(std::ostream& fout, cmTarget &target);

Index: cmGlobalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalGenerator.h,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- cmGlobalGenerator.h	28 Jan 2008 13:38:35 -0000	1.103
+++ cmGlobalGenerator.h	30 Jan 2008 17:04:38 -0000	1.104
@@ -234,8 +234,9 @@
   // Class to track a set of dependencies.
   class TargetDependSet: public std::set<cmTarget const*> {};
 
-  // what targets does the specified target depend on
-  TargetDependSet const& GetTargetDepends(cmTarget const& target);
+  // what targets does the specified target depend on directly
+  // via a target_link_libraries or add_dependencies
+  TargetDependSet const& GetTargetDirectDepends(cmTarget const& target);
 
   const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
                                                const {return this->ProjectMap;}
@@ -245,6 +246,15 @@
   void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
 
 protected:
+  // for a project collect all its targets by following depend
+  // information, and also collect all the targets
+  void GetTargetSets(cmGlobalGenerator::TargetDependSet& projectTargets,
+                     cmGlobalGenerator::TargetDependSet& originalTargets,
+                     cmLocalGenerator* root,
+                     std::vector<cmLocalGenerator*> const& generators);
+  void AddTargetDepends(cmTarget* target,
+                        cmGlobalGenerator::TargetDependSet&
+                        projectTargets);
   void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
   void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
 

Index: cmGlobalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.cxx,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- cmGlobalUnixMakefileGenerator3.cxx	23 Dec 2007 20:03:42 -0000	1.123
+++ cmGlobalUnixMakefileGenerator3.cxx	30 Jan 2008 17:04:38 -0000	1.124
@@ -861,7 +861,7 @@
       (target.GetMakefile()->GetLocalGenerator());
     result = static_cast<int>(lg->ProgressFiles[target.GetName()].size());
     
-    TargetDependSet const& depends = this->GetTargetDepends(target);
+    TargetDependSet const& depends = this->GetTargetDirectDepends(target);
     
     TargetDependSet::const_iterator i;
     for (i = depends.begin(); i != depends.end(); ++i)
@@ -898,7 +898,7 @@
 ::AppendGlobalTargetDepends(std::vector<std::string>& depends,
                             cmTarget& target)
 {
-  TargetDependSet const& depends_set = this->GetTargetDepends(target);
+  TargetDependSet const& depends_set = this->GetTargetDirectDepends(target);
   for(TargetDependSet::const_iterator i = depends_set.begin();
       i != depends_set.end(); ++i)
     {

Index: cmGlobalVisualStudio71Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio71Generator.cxx,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- cmGlobalVisualStudio71Generator.cxx	28 Jan 2008 13:38:35 -0000	1.46
+++ cmGlobalVisualStudio71Generator.cxx	30 Jan 2008 17:04:38 -0000	1.47
@@ -45,228 +45,34 @@
   mf->AddDefinition("MSVC71", "1");
 }
 
-// Write a SLN file to the stream
+
 void cmGlobalVisualStudio71Generator
 ::WriteSLNFile(std::ostream& fout,
                cmLocalGenerator* root,
                std::vector<cmLocalGenerator*>& generators)
-{
+{ 
   // Write out the header for a SLN file
   this->WriteSLNHeader(fout);
   
-  // Get the start directory with the trailing slash
-  std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
-  rootdir += "/";
-  bool doneAllBuild = false;
-  bool doneCheckBuild = false;
-  bool doneRunTests = false;
-  bool doneInstall  = false;
-  bool doneEditCache = false;
-  bool doneRebuildCache = false;
-  bool donePackage = false;
-  
-  // For each cmMakefile, create a VCProj for it, and
-  // add it to this SLN file
-  unsigned int i;
-  for(i = 0; i < generators.size(); ++i)
-    {
-    if(this->IsExcluded(root, generators[i]))
-      {
-      continue;
-      }
-    cmMakefile* mf = generators[i]->GetMakefile();
-
-    // Get the source directory from the makefile
-    std::string dir = mf->GetStartOutputDirectory();
-    // remove the home directory and / from the source directory
-    // this gives a relative path 
-    cmSystemTools::ReplaceString(dir, rootdir.c_str(), "");
-
-    // Get the list of create dsp files names from the cmVCProjWriter, more
-    // than one dsp could have been created per input CMakeLists.txt file
-    // for each target
-    cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
-    cmTargets::iterator l = tgts.begin();
-    for(; l != tgts.end(); ++l)
-      {
-      // special handling for the current makefile
-      if(mf == generators[0]->GetMakefile())
-        {
-        dir = "."; // no subdirectory for project generated
-        // if this is the special ALL_BUILD utility, then
-        // make it depend on every other non UTILITY project.
-        // This is done by adding the names to the GetUtilities
-        // vector on the makefile
-        if(l->first == "ALL_BUILD" && !doneAllBuild)
-          {
-          unsigned int j;
-          for(j = 0; j < generators.size(); ++j)
-            {
-            cmTargets &atgts = generators[j]->GetMakefile()->GetTargets();
-            for(cmTargets::iterator al = atgts.begin();
-                al != atgts.end(); ++al)
-              {
-              if (!al->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
-                {
-                if (al->second.GetType() == cmTarget::UTILITY ||
-                    al->second.GetType() == cmTarget::GLOBAL_TARGET)
-                  {
-                  l->second.AddUtility(al->first.c_str());
-                  }
-                else
-                  {
-                  l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
-                  }
-                }
-              }
-            }
-          }
-        }
-      // Write the project into the SLN file
-      if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
-        {
-        cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
-        const cmCustomCommandLines& cmds = cc.GetCommandLines();
-        std::string project = cmds[0][0];
-        std::string location = cmds[0][1];
-        this->WriteExternalProject(fout, project.c_str(), 
-                                   location.c_str(), cc.GetDepends());
-        }
-      else 
-        {
-          bool skip = false;
-          if(l->first == "ALL_BUILD" )
-            {
-            if(doneAllBuild)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneAllBuild = true;
-              }
-            }
-          if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET)
-            {
-            if(doneCheckBuild)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneCheckBuild = true;
-              }
-            }
-          if(l->first == "INSTALL")
-            {
-            if(doneInstall)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneInstall = true;
-              }
-            }
-          if(l->first == "RUN_TESTS")
-            {
-            if(doneRunTests)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneRunTests = true;
-              }
-            }
-          if(l->first == "EDIT_CACHE")
-            {
-            if(doneEditCache)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneEditCache = true;
-              }
-            }
-          if(l->first == "REBUILD_CACHE")
-            {
-            if(doneRebuildCache)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneRebuildCache = true;
-              }
-            }
-          if(l->first == "PACKAGE")
-            {
-            if(donePackage)
-              {
-              skip = true;
-              }
-            else
-              {
-              donePackage = true;
-              }
-            }
-          if(!skip)
-            {
-            const char *dspname = 
-              l->second.GetProperty("GENERATOR_FILE_NAME");
-            if (dspname)
-              {
-              this->WriteProject(fout, dspname, dir.c_str(),l->second);
-              }
-            }
-        }
-      }
-    }
+  // collect the set of targets for this project by 
+  // tracing depends of all targets.
+  // also collect the set of targets that are explicitly
+  // in this project. 
+  cmGlobalGenerator::TargetDependSet projectTargets;
+  cmGlobalGenerator::TargetDependSet originalTargets;
+  this->GetTargetSets(projectTargets,
+                      originalTargets,
+                      root, generators);
+  this->WriteTargetsToSolution(fout, root, projectTargets, originalTargets);
+  // Write out the configurations information for the solution
   fout << "Global\n";
+  // Write out the configurations for the solution
   this->WriteSolutionConfigurations(fout);
   fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
        << ") = postSolution\n";
-  // loop over again and compute the depends
-  for(i = 0; i < generators.size(); ++i)
-    {
-    cmMakefile* mf = generators[i]->GetMakefile();
-    cmLocalVisualStudio7Generator* pg =  
-      static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
-    // Get the list of create dsp files names from the cmVCProjWriter, more
-    // than one dsp could have been created per input CMakeLists.txt file
-    // for each target
-    cmTargets &tgts = pg->GetMakefile()->GetTargets();
-    cmTargets::iterator l = tgts.begin();
-    std::string dir = mf->GetStartDirectory();
-    for(; l != tgts.end(); ++l)
-      {
-      if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
-        {
-        cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
-        const cmCustomCommandLines& cmds = cc.GetCommandLines();
-        std::string project = cmds[0][0];
-        this->WriteProjectConfigurations(fout, project.c_str(),
-                                         true);
-        }
-      else
-        {
-        bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
-          root->GetMakefile()->GetProjectName(),
-          &l->second);
-        const char *dspname = 
-          l->second.GetProperty("GENERATOR_FILE_NAME");
-        if (dspname)
-          {
-          this->WriteProjectConfigurations(fout, dspname,
-                                           partOfDefaultBuild);
-          }
-        }
-      }
-    }
+  // Write out the configurations for all the targets in the project
+  this->WriteTargetConfigurations(fout, root, projectTargets);
   fout << "\tEndGlobalSection\n";
-
   // Write the footer for the SLN file
   this->WriteSLNFooter(fout);
 }
@@ -338,7 +144,9 @@
       if(j->first != dspname)
         {
         // is the library part of this SLN ? If so add dependency
-        if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str()))
+        // find target anywhere because all depend libraries are 
+        // brought in as well
+        if(this->FindTarget(0, j->first.c_str()))
           {
           fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
                << this->GetGUID(j->first.c_str()) << "}\n";
@@ -379,6 +187,7 @@
                        const char* location,
                        const std::vector<std::string>& depends)
 { 
+  std::cout << "WriteExternalProject vs71\n";
   fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" 
        << name << "\", \""
        << this->ConvertToSolutionPath(location) << "\", \"{"

Index: cmGlobalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalGenerator.cxx,v
retrieving revision 1.220
retrieving revision 1.221
diff -u -d -r1.220 -r1.221
--- cmGlobalGenerator.cxx	28 Jan 2008 18:05:58 -0000	1.220
+++ cmGlobalGenerator.cxx	30 Jan 2008 17:04:37 -0000	1.221
@@ -1036,7 +1036,6 @@
   std::string makeCommand =
     this->GenerateBuildCommand(makeCommandCSTR, projectName,
                                0, target, config, false, fast);
-
   if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), output,
                                        &retVal, 0, false, timeout))
     {
@@ -1291,7 +1290,7 @@
         // Add dependencies of the included target.  An excluded
         // target may still be included if it is a dependency of a
         // non-excluded target.
-        TargetDependSet const& tgtdeps = this->GetTargetDepends(target);
+        TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
         for(TargetDependSet::const_iterator ti = tgtdeps.begin();
             ti != tgtdeps.end(); ++ti)
           {
@@ -1684,7 +1683,7 @@
 
 //----------------------------------------------------------------------------
 cmGlobalGenerator::TargetDependSet const&
-cmGlobalGenerator::GetTargetDepends(cmTarget const& target)
+cmGlobalGenerator::GetTargetDirectDepends(cmTarget const& target)
 {
   // Clarify the role of the input target.
   cmTarget const* depender = &target;
@@ -1863,6 +1862,62 @@
     std::back_inserter(filenames));
 }
 
+void
+cmGlobalGenerator
+::GetTargetSets(cmGlobalGenerator::TargetDependSet& projectTargets,
+                cmGlobalGenerator::TargetDependSet& originalTargets,
+                cmLocalGenerator* root,
+                std::vector<cmLocalGenerator*> const& generators)
+{
+  // loop over all local generators
+  for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
+      i != generators.end(); ++i)
+    {
+    // check to make sure generator is not excluded
+    if(this->IsExcluded(root, *i))
+      {
+      continue;
+      }
+    cmMakefile* mf = (*i)->GetMakefile();
+    // Get the targets in the makefile
+    cmTargets &tgts = mf->GetTargets();  
+    // loop over all the targets
+    for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+      {
+      cmTarget* target = &l->second;
+      // put the target in the set of original targets
+      originalTargets.insert(target);
+      // Get the set of targets that depend on target
+      this->AddTargetDepends(target,
+                             projectTargets);
+      }
+    }
+}
+                
+void
+cmGlobalGenerator::AddTargetDepends(cmTarget* target,
+                                    cmGlobalGenerator::TargetDependSet&
+                                    projectTargets)
+{
+  // add the target itself
+  projectTargets.insert(target);
+  // get the direct depends of target
+  cmGlobalGenerator::TargetDependSet const& tset 
+    = this->GetTargetDirectDepends(*target);
+  if(tset.size())
+    {
+    // if there are targets that depend on target 
+    // add them and their depends as well
+    for(cmGlobalGenerator::TargetDependSet::const_iterator i =
+          tset.begin(); i != tset.end(); ++i)
+      {
+      cmTarget* dtarget = const_cast<cmTarget*>(*i);
+      this->AddTargetDepends(dtarget, projectTargets);
+      }
+    }
+}
+
+
 //----------------------------------------------------------------------------
 void cmGlobalGenerator::AddToManifest(const char* config,
                                       std::string const& f)
@@ -1901,3 +1956,4 @@
     }
   return dc;
 }
+

Index: cmGlobalVisualStudio7Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio7Generator.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- cmGlobalVisualStudio7Generator.h	28 Jun 2007 13:09:26 -0000	1.43
+++ cmGlobalVisualStudio7Generator.h	30 Jan 2008 17:04:38 -0000	1.44
@@ -114,11 +114,29 @@
   virtual void WriteSLNHeader(std::ostream& fout);
   virtual void AddPlatformDefinitions(cmMakefile* mf);
 
+  virtual void WriteTargetsToSolution(
+    std::ostream& fout,
+    cmLocalGenerator* root,
+    cmGlobalGenerator::TargetDependSet& projectTargets,
+    cmGlobalGenerator::TargetDependSet& originalTargets);
+  virtual void WriteTargetDepends(
+    std::ostream& fout,
+    cmGlobalGenerator::TargetDependSet& projectTargets);
+  virtual void WriteTargetConfigurations(
+    std::ostream& fout,
+    cmLocalGenerator* root,
+    cmGlobalGenerator::TargetDependSet& projectTargets);
+  
+  void AddAllBuildDepends(cmLocalGenerator* root,
+                          cmTarget* target,
+                          cmGlobalGenerator::TargetDependSet& targets);
+                                       
   void GenerateConfigurations(cmMakefile* mf);
 
-  void WriteExternalProject(std::ostream& fout, 
-                            const char* name, const char* path,
-                            const std::vector<std::string>& dependencies);
+  virtual void WriteExternalProject(std::ostream& fout, 
+                                    const char* name, 
+                                    const char* path,
+                                    const std::vector<std::string>& dependencies);
 
   std::string ConvertToSolutionPath(const char* path);
 

Index: cmGlobalVisualStudio71Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio71Generator.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- cmGlobalVisualStudio71Generator.h	9 Nov 2006 14:57:23 -0000	1.16
+++ cmGlobalVisualStudio71Generator.h	30 Jan 2008 17:04:38 -0000	1.17
@@ -56,7 +56,8 @@
   virtual void WriteProjectConfigurations(std::ostream& fout,
                                           const char* name,
                                           bool partOfDefaultBuild);
-  virtual void WriteExternalProject(std::ostream& fout, const char* name,
+  virtual void WriteExternalProject(std::ostream& fout,
+                                    const char* name,
                                     const char* path,
                                     const std::vector<std::string>& depends);
   virtual void WriteSLNFooter(std::ostream& fout);

Index: cmGlobalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio7Generator.cxx,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- cmGlobalVisualStudio7Generator.cxx	28 Jan 2008 13:38:35 -0000	1.96
+++ cmGlobalVisualStudio7Generator.cxx	30 Jan 2008 17:04:38 -0000	1.97
@@ -150,45 +150,20 @@
     = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
   if ( ct )
     {
-    std::string configTypes = ct;
-    
-    std::string::size_type start = 0;
-    std::string::size_type endpos = 0;
-    while(endpos != std::string::npos)
+    std::vector<std::string> argsOut;
+    cmSystemTools::ExpandListArgument(ct, argsOut);
+    for(std::vector<std::string>::iterator i = argsOut.begin();
+        i != argsOut.end(); ++i)
       {
-      endpos = configTypes.find_first_of(" ;", start);
-      std::string config;
-      std::string::size_type len;
-      if(endpos != std::string::npos)
-        {
-        len = endpos - start;
-        }
-      else
-        {
-        len = configTypes.size() - start;
-        }
-      config = configTypes.substr(start, len);
-      if(config == "Debug" || config == "Release" ||
-         config == "MinSizeRel" || config == "RelWithDebInfo")
-        {
-        // only add unique configurations
-        if(std::find(this->Configurations.begin(), 
-                     this->Configurations.end(),
-                     config) == this->Configurations.end())
-          {
-          this->Configurations.push_back(config);
-          }
-        }
-      else
+      if(std::find(this->Configurations.begin(), 
+                   this->Configurations.end(),
+                   *i) == this->Configurations.end())
         {
-        cmSystemTools::Error(
-          "Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ",
-          config.c_str(),
-          " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)");
+        this->Configurations.push_back(*i);
         }
-      start = endpos+1;
       }
     }
+  // default to at least Debug and Release
   if(this->Configurations.size() == 0)
     {
     this->Configurations.push_back("Debug");
@@ -265,293 +240,238 @@
 }
 
 
-// Write a SLN file to the stream
-void cmGlobalVisualStudio7Generator
-::WriteSLNFile(std::ostream& fout,
-               cmLocalGenerator* root,
-               std::vector<cmLocalGenerator*>& generators)
+void cmGlobalVisualStudio7Generator::AddAllBuildDepends(
+  cmLocalGenerator* root,
+  cmTarget* target,
+  cmGlobalGenerator::TargetDependSet& originalTargets)
 {
-  // Write out the header for a SLN file
-  this->WriteSLNHeader(fout);
-  
-  // Get the start directory with the trailing slash
-  std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
-  rootdir += "/";
-  bool doneAllBuild = false;
-  bool doneRunTests = false;
-  bool doneInstall  = false;
-  bool doneEditCache = false;
-  bool doneRebuildCache = false;
-  bool donePackage = false;
-  
-  
-  // 1.
-  // Collecte all targets in generators vector and the targets
-  // that they depend on
-  
-  // 2. loop over all targets and put .vcproj reference 
-  //   into .sln file. .vcproj files should already exist
-  //   from local generation step.  Do not add "pulled" in .vcproj
-  //   to ALL_BUILD.
-  // See: cmGlobalGenerator::GetTargetDepends
-  // cmGlobalGenerator::TargetDependSet myset;
-  // foreach t in all targets
-  //   cmGlobalGenerator::TargetDependSet const& tset = GetTargetDepends(t);
-  //    myset.insert(tset.begin(), tset.end());
-  //  foreach t in myset
-  //    t->GetMakefile()->GetLocalGenerator()->GetVCProjPath()
-  //  if t was not in original set of targets disable all for it
-  
-  // For each cmMakefile, create a VCProj for it, and
-  // add it to this SLN file
-  unsigned int i;
-  for(i = 0; i < generators.size(); ++i)
+  // if this is the special ALL_BUILD utility, then
+  // make it depend on every other non UTILITY project.
+  for(cmGlobalGenerator::TargetDependSet::iterator ot =
+        originalTargets.begin(); ot != originalTargets.end(); ++ot)
     {
-    if(this->IsExcluded(root, generators[i]))
-      {
-      continue;
-      }
-    cmMakefile* mf = generators[i]->GetMakefile();
-
-    // Get the source directory from the makefile
-    std::string dir = mf->GetStartOutputDirectory();
-    // remove the home directory and / from the source directory
-    // this gives a relative path 
-    cmSystemTools::ReplaceString(dir, rootdir.c_str(), "");
-
-    // Get the list of create dsp files names from the cmVCProjWriter, more
-    // than one dsp could have been created per input CMakeLists.txt file
-    // for each target
-    cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
-    for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
+    cmTarget* t = const_cast<cmTarget*>(*ot);
+    if(!this->IsExcluded(root, *t))
       {
-      // special handling for the current makefile
-      if(mf == generators[0]->GetMakefile())
+      if (t->GetType() == cmTarget::UTILITY ||
+          t->GetType() == cmTarget::GLOBAL_TARGET)
         {
-        dir = "."; // no subdirectory for project generated
-        // if this is the special ALL_BUILD utility, then
-        // make it depend on every other non UTILITY project.
-        // This is done by adding the names to the GetUtilities
-        // vector on the makefile
-        if(l->first == "ALL_BUILD" && !doneAllBuild)
-          {
-          unsigned int j;
-          for(j = 0; j < generators.size(); ++j)
-            {
-            cmTargets &atgts = generators[j]->GetMakefile()->GetTargets();
-            for(cmTargets::iterator al = atgts.begin();
-                al != atgts.end(); ++al)
-              {
-              if (!al->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
-                {
-                if (al->second.GetType() == cmTarget::UTILITY ||
-                    al->second.GetType() == cmTarget::GLOBAL_TARGET)
-                  {
-                  l->second.AddUtility(al->first.c_str());
-                  }
-                else
-                  {
-                  l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
-                  }
-                }
-              }
-            }
-          }
+        target->AddUtility(t->GetName());
         }
-      // Write the project into the SLN file
-      if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+      else
         {
-        cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
-        const cmCustomCommandLines& cmds = cc.GetCommandLines();
-        std::string project = cmds[0][0];
-        std::string location = cmds[0][1];
-        this->WriteExternalProject(fout, project.c_str(), 
-                                   location.c_str(), cc.GetDepends());
+        target->AddLinkLibrary(t->GetName(),cmTarget::GENERAL);
         }
-      else 
+      }
+    }
+}
+
+void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
+  std::ostream& fout, 
+  cmLocalGenerator* root,
+  cmGlobalGenerator::TargetDependSet& projectTargets)
+{
+  // loop over again and write out configurations for each target
+  // in the solution
+  for(cmGlobalGenerator::TargetDependSet::iterator tt =
+        projectTargets.begin(); tt != projectTargets.end(); ++tt)
+    {
+    cmTarget* target = const_cast<cmTarget*>(*tt);
+    if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+      {
+      cmCustomCommand cc = target->GetPostBuildCommands()[0];
+      const cmCustomCommandLines& cmds = cc.GetCommandLines();
+      std::string project = cmds[0][0];
+      this->WriteProjectConfigurations(fout, project.c_str(),
+                                       true);
+      }
+    else
+      {
+      bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
+        root->GetMakefile()->GetProjectName(), target);
+      const char *vcprojName = 
+        target->GetProperty("GENERATOR_FILE_NAME");
+      if (vcprojName)
         {
-          bool skip = false;
-          if(l->first == "ALL_BUILD" )
-            {
-            if(doneAllBuild)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneAllBuild = true;
-              }
-            }
-          if(l->first == "INSTALL")
-            {
-            if(doneInstall)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneInstall = true;
-              }
-            }
-          if(l->first == "RUN_TESTS")
-            {
-            if(doneRunTests)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneRunTests = true;
-              }
-            }
-          if(l->first == "EDIT_CACHE")
-            {
-            if(doneEditCache)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneEditCache = true;
-              }
-            }
-          if(l->first == "REBUILD_CACHE")
-            {
-            if(doneRebuildCache)
-              {
-              skip = true;
-              }
-            else
-              {
-              doneRebuildCache = true;
-              }
-            }
-          if(l->first == "PACKAGE")
-            {
-            if(donePackage)
-              {
-              skip = true;
-              }
-            else
-              {
-              donePackage = true;
-              }
-            }
-          if(!skip)
-            {
-            const char *dspname = 
-              l->second.GetProperty("GENERATOR_FILE_NAME");
-            if (dspname)
-              {
-              this->WriteProject(fout, dspname, dir.c_str(),l->second);
-              }
-            }
+        this->WriteProjectConfigurations(fout, vcprojName,
+                                         partOfDefaultBuild);
         }
       }
     }
-  fout << "Global\n"
-       << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
-  
-  int c = 0;
-  for(std::vector<std::string>::iterator i = this->Configurations.begin();
-      i != this->Configurations.end(); ++i)
+}
+
+
+void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
+    std::ostream& fout,
+    cmLocalGenerator* root,
+    cmGlobalGenerator::TargetDependSet& projectTargets,
+    cmGlobalGenerator::TargetDependSet& originalTargets
+    )
+{
+  // Create a map of project that should only show up once
+  // in a project
+  const char* onlyOnceNames[] = 
+    {"INCLUDE_EXTERNAL_MSPROJECT","CMAKE_CHECK_BUILD_SYSTEM_TARGET",
+     "INSTALL", "RUN_TESTS", "EDIT_CACHE", "REBUILD_CACHE", "PACKAGE", 0};
+  std::map<cmStdString, int> onlyOnceMap;
+  int i =0;
+  for(const char* name = onlyOnceNames[i];
+      name != 0; name = onlyOnceNames[++i])
     {
-    fout << "\t\tConfigName." << c << " = " << *i << "\n";
-    c++;
+    onlyOnceMap[name] = 0;
     }
-  fout << "\tEndGlobalSection\n"
-       << "\tGlobalSection(ProjectDependencies) = postSolution\n";
-
-  // loop over again and compute the depends
-  for(i = 0; i < generators.size(); ++i)
+  // add the CMAKE_CHECK_BUILD_SYSTEM_TARGET 
+  onlyOnceMap[CMAKE_CHECK_BUILD_SYSTEM_TARGET] = 0;
+  std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
+  rootdir += "/";
+  for(cmGlobalGenerator::TargetDependSet::iterator tt =
+        projectTargets.begin(); tt != projectTargets.end(); ++tt)
     {
-    cmMakefile* mf = generators[i]->GetMakefile();
-    cmLocalVisualStudio7Generator* pg =  
-      static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
-    // Get the list of create dsp files names from the cmVCProjWriter, more
-    // than one dsp could have been created per input CMakeLists.txt file
-    // for each target
-    cmTargets &tgts = pg->GetMakefile()->GetTargets();
-    cmTargets::iterator l = tgts.begin();
-    std::string dir = mf->GetStartDirectory();
-    for(; l != tgts.end(); ++l)
+    cmTarget* target = const_cast<cmTarget*>(*tt);
+    cmMakefile* mf = target->GetMakefile();
+    // look for the all_build rule and add depends to all
+    // of the original targets (none that were "pulled" into this project)
+    if(mf == root->GetMakefile() &&
+       strcmp(target->GetName(), "ALL_BUILD") == 0)
       {
-       if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
-         {
-         cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
-         const cmCustomCommandLines& cmds = cc.GetCommandLines();
-         std::string name = cmds[0][0];
-         std::vector<std::string> depends = cc.GetDepends();
-         std::vector<std::string>::iterator iter;
-         int depcount = 0;
-         for(iter = depends.begin(); iter != depends.end(); ++iter)
-           {
-           std::string guid = this->GetGUID(iter->c_str());
-           if(guid.size() == 0)
-             {
-             std::string m = "Target: ";
-             m += l->first;
-             m += " depends on unknown target: ";
-             m += iter->c_str();
-             cmSystemTools::Error(m.c_str());
-             }
-           
-           fout << "\t\t{" << this->GetGUID(name.c_str()) 
-                << "}." << depcount << " = {" << guid.c_str() << "}\n";
-           depcount++;
-           }
-         }
-       else
+      this->AddAllBuildDepends(root, target, originalTargets);
+      }
+    // handle external vc project files
+    if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+      { 
+      cmCustomCommand cc = target->GetPostBuildCommands()[0];
+      const cmCustomCommandLines& cmds = cc.GetCommandLines();
+      std::string project = cmds[0][0];
+      std::string location = cmds[0][1];
+      std::cout << "About to call WriteExternalProject " << this->GetName() << "\n";
+      this->WriteExternalProject(fout, project.c_str(), 
+                                 location.c_str(), cc.GetDepends());
+      }
+    else
+      {
+      // if the target is an onlyOnceNames do it once
+      std::map<cmStdString, int>::iterator o = 
+        onlyOnceMap.find(target->GetName());
+      bool skip = false;
+      if(o != onlyOnceMap.end())
         {
-        const char *dspname = 
-          l->second.GetProperty("GENERATOR_FILE_NAME");
-        if (dspname)
+        if(o->second > 0)
           {
-          this->WriteProjectDepends(fout, dspname, 
-                                    dir.c_str(), l->second);
+          skip = true;
+          }
+        else
+          {
+          o->second++;
+          }
+        }
+      // if not skipping the project then write it into the 
+      // solution
+      if(!skip)
+        { 
+        const char *vcprojName = 
+          target->GetProperty("GENERATOR_FILE_NAME");
+        if(vcprojName)
+          {
+          cmMakefile* tmf = target->GetMakefile();
+          std::string dir = tmf->GetStartOutputDirectory();
+          dir = root->Convert(dir.c_str(), 
+                              cmLocalGenerator::START_OUTPUT);
+          this->WriteProject(fout, vcprojName, dir.c_str(),
+                             *target);
           }
         }
       }
     }
-  fout << "\tEndGlobalSection\n";
-  fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
-  // loop over again and compute the depends
-  for(i = 0; i < generators.size(); ++i)
+}
+
+
+void cmGlobalVisualStudio7Generator::WriteTargetDepends(
+    std::ostream& fout,
+    cmGlobalGenerator::TargetDependSet& projectTargets
+    )
+{
+  for(cmGlobalGenerator::TargetDependSet::iterator tt =
+        projectTargets.begin(); tt != projectTargets.end(); ++tt)
     {
-    cmMakefile* mf = generators[i]->GetMakefile();
-    cmLocalVisualStudio7Generator* pg =  
-      static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
-    // Get the list of create dsp files names from the cmVCProjWriter, more
-    // than one dsp could have been created per input CMakeLists.txt file
-    // for each target
-    cmTargets &tgts = pg->GetMakefile()->GetTargets();
-    cmTargets::iterator l = tgts.begin();
-    std::string dir = mf->GetStartDirectory();
-    for(; l != tgts.end(); ++l)
+    cmTarget* target = const_cast<cmTarget*>(*tt);
+    cmMakefile* mf = target->GetMakefile();
+    if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
       {
-      if(strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+      cmCustomCommand cc = target->GetPostBuildCommands()[0];
+      const cmCustomCommandLines& cmds = cc.GetCommandLines();
+      std::string name = cmds[0][0];
+      std::vector<std::string> depends = cc.GetDepends();
+      std::vector<std::string>::iterator iter;
+      int depcount = 0;
+      for(iter = depends.begin(); iter != depends.end(); ++iter)
         {
-        cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
-        const cmCustomCommandLines& cmds = cc.GetCommandLines();
-        std::string name = cmds[0][0];
-        this->WriteProjectConfigurations(fout, name.c_str(),
-                                         true);
-        }
-      else
-        {    
-        bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
-          root->GetMakefile()->GetProjectName(),
-          &l->second);
-        const char *dspname = 
-          l->second.GetProperty("GENERATOR_FILE_NAME");
-        if (dspname)
+        std::string guid = this->GetGUID(iter->c_str());
+        if(guid.size() == 0)
           {
-          this->WriteProjectConfigurations(fout, dspname,
-                                           partOfDefaultBuild);
+          std::string m = "Target: ";
+          m += target->GetName();
+          m += " depends on unknown target: ";
+          m += iter->c_str();
+          cmSystemTools::Error(m.c_str());
           }
+        
+        fout << "\t\t{" << this->GetGUID(name.c_str()) 
+             << "}." << depcount << " = {" << guid.c_str() << "}\n";
+        depcount++;
+        }
+      }
+    else
+      {
+      const char *vcprojName = 
+        target->GetProperty("GENERATOR_FILE_NAME");
+      if (vcprojName)
+        { 
+        std::string dir = mf->GetStartDirectory();
+        this->WriteProjectDepends(fout, vcprojName, 
+                                  dir.c_str(), *target);
         }
       }
     }
+}
+// Write a SLN file to the stream
+void cmGlobalVisualStudio7Generator
+::WriteSLNFile(std::ostream& fout,
+               cmLocalGenerator* root,
+               std::vector<cmLocalGenerator*>& generators)
+{
+  // Write out the header for a SLN file
+  this->WriteSLNHeader(fout);
+  
+   // collect the set of targets for this project by 
+  // tracing depends of all targets.
+  // also collect the set of targets that are explicitly
+  // in this project. 
+  cmGlobalGenerator::TargetDependSet projectTargets;
+  cmGlobalGenerator::TargetDependSet originalTargets;
+  this->GetTargetSets(projectTargets,
+                      originalTargets,
+                      root, generators);
+  this->WriteTargetsToSolution(fout, root, projectTargets, originalTargets);
+  // Write out the configurations information for the solution
+  fout << "Global\n"
+       << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
+  
+  int c = 0;
+  for(std::vector<std::string>::iterator i = this->Configurations.begin();
+      i != this->Configurations.end(); ++i)
+    {
+    fout << "\t\tConfigName." << c << " = " << *i << "\n";
+    c++;
+    }
+  fout << "\tEndGlobalSection\n";
+  // Write out project(target) depends 
+  fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
+  this->WriteTargetDepends(fout, projectTargets);
+  fout << "\tEndGlobalSection\n";
+
+  // Write out the configurations for all the targets in the project
+  fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
+  this->WriteTargetConfigurations(fout, root, projectTargets);
   fout << "\tEndGlobalSection\n";
 
   // Write the footer for the SLN file
@@ -611,7 +531,7 @@
       if(j->first != dspname)
         {
         // is the library part of this SLN ? If so add dependency
-        if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str()))
+        if(this->FindTarget(0, j->first.c_str()))
           {
           std::string guid = this->GetGUID(j->first.c_str());
           if(guid.size() == 0)
@@ -687,6 +607,7 @@
                                const char* location,
                                const std::vector<std::string>&)
 { 
+  std::cout << "WriteExternalProject vs7\n";
   std::string d = cmSystemTools::ConvertToOutputPath(location);
   fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" 
        << name << "\", \""



More information about the Cmake-commits mailing list