[cmake-commits] king committed cmCTest.cxx 1.329 1.330 cmCTest.h 1.98 1.99 cmDumpDocumentation.cxx 1.19 1.20 cmSystemTools.cxx 1.355 1.356 cmSystemTools.h 1.142 1.143 cmake.cxx 1.338 1.339 cmake.h 1.96 1.97 cmakemain.cxx 1.75 1.76 ctest.cxx 1.99 1.100

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Dec 13 17:56:51 EST 2007


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

Modified Files:
	cmCTest.cxx cmCTest.h cmDumpDocumentation.cxx 
	cmSystemTools.cxx cmSystemTools.h cmake.cxx cmake.h 
	cmakemain.cxx ctest.cxx 
Log Message:
ENH: Centralized and globalized computation of CMake program locations.  This eliminates startup paths that failed to produce this information.


Index: cmSystemTools.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.h,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -d -r1.142 -r1.143
--- cmSystemTools.h	5 Oct 2007 13:46:28 -0000	1.142
+++ cmSystemTools.h	13 Dec 2007 22:56:49 -0000	1.143
@@ -350,6 +350,14 @@
       the first argument to that named by the second.  */
   static bool CopyFileTime(const char* fromFile, const char* toFile);
 
+  /** Find the directory containing the running executable.  Save it
+   in a global location to be queried by GetExecutableDirectory
+   later.  */
+  static void FindExecutableDirectory(const char* argv0);
+
+  /** Get the directory containing the currently running executable.  */
+  static const char* GetExecutableDirectory();
+
 private:
   static bool s_ForceUnixPaths;
   static bool s_RunCommandHideConsole;

Index: cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- cmake.h	13 Dec 2007 20:54:29 -0000	1.96
+++ cmake.h	13 Dec 2007 22:56:49 -0000	1.97
@@ -288,7 +288,7 @@
   /**
    * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
    */
