[cmake-commits] alex committed cmCPackGenericGenerator.cxx 1.45 1.46 cmCPackGenericGenerator.h 1.18 1.19 cmCPackZIPGenerator.cxx 1.8 1.9 cmCPackZIPGenerator.h 1.4 1.5

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Jul 24 12:52:41 EDT 2007


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

Modified Files:
	cmCPackGenericGenerator.cxx cmCPackGenericGenerator.h 
	cmCPackZIPGenerator.cxx cmCPackZIPGenerator.h 
Log Message:

ENH: add ReadListFile() to cmCPackGenericGenerator, so cmMakefile can be
private again
-convert the ZIP generator to use a cmake script instead of hardcoding
everything (CPackZIP.cmake)

Alex


Index: cmCPackZIPGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackZIPGenerator.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cmCPackZIPGenerator.cxx	14 Jun 2007 17:57:00 -0000	1.8
+++ cmCPackZIPGenerator.cxx	24 Jul 2007 16:52:37 -0000	1.9
@@ -17,11 +17,7 @@
 
 #include "cmCPackZIPGenerator.h"
 
-#include "cmake.h"
-#include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
 #include "cmSystemTools.h"
-#include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
 #include "cmCPackLog.h"
 
@@ -41,67 +37,14 @@
 int cmCPackZIPGenerator::InitializeInternal()
 {
   this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
-  std::vector<std::string> path;
-  std::string pkgPath = "c:/Program Files/WinZip";
-  path.push_back(pkgPath);
-  pkgPath = cmSystemTools::FindProgram("wzzip", path, false);
-  this->ZipStyle = cmCPackZIPGenerator::StyleUnkown;
-  bool found = false;
-  if ( pkgPath.empty() )
-    {
-    cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find WinZip" << std::endl);
-    }
-  else
-    {
-    this->ZipStyle = cmCPackZIPGenerator::StyleWinZip;
-    found = true;
-    }
-
-  if ( !found )
-    {
-    pkgPath = "c:/Program Files/7-Zip";
-    path.push_back(pkgPath);
-    pkgPath = cmSystemTools::FindProgram("7z", path, false);
-
-    if ( pkgPath.empty() )
-      {
-      cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find 7ZIP"
-        << std::endl);
-      }
-    else
-      {
-      this->ZipStyle = cmCPackZIPGenerator::Style7Zip;
-      found = true;
-      }
-    }
-
-  if ( !found )
-    {
-    path.erase(path.begin(), path.end());
-    pkgPath = "c:/cygwin/bin";
-    path.push_back(pkgPath);
-    pkgPath = cmSystemTools::FindProgram("zip", path, false);
-    if ( pkgPath.empty() )
-      {
-      cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP"
-        << std::endl);
-      }
-    else
-      {
-      this->ZipStyle = cmCPackZIPGenerator::StyleUnixZip;
-      found = true;
-      }
-    }
-  if ( !found )
+  this->ReadListFile("CPackZIP.cmake");
+  if ((!this->IsSet("ZIP_EXECUTABLE")) 
+      || (!this->IsSet("CPACK_ZIP_COMMAND")))
     {
     cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a suitable ZIP program"
       << std::endl);
     return 0;
     }
-  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
-  cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: "
-    << pkgPath.c_str()
-    << std::endl);
   return this->Superclass::InitializeInternal();
 }
 
@@ -112,75 +55,46 @@
   std::string tempFileName;
   tempFileName = toplevel;
   tempFileName += "/winZip.filelist";
