[cmake-commits] alex committed cmExportLibraryDependencies.cxx 1.17 1.18 cmExportLibraryDependencies.h 1.5 1.6 cmGlobalGenerator.h 1.80 1.81 cmLocalGenerator.h 1.82 1.83 cmMakefile.h 1.206 1.207 cmTarget.h 1.86 1.87 cmake.cxx 1.297 1.298 cmake.h 1.81 1.82

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Jun 15 10:10:26 EDT 2007


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

Modified Files:
	cmExportLibraryDependencies.cxx cmExportLibraryDependencies.h 
	cmGlobalGenerator.h cmLocalGenerator.h cmMakefile.h cmTarget.h 
	cmake.cxx cmake.h 
Log Message:

STYLE: remove duplicate non-const accessors GetLocalGenerator(int) and
GetLocaGenerators(cmLocalGenerators) from cmGlobalGenerator(). Now there is
one const accessor which is even faster since it returns a reference
(instead of copying a vector)
-more const to ensure that this the returned local generators don't actually
get modified
-removed duplicated code in GetCTestCommand() and GetCPackCommand()
-added some const accessors

Alex


Index: cmLocalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.h,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- cmLocalGenerator.h	17 May 2007 14:53:17 -0000	1.82
+++ cmLocalGenerator.h	15 Jun 2007 14:10:24 -0000	1.83
@@ -81,6 +81,10 @@
   cmMakefile *GetMakefile() {
     return this->Makefile; };
   
+  ///! Get the makefile for this generator, const version
+    const cmMakefile *GetMakefile() const {
+      return this->Makefile; };
+  
   ///! Get the GlobalGenerator this is associated with
   cmGlobalGenerator *GetGlobalGenerator() {
     return this->GlobalGenerator; };

Index: cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- cmake.h	12 Jun 2007 14:56:39 -0000	1.81
+++ cmake.h	15 Jun 2007 14:10:24 -0000	1.82
@@ -155,7 +155,10 @@
   cmGlobalGenerator* CreateGlobalGenerator(const char* name);
 
   ///! Return the global generator assigned to this instance of cmake
-  cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; };
+  cmGlobalGenerator* GetGlobalGenerator()     { return this->GlobalGenerator; }
+  ///! Return the global generator assigned to this instance of cmake, const
+  const cmGlobalGenerator* GetGlobalGenerator() const 
+                                              { return this->GlobalGenerator; }
 
   ///! Return the global generator assigned to this instance of cmake
   void SetGlobalGenerator(cmGlobalGenerator *);
@@ -284,7 +287,7 @@
    */
   const char* GetCTestCommand();
   const char* GetCPackCommand();
-  const char* GetCMakeCommand() { return this->CMakeCommand.c_str(); }
+  const char* GetCMakeCommand() const { return this->CMakeCommand.c_str(); }
 
   // Do we want debug output during the cmake run.
   bool GetDebugOutput() { return this->DebugOutput; }
@@ -354,13 +357,15 @@
   //macros.
   void CleanupCommandsAndMacros();
 
-  void GenerateGraphViz(const char* fileName);
+  void GenerateGraphViz(const char* fileName) const;
 
   static int ExecuteEchoColor(std::vector<std::string>& args);
   static int ExecuteLinkScript(std::vector<std::string>& args);
   
   cmVariableWatch* VariableWatch;
   
+  ///! Find the full path to one of the cmake programs like ctest, cpack, etc.
+  std::string FindCMakeProgram(const char* name) const;
 private:
   ProgressCallbackType ProgressCallback;
   void* ProgressCallbackClientData;

Index: cmGlobalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalGenerator.h,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- cmGlobalGenerator.h	11 Jun 2007 19:31:42 -0000	1.80
+++ cmGlobalGenerator.h	15 Jun 2007 14:10:24 -0000	1.81
@@ -117,10 +117,8 @@
   cmake *GetCMakeInstance() { return this->CMakeInstance; };
 
   void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;}
