[Cmake] include external msproject

Clinton Stimpson clinton at elemtech.com
Tue Sep 14 10:29:30 EDT 2004


Thanks Bill.  After getting the project files into the solution file and 
continuing with my regular work, I found that the project dependencies 
were missing.  The 7.0 and 7.1 IDE handles dependencies differently than 
6.0.
So here is another attached patch to handle dependencies correctly.  
This fixes it for 7.0 as well as 7.1.

Here's what I changed....
 void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& 
fout,

                                const char* name,
                                const char* location,
-                               const std::vector<std::string>& )
+                               const std::vector<std::string>& depends)

I added the depends parameter and implemented it.

I changed in cmIncludeExternalMSProjectCommand.cxx
     m_Makefile->AddUtilityCommand(utility_name.c_str(), "echo", 
"\"Include external project\"",
-                                  false, name_and_location, depends);
+                                  true, name_and_location, depends)

So that these projects can be part of the ALL_BUILD.
That flag is used in the writing out of the global project configuration 
in the solution file in both the 7.0 and 7.1 generator (code I added 
there too).
If that parameter is to stay false for 6.0, then we can change the code 
I added in the 7.0 and 7.1 generator to pass in a true instead of using 
the IsInAll flag.  The only difference this makes with 6.0 workspace 
files is that these external projects are added to the ALL_BUILD 
dependencies.

These changes are all necessary for correct project dependencies in 7.0 
and 7.1.  Otherwise, in the IDE, I have to manually build each of these 
external projects before the other projects that depend on them.

Thanks for the suggestions and howto for adding a test.  I'll give you 
one of those too.

Clint

William A. Hoffman wrote:

>Thanks for the fix, looks like the bug was in the 7 and 71 generators, 
>I have fixed both.  Here is the commit:
>
>$ cvs commit -m "BUG: fix include external project bug" cmGlobalVisualStudio71G
>enerator.cxx cmGlobalVisualStudio7Generator.cxx
>/cvsroot/CMake/CMake/Source/cmGlobalVisualStudio71Generator.cxx,v  <--  cmGlobal
>VisualStudio71Generator.cxx
>new revision: 1.13; previous revision: 1.12
>/cvsroot/CMake/CMake/Source/cmGlobalVisualStudio7Generator.cxx,v  <--  cmGlobalV
>isualStudio7Generator.cxx
>new revision: 1.34; previous revision: 1.33
>
>
>As for the test, it would have to be part of the cmake test suite.
>Once you build cmake, you and run ctest  in the build tree and
>it will run all the tests.  The tests are added in Source/CMakeLists.txt, and
>the source for them is in Tests/[testname].  So, if you could create a test, something
>like this:
>
>Tests/VSExternalInclude/
>
>It should have all the stuff it needs to run the test, and the external project will
>have to work from any directory.   That will be the tricky part.  I suppose you will
>have to use cmake to generate the external project to include, perhaps with an
>EXEC_PROGRAM call??  I am not sure.  I suppose you could also just check in a dsp and
>proj to include, and then use CONFIGURE_FILE to copy them from the source tree to the
>build tree.  That may be the best approach.   
>
>You add the test in Source/CMakeLists.txt like this:
>
>
> ADD_TEST(VSExternalInclude ${CMAKE_CTEST_COMMAND}
>    --build-and-test 
>    "${CMake_SOURCE_DIR}/Tests/VSExternalInclude"
>    "${CMake_BINARY_DIR}/Tests/VSExternalInclude"
>    --build-two-config
>    --build-generator ${CMAKE_GENERATOR}
>    --build-project VSExternalInclude
>    --build-makeprogram ${MAKEPROGRAM}
>    --test-command VSExternalInclude)
>
>-Bill
>
>
>
>At 05:57 PM 9/13/2004, Clinton Stimpson wrote:
>  
>
>>I've attached a patch file that'll fix this problem.  It changes just one line of code in cmGlobalVisualStudio71Generator.cxx and I used the VS 6.0 code for comparison.
>>
>>I can make a simple test case to make sure this command works with VC 6.0 and 7.1.  Who do I give this test case to?
>>Are you just looking for a simple set of code, project files, and CMakeLists.txt files to build a hello world or something?
>>
>>Clint
>>    
>>
>
>  
>
-------------- next part --------------
Index: cmGlobalVisualStudio71Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio71Generator.cxx,v
retrieving revision 1.12
diff -u -r1.12 cmGlobalVisualStudio71Generator.cxx
--- cmGlobalVisualStudio71Generator.cxx	15 Jun 2004 12:30:22 -0000	1.12
+++ cmGlobalVisualStudio71Generator.cxx	13 Sep 2004 23:39:45 -0000
@@ -205,7 +204,15 @@
     for(std::vector<std::string>::iterator si = dspnames.begin(); 
         l != tgts.end() && si != dspnames.end(); ++l)
       {
-      if ((l->second.GetType() != cmTarget::INSTALL_FILES)
+      if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+        {
+          cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
+          // dodgy use of the cmCustomCommand's members to store the 
+          // arguments from the INCLUDE_EXTERNAL_MSPROJECT command
+          std::vector<std::string> stuff = cc.GetDepends();
+          this->WriteProjectConfigurations(fout, stuff[0].c_str(), l->second.IsInAll());
+        }
+      else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
           && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
         {
         this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
@@ -282,8 +289,11 @@
     {
     if(*i != dspname)
       {
-      fout << "\t\t{" << this->GetGUID(i->c_str()) << "} = {"
-           << this->GetGUID(i->c_str()) << "}\n";
+        std::string name = i->c_str();
+        if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+          name.erase(name.begin(), name.begin() + 27);
+        fout << "\t\t{" << this->GetGUID(name.c_str()) << "} = {"
+             << this->GetGUID(name.c_str()) << "}\n";
       }
     }
 }
Index: cmGlobalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalVisualStudio7Generator.cxx,v
retrieving revision 1.33
diff -u -r1.33 cmGlobalVisualStudio7Generator.cxx
--- cmGlobalVisualStudio7Generator.cxx	7 Sep 2004 20:55:24 -0000	1.33
+++ cmGlobalVisualStudio7Generator.cxx	13 Sep 2004 23:39:45 -0000
@@ -476,7 +475,15 @@
     for(std::vector<std::string>::iterator si = dspnames.begin(); 
         l != tgts.end() && si != dspnames.end(); ++l)
       {
-      if ((l->second.GetType() != cmTarget::INSTALL_FILES)
+      if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
+        {
+          cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
+          // dodgy use of the cmCustomCommand's members to store the 
+          // arguments from the INCLUDE_EXTERNAL_MSPROJECT command
+          std::vector<std::string> stuff = cc.GetDepends();
+          this->WriteProjectConfigurations(fout, stuff[0].c_str(), l->second.IsInAll());
+        }
+      else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
           && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
         {
         this->WriteProjectDepends(fout, si->c_str(), dir.c_str(),l->second);
@@ -613,13 +620,33 @@
 void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout, 
                                const char* name,
                                const char* location,
-                               const std::vector<std::string>& )
+                               const std::vector<std::string>& depends)
 { 
   std::string d = cmSystemTools::ConvertToOutputPath(location);
   fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" 
        << name << "\", \""
        << d << "\", \"{"
-       << this->GetGUID(name) << "}\"\nEndProject\n";
+       << this->GetGUID(name)
+       << "}\"\n";
+
+  if(!depends.empty())
+  {
+    fout << "\tProjectSection(ProjectDependencies) = postProject\n";
+    std::vector<std::string>::const_iterator it;
+    for(it = depends.begin(); it != depends.end(); ++it)
+    {
+      if(it->size() > 0)
+      {
+        fout << "\t\t{" 
+             << this->GetGUID(it->c_str()) 
+             << "} = {" 
+             << this->GetGUID(it->c_str()) 
+             << "}\n";
+      }
+    }
+    fout << "\tEndProjectSection\n";
+  }  
+  fout << "EndProject\n";
 }
 
 
Index: cmIncludeExternalMSProjectCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmIncludeExternalMSProjectCommand.cxx,v
retrieving revision 1.8
diff -u -r1.8 cmIncludeExternalMSProjectCommand.cxx
--- cmIncludeExternalMSProjectCommand.cxx	7 Aug 2003 20:07:23 -0000	1.8
+++ cmIncludeExternalMSProjectCommand.cxx	13 Sep 2004 23:39:45 -0000
@@ -48,7 +48,7 @@
     utility_name += args[0];
     
     m_Makefile->AddUtilityCommand(utility_name.c_str(), "echo", "\"Include external project\"",
-                                  false, name_and_location, depends);
+                                  true, name_and_location, depends);
     
     }
 #endif


More information about the Cmake mailing list