-  bool needQuotesInFile = false;
-  cmOStringStream dmgCmd;
-  switch ( this->ZipStyle )
-    {
-  case cmCPackZIPGenerator::StyleWinZip:
-    dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
-           << "\" -P \"" << outFileName
-           << "\" @winZip.filelist";
-    needQuotesInFile = true;
-    break;
-  case cmCPackZIPGenerator::Style7Zip:
-    // this is the zip generator, so tell 7zip to generate zip files
-    dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
-           << "\" a -tzip \"" << outFileName
-           << "\" @winZip.filelist";
-    needQuotesInFile = true;
-    break;
-  case cmCPackZIPGenerator::StyleUnixZip:
-    dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
-      << "\" -r \"" << outFileName
-      << "\" . -i at winZip.filelist";
-    break;
-  default:
-    cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style"
-      << std::endl);
-    return 0;
-    }
-  if(tempFileName.size())
+  bool needQuotesInFile = cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES"));
+
+  std::string cmd = this->GetOption("CPACK_ZIP_COMMAND");
+  cmsys::SystemTools::ReplaceString(cmd, "<ARCHIVE>", outFileName);
+  cmsys::SystemTools::ReplaceString(cmd, "<FILELIST>", "winZip.filelist");
+
+  { // the scope is needed for cmGeneratedFileStream
+  cmGeneratedFileStream out(tempFileName.c_str());
+  std::vector<std::string>::const_iterator fileIt;
+  for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
     {
-    cmGeneratedFileStream out(tempFileName.c_str());
-    std::vector<std::string>::const_iterator fileIt;
-    for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
+    if ( needQuotesInFile )
       {
-      if ( needQuotesInFile )
-        {
-        out << "\"";
-        }
-      out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
-      if ( needQuotesInFile )
-        {
-        out << "\"";
-        }
-      out << std::endl;
+      out << "\"";
       }
-    }
-  else
-    {
-    std::vector<std::string>::const_iterator fileIt;
-    for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
+    out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
+    if ( needQuotesInFile )
       {
-      dmgCmd << " \""
-             << cmSystemTools::RelativePath(toplevel, fileIt->c_str())
-             << "\"";
+      out << "\"";
       }
+    out << std::endl;
     }
+  }
+
+
   std::string output;
   int retVal = -1;
-  int res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
+  int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
     &retVal, toplevel, this->GeneratorVerbose, 0);
+
   if ( !res || retVal )
     {
     std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
     tmpFile += "/CompressZip.log";
     cmGeneratedFileStream ofs(tmpFile.c_str());
-    ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
+    ofs << "# Run command: " << cmd.c_str() << std::endl
       << "# Output:" << std::endl
       << output.c_str() << std::endl;
     cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
-      << dmgCmd.str().c_str() << std::endl
+      << cmd.c_str() << std::endl
       << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
     return 0;
     }

Index: cmCPackZIPGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackZIPGenerator.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cmCPackZIPGenerator.h	14 Jun 2007 16:03:53 -0000	1.4
+++ cmCPackZIPGenerator.h	24 Jul 2007 16:52:37 -0000	1.5
@@ -37,14 +37,6 @@
   cmCPackZIPGenerator();
   virtual ~cmCPackZIPGenerator();
 
-  enum ZipStyles
-    {
-    StyleUnkown,
-    StyleWinZip,
-    StyleUnixZip,
-    Style7Zip
-    };
-
 protected:
   virtual int InitializeInternal();
   int CompressFiles(const char* outFileName, const char* toplevel,

Index: cmCPackGenericGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackGenericGenerator.cxx,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- cmCPackGenericGenerator.cxx	24 Jul 2007 14:00:26 -0000	1.45
+++ cmCPackGenericGenerator.cxx	24 Jul 2007 16:52:37 -0000	1.46
@@ -32,14 +32,14 @@
 cmCPackGenericGenerator::cmCPackGenericGenerator()
 {
   this->GeneratorVerbose = false;
-  this->Makefile = 0;
+  this->MakefileMap = 0;
   this->Logger = 0;
 }
 
 //----------------------------------------------------------------------
 cmCPackGenericGenerator::~cmCPackGenericGenerator()
 {
-  this->Makefile = 0;
+  this->MakefileMap = 0;
 }
 
 //----------------------------------------------------------------------
@@ -392,7 +392,7 @@
         tempInstallDirectory);
       this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
         tempInstallDirectory);
-      int res = this->Makefile->ReadListFile(0, installScript.c_str());
+      int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
       if ( cmSystemTools::GetErrorOccuredFlag() || !res )
         {
         return 0;
@@ -454,7 +454,7 @@
 
       const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
       cmGlobalGenerator* globalGenerator
-        = this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
+        = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
           cmakeGenerator);
       // set the global flag for unix style paths on cmSystemTools as
       // soon as the generator is set.  This allows gmake to be used