-  cmLocalGenerator* GetLocalGenerator(int p) { 
-    return this->LocalGenerators[p];}
-  void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) { 
-    g = this->LocalGenerators;}
+  const std::vector<cmLocalGenerator *>& GetLocalGenerators() const { 
+    return this->LocalGenerators;}
 
   void AddLocalGenerator(cmLocalGenerator *lg);
 

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.297
retrieving revision 1.298
diff -u -d -r1.297 -r1.298
--- cmake.cxx	12 Jun 2007 14:56:39 -0000	1.297
+++ cmake.cxx	15 Jun 2007 14:10:24 -0000	1.298
@@ -2402,47 +2402,52 @@
   return s;
 }
 
-const char* cmake::GetCTestCommand()
+std::string cmake::FindCMakeProgram(const char* name) const
 {
-  if ( !this->CTestCommand.empty() )
+  std::string path;
+  if ((name) && (*name))
     {
-    return this->CTestCommand.c_str();
-    }
-
-  cmMakefile* mf
-    = this->GetGlobalGenerator()->GetLocalGenerator(0)->GetMakefile();
+    const cmMakefile* mf
+        = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile();
 #ifdef CMAKE_BUILD_WITH_CMAKE
-  this->CTestCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
-  this->CTestCommand = removeQuotes(this->CTestCommand);
-  this->CTestCommand = 
-    cmSystemTools::GetFilenamePath(this->CTestCommand.c_str());
-  this->CTestCommand += "/";
-  this->CTestCommand += "ctest";
-  this->CTestCommand += cmSystemTools::GetExecutableExtension();
-  if(!cmSystemTools::FileExists(this->CTestCommand.c_str()))
+    path = mf->GetRequiredDefinition("CMAKE_COMMAND");
+    path = removeQuotes(path);
+    path = cmSystemTools::GetFilenamePath(path.c_str());
+    path += "/";
+    path += name;
+    path += cmSystemTools::GetExecutableExtension();
+    if(!cmSystemTools::FileExists(path.c_str()))
     {
-    this->CTestCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
-    this->CTestCommand = 
-      cmSystemTools::GetFilenamePath(this->CTestCommand.c_str());
-    this->CTestCommand += "/Debug/";
-    this->CTestCommand += "ctest";
-    this->CTestCommand += cmSystemTools::GetExecutableExtension();
+      path = mf->GetRequiredDefinition("CMAKE_COMMAND");
+      path = cmSystemTools::GetFilenamePath(path.c_str());
+      path += "/Debug/";
+      path += name;
+      path += cmSystemTools::GetExecutableExtension();
     }
-  if(!cmSystemTools::FileExists(this->CTestCommand.c_str()))
+    if(!cmSystemTools::FileExists(path.c_str()))
     {
-    this->CTestCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
-    this->CTestCommand = 
-      cmSystemTools::GetFilenamePath(this->CTestCommand.c_str());
-    this->CTestCommand += "/Release/";
-    this->CTestCommand += "ctest";
-    this->CTestCommand += cmSystemTools::GetExecutableExtension();
+      path = mf->GetRequiredDefinition("CMAKE_COMMAND");
+      path = cmSystemTools::GetFilenamePath(path.c_str());
+      path += "/Release/";
+      path += name;
+      path += cmSystemTools::GetExecutableExtension();
     }
 #else
-  // Only for bootstrap
-  this->CTestCommand += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
-  this->CTestCommand += "/ctest";
-  this->CTestCommand += cmSystemTools::GetExecutableExtension();
+    // Only for bootstrap
+    path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
+    path += name;
+    path += cmSystemTools::GetExecutableExtension();
 #endif
+    }
+  return path;
+}
+
+const char* cmake::GetCTestCommand()
+{
+  if ( this->CTestCommand.empty() )
+    {
+    this->CTestCommand = this->FindCMakeProgram("ctest");
+    }
   if ( this->CTestCommand.empty() )
     {
     cmSystemTools::Error("Cannot find the CTest executable");
@@ -2453,55 +2458,19 @@
 
 const char* cmake::GetCPackCommand()
 {
-  if ( !this->CPackCommand.empty() )
-    {
-    return this->CPackCommand.c_str();
-    }
-
-  cmMakefile* mf
-    = this->GetGlobalGenerator()->GetLocalGenerator(0)->GetMakefile();
-
-#ifdef CMAKE_BUILD_WITH_CMAKE
-  this->CPackCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
-  this->CPackCommand = removeQuotes(this->CPackCommand);
-  this->CPackCommand = 
-    cmSystemTools::GetFilenamePath(this->CPackCommand.c_str());
-  this->CPackCommand += "/";
-  this->CPackCommand += "cpack";
-  this->CPackCommand += cmSystemTools::GetExecutableExtension();
-  if(!cmSystemTools::FileExists(this->CPackCommand.c_str()))
-    {
-    this->CPackCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
-    this->CPackCommand = 
-      cmSystemTools::GetFilenamePath(this->CPackCommand.c_str());
-    this->CPackCommand += "/Debug/";
-    this->CPackCommand += "cpack";
-    this->CPackCommand += cmSystemTools::GetExecutableExtension();
-    }
-  if(!cmSystemTools::FileExists(this->CPackCommand.c_str()))
+  if ( this->CPackCommand.empty() )
     {
-    this->CPackCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
-    this->CPackCommand = 
-      cmSystemTools::GetFilenamePath(this->CPackCommand.c_str());
-    this->CPackCommand += "/Release/";
-    this->CPackCommand += "cpack";
-    this->CPackCommand += cmSystemTools::GetExecutableExtension();
+    this->CPackCommand = this->FindCMakeProgram("cpack");
     }
-  if (!cmSystemTools::FileExists(this->CPackCommand.c_str()))
+  if ( this->CPackCommand.empty() )
     {
     cmSystemTools::Error("Cannot find the CPack executable");
     this->CPackCommand = "CPACK-COMMAND-NOT-FOUND";
     }
-#else
-  // Only for bootstrap
-  this->CPackCommand += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
-  this->CPackCommand += "/cpack";
-  this->CPackCommand += cmSystemTools::GetExecutableExtension();
-#endif
-  return this->CPackCommand.c_str();
+    return this->CPackCommand.c_str();
 }
 
-void cmake::GenerateGraphViz(const char* fileName)
+void cmake::GenerateGraphViz(const char* fileName) const
 {
   cmGeneratedFileStream str(fileName);
   if ( !str )
@@ -2568,23 +2537,23 @@
   str << graphType << " " << graphName << " {" << std::endl;
   str << graphHeader << std::endl;
 
-  cmGlobalGenerator* gg = this->GetGlobalGenerator();
-  std::vector<cmLocalGenerator*> localGenerators;
-  gg->GetLocalGenerators(localGenerators);
-  std::vector<cmLocalGenerator*>::iterator lit;
+  const cmGlobalGenerator* gg = this->GetGlobalGenerator();
+  const std::vector<cmLocalGenerator*>& localGenerators = 
+      gg->GetLocalGenerators();
+  std::vector<cmLocalGenerator*>::const_iterator lit;
   // for target deps
   // 1 - cmake target
   // 2 - external target
   // 0 - no deps
   std::map<cmStdString, int> targetDeps;
-  std::map<cmStdString, cmTarget*> targetPtrs;
+  std::map<cmStdString, const cmTarget*> targetPtrs;
   std::map<cmStdString, cmStdString> targetNamesNodes;
   int cnt = 0;
   // First pass get the list of all cmake targets
   for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit )
     {
-    cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
-    cmTargets::iterator tit;
+    const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
+    cmTargets::const_iterator tit;
     for ( tit = targets->begin(); tit != targets->end(); ++ tit )
       {
       const char* realTargetName = tit->first.c_str();
@@ -2603,8 +2572,8 @@
   // Ok, now find all the stuff we link to that is not in cmake
   for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit )
     {
-    cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
-    cmTargets::iterator tit;
+    const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
+    cmTargets::const_iterator tit;
     for ( tit = targets->begin(); tit != targets->end(); ++ tit )
       {
       const cmTarget::LinkLibraryVectorType* ll
@@ -2623,7 +2592,7 @@
       for ( llit = ll->begin(); llit != ll->end(); ++ llit )
         {
         const char* libName = llit->first.c_str();
-        std::map<cmStdString, cmStdString>::iterator tarIt
+        std::map<cmStdString, cmStdString>::const_iterator tarIt
           = targetNamesNodes.find(libName);
         if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() )
           {
@@ -2641,7 +2610,7 @@
           }
         else
           {
-          std::map<cmStdString, int>::iterator depIt
+          std::map<cmStdString, int>::const_iterator depIt
             = targetDeps.find(libName);
           if ( depIt == targetDeps.end() )
             {
@@ -2653,11 +2622,11 @@
     }
 
   // Write out nodes
-  std::map<cmStdString, int>::iterator depIt;
+  std::map<cmStdString, int>::const_iterator depIt;
   for ( depIt = targetDeps.begin(); depIt != targetDeps.end(); ++ depIt )
     {
     const char* newTargetName = depIt->first.c_str();
-    std::map<cmStdString, cmStdString>::iterator tarIt
+    std::map<cmStdString, cmStdString>::const_iterator tarIt
       = targetNamesNodes.find(newTargetName);
     if ( tarIt == targetNamesNodes.end() )
       {
@@ -2671,8 +2640,8 @@
       << newTargetName <<  "\" shape=\"";
     if ( depIt->second == 1 )
       {
-      std::map<cmStdString, cmTarget*>::iterator tarTypeIt= targetPtrs.find(
-        newTargetName);
+      std::map<cmStdString, const cmTarget*>::const_iterator tarTypeIt = 
+                                                targetPtrs.find(newTargetName);
       if ( tarTypeIt == targetPtrs.end() )
         {
         // We should not be here.
@@ -2680,7 +2649,7 @@
           << " even though it was added in the previous pass" << std::endl;
         abort();
         }
-      cmTarget* tg = tarTypeIt->second;
+      const cmTarget* tg = tarTypeIt->second;
       switch ( tg->GetType() )
         {
       case cmTarget::EXECUTABLE:
@@ -2709,8 +2678,8 @@
   // Now generate the connectivity
   for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit )
     {
-    cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
-    cmTargets::iterator tit;
+    const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
+    cmTargets::const_iterator tit;
     for ( tit = targets->begin(); tit != targets->end(); ++ tit )
       {
       std::map<cmStdString, int>::iterator dependIt
@@ -2727,7 +2696,7 @@
       for ( llit = ll->begin(); llit != ll->end(); ++ llit )
         {
         const char* libName = llit->first.c_str();
-        std::map<cmStdString, cmStdString>::iterator tarIt
+        std::map<cmStdString, cmStdString>::const_iterator tarIt
           = targetNamesNodes.find(libName);
         if ( tarIt == targetNamesNodes.end() )
           {

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -d -r1.206 -r1.207
--- cmMakefile.h	11 Jun 2007 14:25:40 -0000	1.206
+++ cmMakefile.h	15 Jun 2007 14:10:24 -0000	1.207
@@ -418,6 +418,10 @@
    * Get the list of targets
    */
   cmTargets &GetTargets() { return this->Targets; }
+  /**
+   * Get the list of targets, const version
+   */
+  const cmTargets &GetTargets() const { return this->Targets; }
   const cmTargets &GetImportedTargets() const { return this->ImportedTargets; }
 
   cmTarget* FindTarget(const char* name, bool useImportedTargets);

Index: cmTarget.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.h,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- cmTarget.h	28 May 2007 14:25:03 -0000	1.86
+++ cmTarget.h	15 Jun 2007 14:10:24 -0000	1.87
@@ -102,9 +102,9 @@
   typedef std::pair<cmStdString, LinkLibraryType> LibraryID;
 
   typedef std::vector<LibraryID > LinkLibraryVectorType;
-  const LinkLibraryVectorType &GetLinkLibraries() {
+  const LinkLibraryVectorType &GetLinkLibraries() const {
     return this->LinkLibraries;}
-  const LinkLibraryVectorType &GetOriginalLinkLibraries() 
+  const LinkLibraryVectorType &GetOriginalLinkLibraries() const
     {return this->OriginalLinkLibraries;}
   
   /**

Index: cmExportLibraryDependencies.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExportLibraryDependencies.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmExportLibraryDependencies.cxx	7 Jun 2007 12:29:15 -0000	1.17
+++ cmExportLibraryDependencies.cxx	15 Jun 2007 14:10:24 -0000	1.18
@@ -32,38 +32,40 @@
     }
   
   // store the arguments for the final pass
-  // also expand any CMake variables
-
-  this->Args = args;
+  this->Filename = args[0];
+  this->Append = false;
+  if(args.size() > 1)
+    {
+    if(args[1] == "APPEND")
+      {
+      this->Append = true;
+      }
+    }
   return true;
 }
 
 
 void cmExportLibraryDependenciesCommand::FinalPass()
 {
-  // Create a full path filename for output
-  std::string fname = this->Args[0];
-  bool append = false;
-  if(this->Args.size() > 1)
-    {
-    if(this->Args[1] == "APPEND")
-      {
-      append = true;
-      }
-    }
+  // export_library_dependencies() shouldn't modify anything
+  // ensure this by calling a const method
+  this->ConstFinalPass();
+}
 
+void cmExportLibraryDependenciesCommand::ConstFinalPass() const
+{
   // Use copy-if-different if not appending.
   cmsys::auto_ptr<std::ofstream> foutPtr;
-  if(append)
+  if(this->Append)
     {
     cmsys::auto_ptr<std::ofstream> ap(
-      new std::ofstream(fname.c_str(), std::ios::app));
+      new std::ofstream(this->Filename.c_str(), std::ios::app));
     foutPtr = ap;
     }
   else
     {
     cmsys::auto_ptr<cmGeneratedFileStream> ap(
-      new cmGeneratedFileStream(fname.c_str(), true));
+      new cmGeneratedFileStream(this->Filename.c_str(), true));
     ap->SetCopyIfDifferent(true);
     foutPtr = ap;
     }
@@ -71,23 +73,22 @@
 
   if (!fout)
     {
-    cmSystemTools::Error("Error Writing ", fname.c_str());
+    cmSystemTools::Error("Error Writing ", this->Filename.c_str());
     cmSystemTools::ReportLastSystemError("");
     return;
     }
-  cmake* cm = this->Makefile->GetCMakeInstance();
-  cmGlobalGenerator* global = cm->GetGlobalGenerator();
-  std::vector<cmLocalGenerator *> locals;
-  global->GetLocalGenerators(locals);
+  const cmake* cm = this->Makefile->GetCMakeInstance();
+  const cmGlobalGenerator* global = cm->GetGlobalGenerator();
+  const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators();
   std::string libDepName;
-  for(std::vector<cmLocalGenerator *>::iterator i = locals.begin();
+  for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin();
       i != locals.end(); ++i)
     {
-    cmLocalGenerator* gen = *i;
-    cmTargets &tgts = gen->GetMakefile()->GetTargets();  
+    const cmLocalGenerator* gen = *i;
+    const cmTargets &tgts = gen->GetMakefile()->GetTargets();  
     std::vector<std::string> depends;
     const char *defType;
-    for(cmTargets::iterator l = tgts.begin();
+    for(cmTargets::const_iterator l = tgts.begin();
         l != tgts.end(); ++l)
       {
       libDepName = l->first;

Index: cmExportLibraryDependencies.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmExportLibraryDependencies.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmExportLibraryDependencies.h	10 May 2006 19:08:38 -0000	1.5
+++ cmExportLibraryDependencies.h	15 Jun 2007 14:10:24 -0000	1.6
@@ -81,7 +81,9 @@
   cmTypeMacro(cmExportLibraryDependenciesCommand, cmCommand);
 
 private:
-  std::vector<std::string> Args;
+  std::string Filename;
+  bool Append;
+  void ConstFinalPass() const;
 };
 
 



More information about the Cmake-commits mailing list