-  int AddCMakePaths(const char *arg0);
+  int AddCMakePaths();
 
   /**
    * Get the file comparison class

Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.355
retrieving revision 1.356
diff -u -d -r1.355 -r1.356
--- cmSystemTools.cxx	8 Oct 2007 14:05:42 -0000	1.355
+++ cmSystemTools.cxx	13 Dec 2007 22:56:49 -0000	1.356
@@ -2064,3 +2064,26 @@
 #endif
   return true;
 }
+
+//----------------------------------------------------------------------------
+static std::string cmSystemToolsExecutableDirectory;
+void cmSystemTools::FindExecutableDirectory(const char* argv0)
+{
+  std::string errorMsg;
+  std::string exe;
+  if(cmSystemTools::FindProgramPath(argv0, exe, errorMsg))
+    {
+    cmSystemToolsExecutableDirectory =
+      cmSystemTools::GetFilenamePath(exe.c_str());
+    }
+  else
+    {
+    // ???
+    }
+}
+
+//----------------------------------------------------------------------------
+const char* cmSystemTools::GetExecutableDirectory()
+{
+  return cmSystemToolsExecutableDirectory.c_str();
+}

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.338
retrieving revision 1.339
diff -u -d -r1.338 -r1.339
--- cmake.cxx	13 Dec 2007 22:39:53 -0000	1.338
+++ cmake.cxx	13 Dec 2007 22:56:49 -0000	1.339
@@ -739,56 +739,16 @@
 
 // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
 // cache
-int cmake::AddCMakePaths(const char *arg0)
+int cmake::AddCMakePaths()
 {
   // Find the cmake executable
-  std::vector<cmStdString> failures;
-  std::string cMakeSelf = arg0;
-  cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
-  if ((strstr(arg0, "cpack")!=0) || (strstr(arg0, "ctest")!=0))
-    {
-    // when called from cpack or ctest CMAKE_COMMAND would otherwise point
-    // to cpack or ctest and not cmake
-    cMakeSelf = cmSystemTools::GetFilenamePath(cMakeSelf) +
-      "/cmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
-    }
-  failures.push_back(cMakeSelf);
-  cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
-  cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
-  if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
-    {
-#ifdef CMAKE_BUILD_DIR
-  std::string intdir = ".";
-#ifdef  CMAKE_INTDIR
-  intdir = CMAKE_INTDIR;
-#endif
-  cMakeSelf = CMAKE_BUILD_DIR;
-  cMakeSelf += "/bin/";
-  cMakeSelf += intdir;
+  std::string cMakeSelf = cmSystemTools::GetExecutableDirectory();
   cMakeSelf += "/cmake";
   cMakeSelf += cmSystemTools::GetExecutableExtension();
-#endif
-    }
-#ifdef CMAKE_PREFIX
-  if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
-    {
-    failures.push_back(cMakeSelf);
-    cMakeSelf = CMAKE_PREFIX "/bin/cmake";
-    }
-#endif
   if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
     {
-    failures.push_back(cMakeSelf);
-    cmOStringStream msg;
-    msg << "CMAKE can not find the command line program cmake.\n";
-    msg << "  argv[0] = \"" << arg0 << "\"\n";
-    msg << "  Attempted paths:\n";
-    std::vector<cmStdString>::iterator i;
-    for(i=failures.begin(); i != failures.end(); ++i)
-      {
-      msg << "    \"" << i->c_str() << "\"\n";
-      }
-    cmSystemTools::Error(msg.str().c_str());
+    cmSystemTools::Error("CMake executable cannot be found at ",
+                         cMakeSelf.c_str());
     return 0;
     }
   // Save the value in the cache
@@ -2157,7 +2117,7 @@
     }
   else
     {
-    this->AddCMakePaths(this->CMakeCommand.c_str());
+    this->AddCMakePaths();
     }
 
   // Add any cache args
@@ -2376,7 +2336,7 @@
     }
 
   // setup CMAKE_ROOT and CMAKE_COMMAND
-  if(!this->AddCMakePaths(this->CMakeCommand.c_str()))
+  if(!this->AddCMakePaths())
     {
     return -3;
     }
@@ -3503,7 +3463,7 @@
 
 
   // we have to find the module directory, so we can copy the files
-  this->AddCMakePaths(args[0].c_str());
+  this->AddCMakePaths();
   std::string modulesPath = 
     this->CacheManager->GetCacheValue("CMAKE_ROOT");
   modulesPath += "/Modules";

Index: cmCTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.cxx,v
retrieving revision 1.329
retrieving revision 1.330
diff -u -d -r1.329 -r1.330
--- cmCTest.cxx	21 Nov 2007 15:07:00 -0000	1.329
+++ cmCTest.cxx	13 Dec 2007 22:56:49 -0000	1.330
@@ -1774,7 +1774,7 @@
 // the main entry point of ctest, called from main
 int cmCTest::Run(std::vector<std::string> &args, std::string* output)
 {
-  this->FindRunningCMake(args[0].c_str());
+  this->FindRunningCMake();
   const char* ctestExec = "ctest";
   bool cmakeAndTest = false;
   bool performSomeTest = true;
@@ -1970,70 +1970,25 @@
 }
 
 //----------------------------------------------------------------------
-void cmCTest::FindRunningCMake(const char* arg0)
+void cmCTest::FindRunningCMake()
 {
   // Find our own executable.
-  std::vector<cmStdString> failures;
-  this->CTestSelf = arg0;
-  cmSystemTools::ConvertToUnixSlashes(this->CTestSelf);
-  failures.push_back(this->CTestSelf);
-  this->CTestSelf = cmSystemTools::FindProgram(this->CTestSelf.c_str());
-  if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
-    {
-    failures.push_back(this->CTestSelf);
-    this->CTestSelf =  "/usr/local/bin/ctest";
-    }
+  this->CTestSelf = cmSystemTools::GetExecutableDirectory();
+  this->CTestSelf += "/ctest";
+  this->CTestSelf += cmSystemTools::GetExecutableExtension();
   if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
     {
-    failures.push_back(this->CTestSelf);
-    cmOStringStream msg;
-    msg << "CTEST can not find the command line program ctest.\n";
-    msg << "  argv[0] = \"" << arg0 << "\"\n";
-    msg << "  Attempted paths:\n";
-    std::vector<cmStdString>::iterator i;
-    for(i=failures.begin(); i != failures.end(); ++i)
-      {
-      msg << "    \"" << i->c_str() << "\"\n";
-      }
-    cmSystemTools::Error(msg.str().c_str());
-    }
-  std::string dir;
-  std::string file;
-  if(cmSystemTools::SplitProgramPath(this->CTestSelf.c_str(),
-                                     dir, file, true))
-    {
-    this->CMakeSelf = dir += "/cmake";
-    this->CMakeSelf += cmSystemTools::GetExecutableExtension();
-    if(cmSystemTools::FileExists(this->CMakeSelf.c_str()))
-      {
-      return;
-      }
+    cmSystemTools::Error("CTest executable cannot be found at ",
+                         this->CTestSelf.c_str());
     }
-  failures.push_back(this->CMakeSelf);
-#ifdef CMAKE_BUILD_DIR
-  std::string intdir = ".";
-#ifdef  CMAKE_INTDIR
-  intdir = CMAKE_INTDIR;
-#endif
-  this->CMakeSelf = CMAKE_BUILD_DIR;
-  this->CMakeSelf += "/bin/";
-  this->CMakeSelf += intdir;
+
+  this->CMakeSelf = cmSystemTools::GetExecutableDirectory();
   this->CMakeSelf += "/cmake";
   this->CMakeSelf += cmSystemTools::GetExecutableExtension();
-#endif
   if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
     {
-    failures.push_back(this->CMakeSelf);
-    cmOStringStream msg;
-    msg << "CTEST can not find the command line program cmake.\n";
-    msg << "  argv[0] = \"" << arg0 << "\"\n";
-    msg << "  Attempted paths:\n";
-    std::vector<cmStdString>::iterator i;
-    for(i=failures.begin(); i != failures.end(); ++i)
-      {
-      msg << "    \"" << i->c_str() << "\"\n";
-      }
-    cmSystemTools::Error(msg.str().c_str());
+    cmSystemTools::Error("CMake executable cannot be found at ",
+                         this->CMakeSelf.c_str());
     }
 }
 

Index: cmakemain.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmakemain.cxx,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- cmakemain.cxx	13 Dec 2007 20:11:09 -0000	1.75
+++ cmakemain.cxx	13 Dec 2007 22:56:49 -0000	1.76
@@ -273,6 +273,7 @@
 int main(int ac, char** av)
 {
   cmSystemTools::EnableMSVCDebugHook();
+  cmSystemTools::FindExecutableDirectory(av[0]);
   int ret = do_cmake(ac, av);
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmDynamicLoader::FlushCache();
@@ -299,7 +300,7 @@
     { 
     // Construct and print requested documentation.
     cmake hcm;
-    hcm.AddCMakePaths(av[0]);
+    hcm.AddCMakePaths();
     doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
 
     // the command line args are processed here so that you can do 

Index: ctest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/ctest.cxx,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- ctest.cxx	22 Oct 2007 16:48:39 -0000	1.99
+++ ctest.cxx	13 Dec 2007 22:56:49 -0000	1.100
@@ -210,6 +210,7 @@
 {
   cmSystemTools::DoNotInheritStdPipes();
   cmSystemTools::EnableMSVCDebugHook();
+  cmSystemTools::FindExecutableDirectory(argv[0]);
   int nocwd = 0;
   cmCTest inst;
 

Index: cmCTest.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.h,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- cmCTest.h	12 Jun 2007 13:40:36 -0000	1.98
+++ cmCTest.h	13 Dec 2007 22:56:49 -0000	1.99
@@ -398,7 +398,7 @@
     const VectorOfStrings& files);
 
   ///! Find the running cmake
-  void FindRunningCMake(const char* arg0);
+  void FindRunningCMake();
 
   //! Check if the argument is the one specified
   bool CheckArgument(const std::string& arg, const char* varg1,

Index: cmDumpDocumentation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDumpDocumentation.cxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cmDumpDocumentation.cxx	22 Oct 2007 16:48:39 -0000	1.19
+++ cmDumpDocumentation.cxx	13 Dec 2007 22:56:49 -0000	1.20
@@ -121,6 +121,7 @@
 int main(int ac, char** av)
 {
   cmSystemTools::EnableMSVCDebugHook();
+  cmSystemTools::FindExecutableDirectory(av[0]);
   const char* outname = "cmake.html";
   bool coverage = false;
   if(ac > 1)



More information about the Cmake-commits mailing list