@@ -464,9 +464,9 @@
       // Does this generator require pre-install?
       if ( globalGenerator->GetPreinstallTargetName() )
         {
-        globalGenerator->FindMakeProgram(this->Makefile);
+        globalGenerator->FindMakeProgram(this->MakefileMap);
         const char* cmakeMakeProgram
-          = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
+          = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
         std::string buildCommand
           = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
             installProjectName.c_str(), 0,
@@ -551,10 +551,17 @@
 }
 
 //----------------------------------------------------------------------
+bool cmCPackGenericGenerator::ReadListFile(const char* moduleName)
+{
+  std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
+  return this->MakefileMap->ReadListFile(0, fullPath.c_str());
+}
+
+//----------------------------------------------------------------------
 void cmCPackGenericGenerator::SetOptionIfNotSet(const char* op,
   const char* value)
 {
-  const char* def = this->Makefile->GetDefinition(op);
+  const char* def = this->MakefileMap->GetDefinition(op);
   if ( def && *def )
     {
     return;
@@ -571,12 +578,12 @@
     }
   if ( !value )
     {
-    this->Makefile->RemoveDefinition(op);
+    this->MakefileMap->RemoveDefinition(op);
     return;
     }
   cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
     << "::SetOption(" << op << ", " << value << ")" << std::endl);
-  this->Makefile->AddDefinition(op, value);
+  this->MakefileMap->AddDefinition(op, value);
 }
 
 //----------------------------------------------------------------------
@@ -680,7 +687,7 @@
 int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf,
  const char* argv0)
 {
-  this->Makefile = mf;
+  this->MakefileMap = mf;
   this->Name = name;
   if ( !this->FindRunningCMake(argv0) )
     {
@@ -698,9 +705,15 @@
 }
 
 //----------------------------------------------------------------------
+bool cmCPackGenericGenerator::IsSet(const char* name) const
+{
+  return this->MakefileMap->IsSet(name);
+}
+
+//----------------------------------------------------------------------
 const char* cmCPackGenericGenerator::GetOption(const char* op)
 {
-  return this->Makefile->GetDefinition(op);
+  return this->MakefileMap->GetDefinition(op);
 }
 
 //----------------------------------------------------------------------
@@ -913,7 +926,7 @@
 {
   cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
     << (name ? name : "(NULL)") << std::endl);
-  std::string ffile = this->Makefile->GetModulesFile(name);
+  std::string ffile = this->MakefileMap->GetModulesFile(name);
   cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
     << ffile.c_str() << std::endl);
   return ffile;
@@ -923,7 +936,7 @@
 bool cmCPackGenericGenerator::ConfigureString(const std::string& inString,
   std::string& outString)
 {
-  this->Makefile->ConfigureString(inString,
+  this->MakefileMap->ConfigureString(inString,
     outString, true, false);
   return true;
 }
@@ -932,7 +945,7 @@
 bool cmCPackGenericGenerator::ConfigureFile(const char* inName,
   const char* outName, bool copyOnly /* = false */)
 {
-  return this->Makefile->ConfigureFile(inName, outName,
+  return this->MakefileMap->ConfigureFile(inName, outName,
     copyOnly, true, false) == 1;
 }
 

Index: cmCPackGenericGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackGenericGenerator.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- cmCPackGenericGenerator.h	24 Jul 2007 14:00:26 -0000	1.18
+++ cmCPackGenericGenerator.h	24 Jul 2007 16:52:37 -0000	1.19
@@ -80,6 +80,7 @@
   void SetOption(const char* op, const char* value);
   void SetOptionIfNotSet(const char* op, const char* value);
   const char* GetOption(const char* op);
+  bool IsSet(const char* name) const;
 
   //! Set all the variables
   int FindRunningCMake(const char* arg0);
@@ -89,6 +90,8 @@
 
   //! Display verbose information via logger
   void DisplayVerboseOutput(const char* msg, float progress);
+  
+  bool ReadListFile(const char* moduleName);
 
 protected:
   int PrepareNames();
@@ -129,8 +132,8 @@
   std::string CMakeRoot;
 
   cmCPackLog* Logger;
-
-  cmMakefile* Makefile;
+private:
+  cmMakefile* MakefileMap;
 };
 
 #endif



More information about the Cmake-commits mailing list