[cmake-commits] martink committed CMakeLists.txt 1.343 1.344 cmake.cxx 1.280 1.281 cmake.h 1.75 1.76 cmakemain.cxx 1.56 1.57

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Feb 27 10:10:12 EST 2007


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

Modified Files:
	CMakeLists.txt cmake.cxx cmake.h cmakemain.cxx 
Log Message:
ENH: added --system-information option to CMake


Index: cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- cmake.h	7 Dec 2006 14:44:46 -0000	1.75
+++ cmake.h	27 Feb 2007 15:10:10 -0000	1.76
@@ -189,6 +189,11 @@
    */
   static int ExecuteCMakeCommand(std::vector<std::string>&);
 
+  /** 
+   * Get the system information and write it to the file specified
+   */
+  int GetSystemInformation(std::vector<std::string>&);
+
   /**
    * Add a command to this cmake instance
    */

Index: cmakemain.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmakemain.cxx,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- cmakemain.cxx	7 Dec 2006 14:44:46 -0000	1.56
+++ cmakemain.cxx	27 Feb 2007 15:10:10 -0000	1.57
@@ -83,6 +83,10 @@
   {"--graphviz=[file]", "Generate graphviz of dependencies.",
    "Generate a graphviz input file that will contain all the library and "
    "executable dependencies in the project."},
+  {"--system-information [file]", "Dump information about this system.",
+   "Dump a wide range of information about the current system. If run "
+   "from the top of a binary tree for a CMake project it will dump "
+   "additional information such as the cache, log files etc."},
   {"--debug-trycompile", "Do not delete the try compile directories..",
    "Do not delete the files and directories created for try_compile calls. "
    "This is useful in debugging failed try_compiles."},
@@ -206,6 +210,7 @@
 #endif
   
   bool wiz = false;
+  bool sysinfo = false;
   bool command = false;
   bool list_cached = false;
   bool list_all_cached = false;
@@ -219,6 +224,10 @@
       {
       wiz = true;
       }
+    else if(!command && strcmp(av[i], "--system-information") == 0)
+      {
+      sysinfo = true;
+      }
     // if command has already been set, then
     // do not eat the -E 
     else if (!command && strcmp(av[i], "-E") == 0)
@@ -277,6 +286,12 @@
     cmakewizard wizard;
     return wizard.RunWizard(args); 
     }
+  if (sysinfo)
+    {
+    cmake cm;
+    int ret = cm.GetSystemInformation(args);
+    return ret; 
+    }
   cmake cm;  
   cm.SetProgressCallback(updateProgress, 0);
   cm.SetScriptMode(script_mode);

Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CMakeLists.txt,v
retrieving revision 1.343
retrieving revision 1.344
diff -u -d -r1.343 -r1.344
--- CMakeLists.txt	23 Feb 2007 19:37:23 -0000	1.343
+++ CMakeLists.txt	27 Feb 2007 15:10:10 -0000	1.344
@@ -505,6 +505,11 @@
     --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
     --test-command DumpInformation)
 
+  ADD_TEST(SystemInformationNew 
+    ${CMAKE_CMAKE_COMMAND} -E chdir "${CMake_BINARY_DIR}"
+    ${CMAKE_CMAKE_COMMAND} --system-information
+    )
+
   ADD_TEST(StringFileTest ${CMAKE_CTEST_COMMAND}
     --build-and-test
     "${CMake_SOURCE_DIR}/Tests/StringFileTest"

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -d -r1.280 -r1.281
--- cmake.cxx	22 Feb 2007 14:10:37 -0000	1.280
+++ cmake.cxx	27 Feb 2007 15:10:10 -0000	1.281
@@ -2912,3 +2912,95 @@
 {
   return cmSystemTools::IsOn(this->GetProperty(prop));
 }
+
+int cmake::GetSystemInformation(std::vector<std::string>& args)
+{
+  // we must create a temporary directory, copy some files to it
+  // run cmake on it, and then collect the results.
+  
+  // so create the directory
+  std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+  std::string destPath = cwd + "/__cmake_systeminformation";
+  cmSystemTools::RemoveADirectory(destPath.c_str());
+  if (!cmSystemTools::MakeDirectory(destPath.c_str()))
+    {
+    std::cerr << "Error: --system-information must be run from a "
+      "writable directory!\n";
+    return 1;
+    }
+  
+  // we have to find the module directory, so we can copy the files
+  this->AddCMakePaths(args[0].c_str());
+  std::string modulesPath = 
+    this->CacheManager->GetCacheValue("CMAKE_ROOT");
+  modulesPath += "/Modules";
+  std::string inFile = modulesPath;
+  inFile += "/SystemInformation.cmake";
+  std::string outFile = destPath;
+  outFile += "/CMakeLists.txt";
+  
+  // Copy file
+  if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
+    {
+    std::cerr << "Error copying file \"" << inFile.c_str()
+              << "\" to \"" << outFile.c_str() << "\".\n";
+    return 1;
+    }
+  
+  // do we write to a file or to stdout?
+  std::string resultFile;
+
+  if (args.size() == 1)
+    {
+    resultFile = cwd;
+    resultFile += "__cmake_systeminformation/results.txt";
+    }
+  else
+    {
+    if (!cmSystemTools::FileIsFullPath(args[1].c_str()))
+      {
+      resultFile += cwd;
+      resultFile += "/";
+      }
+    resultFile = args[1];
+    }
+
+  // now run cmake on the CMakeLists file
+  cmSystemTools::ChangeDirectory(destPath.c_str());
+  cmake cm;
+  std::vector<std::string> args2;
+  args2.push_back(args[0]);
+  args2.push_back(destPath);
+  std::string resultArg = "-DRESULT_FILE=";
+  resultArg += resultFile;
+  args2.push_back(resultArg);
+  int res = cm.Run(args2, false);
+  
+  // change back to the original directory
+  cmSystemTools::ChangeDirectory(cwd.c_str());
+  
+  // echo results to stdout if needed
+  if (args.size() == 1)
+    {
+    FILE* fin = fopen(resultFile.c_str(), "r");
+    if(fin)
+      {
+      const int bufferSize = 4096;
+      char buffer[bufferSize];
+      int n;
+      while((n = fread(buffer, 1, bufferSize, fin)) > 0)
+        {
+        for(char* c = buffer; c < buffer+n; ++c)
+          {
+          putc(*c, stdout);
+          }
+        fflush(stdout);
+        }
+      fclose(fin);
+      }
+    }
+  
+  // clean up the directory
+  cmSystemTools::RemoveADirectory(destPath.c_str());
+  return 0;
+}



More information about the Cmake-commits mailing list