[CMake] Patch: Automatic visual studio project file inclusion

Manuel Klimek klimek at box4.net
Wed May 10 08:07:30 EDT 2006


Hi there,

since I'm sometimes not good at describing stuff I need, I just
wrote a patch to cmake 2.4.1, which fixes my need.
This patch automatically includes dependant visual studio
project files into a solution.
To try it for cmake itself, edit Sources/MFCDialog/CMakeLists.txt
and add
PROJECT( CMakeSetup )
Then run the patched cmake and you'll get a nice CMakeSetup.sln
in the corresponding subdirectory where you can build all of
cmake that is required to link and run CMakeSetup - and you
don't need to build or load the rest (like documentation).
I don't know if it's ok to use this patch by default (are
people using subprojects without dependencies?).
I even don't know if it's the correct place to insert stuff
like this, but my changes are very local (big thumbs up to
whoever did the OO layout for this stuff ;-)

What I did:
- loop over all generators:
  - for all dependencies:
    - if new dependency:
      - add generator to generator list
      - update project map

Anyways, here's the patch...
Bye,
Manuel

--- cmake-2.4.1-orig/Source/cmGlobalVisualStudio71Generator.cxx	2006-04-30
17:06:37.000000000 +0200
+++ cmake-2.4.1/Source/cmGlobalVisualStudio71Generator.cxx	2006-05-10
13:36:19.343750000 +0200
@@ -44,7 +44,7 @@
 // Write a SLN file to the stream
 void cmGlobalVisualStudio71Generator::WriteSLNFile(std::ostream& fout,
                                                    cmLocalGenerator* root,
-                                                  
std::vector<cmLocalGenerator*>& generators)
+                                                  
std::vector<cmLocalGenerator*>& localGenerators)
 {
   // Write out the header for a SLN file
   this->WriteSLNHeader(fout);
@@ -59,7 +59,71 @@
   bool doneEditCache = false;
   bool doneRebuildCache = false;
   bool donePackage = false;
-
+
+  std::vector<cmLocalGenerator*> generators = localGenerators;
+  if(!generators.empty())
+    {
+    // calculate closure on library dependencies
+    cmLocalGenerator *topGenerator = generators[0];
+    while(topGenerator->GetParent() != NULL)
+      {
+      topGenerator = topGenerator->GetParent();
+      }
+    unsigned int lastSize = 0;
+    do
+      {
+      std::vector<cmLocalGenerator*> dependencyGenerators;
+      lastSize = generators.size();
+      // build closure
+      for(unsigned int i=0; i<generators.size(); ++i)
+        {
+        cmMakefile *makefile = generators[i]->GetMakefile();
+        for(cmTargets::iterator it=makefile->GetTargets().begin(); it !=
makefile->GetTargets().end(); ++it)
+          {
+          if(it->second.GetType() != cmTarget::STATIC_LIBRARY)
+            {
+            cmTarget::LinkLibraryVectorType::const_iterator j, jend;
+            j = it->second.GetLinkLibraries().begin();
+            jend = it->second.GetLinkLibraries().end();
+            for(;j!= jend; ++j)
+              {
+              cmTarget *dependency =
topGenerator->GetGlobalGenerator()->FindTarget(NULL, j->first.c_str());
+              if(dependency)
+                {
+                cmLocalGenerator* generator =
topGenerator->GetGlobalGenerator()->FindLocalGenerator(dependency->GetMakefile()->GetCurrentDirectory());
+                bool found = false;
+                for(unsigned int k=0; k<generators.size() && !found; ++k)
+                  {
+                    if(generators[k] == generator)
+                      {
+                        found = true;
+                      }
+                  }
+                for(unsigned int k=0; k<dependencyGenerators.size() &&
!found; ++k)
+                  {
+                    if(dependencyGenerators[k] == generator)
+                      {
+                        found = true;
+                      }
+                  }
+                if(!found)
+                  {
+                    dependencyGenerators.push_back(generator);
+                   
this->ProjectMap[generators[i]->GetMakefile()->GetProjectName()].push_back(generator);
+                  }
+                }
+              }
+            }
+          }
+        }
+      for(unsigned int i=0; i<dependencyGenerators.size(); ++i)
+        {
+        generators.push_back(dependencyGenerators[i]);
+        }
+      }
+    while(lastSize < generators.size());
+    }
+
   // For each cmMakefile, create a VCProj for it, and
   // add it to this SLN file
   unsigned int i;



More information about the CMake mailing list