summaryrefslogtreecommitdiffstats
path: root/Source/CPack
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2006-04-02 15:20:58 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2006-04-02 15:20:58 (GMT)
commitd342d51c0cc2ab2dc0f1053817a5a98b14a3fcf4 (patch)
tree31ee8a0969c5a3538d178a9dfa207f6fc26838dd /Source/CPack
parentc0fe6aa97af5fa668fecf839e3baaafe4ffc2ad0 (diff)
downloadCMake-d342d51c0cc2ab2dc0f1053817a5a98b14a3fcf4.zip
CMake-d342d51c0cc2ab2dc0f1053817a5a98b14a3fcf4.tar.gz
CMake-d342d51c0cc2ab2dc0f1053817a5a98b14a3fcf4.tar.bz2
ENH: Add ZIP generator and add support for including or excluding the toplevel directory
Diffstat (limited to 'Source/CPack')
-rw-r--r--Source/CPack/cmCPackGenerators.cxx2
-rw-r--r--Source/CPack/cmCPackGenericGenerator.cxx5
-rw-r--r--Source/CPack/cmCPackNSISGenerator.cxx8
-rw-r--r--Source/CPack/cmCPackPackageMakerGenerator.cxx4
-rw-r--r--Source/CPack/cmCPackZIPGenerator.cxx138
-rw-r--r--Source/CPack/cmCPackZIPGenerator.h59
-rw-r--r--Source/CPack/cpack.cxx2
7 files changed, 217 insertions, 1 deletions
diff --git a/Source/CPack/cmCPackGenerators.cxx b/Source/CPack/cmCPackGenerators.cxx
index 7713a00..e120c2b 100644
--- a/Source/CPack/cmCPackGenerators.cxx
+++ b/Source/CPack/cmCPackGenerators.cxx
@@ -19,6 +19,7 @@
#include "cmCPackGenericGenerator.h"
#include "cmCPackTGZGenerator.h"
+#include "cmCPackZIPGenerator.h"
#include "cmCPackSTGZGenerator.h"
#include "cmCPackNSISGenerator.h"
#include "cmCPackPackageMakerGenerator.h"
@@ -31,6 +32,7 @@ cmCPackGenerators::cmCPackGenerators()
this->RegisterGenerator("TGZ", cmCPackTGZGenerator::CreateGenerator);
this->RegisterGenerator("STGZ", cmCPackSTGZGenerator::CreateGenerator);
this->RegisterGenerator("NSIS", cmCPackNSISGenerator::CreateGenerator);
+ this->RegisterGenerator("ZIP", cmCPackZIPGenerator::CreateGenerator);
this->RegisterGenerator("PackageMaker",
cmCPackPackageMakerGenerator::CreateGenerator);
}
diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx
index e32d0f8..f61b70d 100644
--- a/Source/CPack/cmCPackGenericGenerator.cxx
+++ b/Source/CPack/cmCPackGenericGenerator.cxx
@@ -328,6 +328,11 @@ int cmCPackGenericGenerator::ProcessGenerator()
<< std::endl);
cmSystemTools::RemoveFile(tempPackageFileName);
}
+ if ( cmSystemTools::IsOn(this->GetOption(
+ "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
+ {
+ tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ }
if ( !this->CompressFiles(tempPackageFileName,
tempDirectory, gl.GetFiles()) )
{
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
index 6261960..f4afea1 100644
--- a/Source/CPack/cmCPackNSISGenerator.cxx
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -122,6 +122,14 @@ int cmCPackNSISGenerator::Initialize(const char* name, cmMakefile* mf)
{
return res;
}
+ if ( cmSystemTools::IsOn(this->GetOption(
+ "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY. This option will be ignored."
+ << std::endl);
+ this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", 0);
+ }
+
cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()"
<< std::endl);
std::vector<std::string> path;
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx
index dbce2f1..b667415 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.cxx
+++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx
@@ -140,6 +140,10 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName,
int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf)
{
int res = this->Superclass::Initialize(name, mf);
+ if ( !res )
+ {
+ return res;
+ }
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"cmCPackPackageMakerGenerator::Initialize()" << std::endl);
std::vector<std::string> path;
diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx
new file mode 100644
index 0000000..0781991
--- /dev/null
+++ b/Source/CPack/cmCPackZIPGenerator.cxx
@@ -0,0 +1,138 @@
+/*=========================================================================
+
+ Program: CMake - Cross-Platform Makefile Generator
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
+ See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+
+#include "cmCPackZIPGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+
+//----------------------------------------------------------------------
+cmCPackZIPGenerator::cmCPackZIPGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackZIPGenerator::~cmCPackZIPGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf)
+{
+ int res = this->Superclass::Initialize(name, mf);
+ if ( !res )
+ {
+ return res;
+ }
+ 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 )
+ {
+ 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 )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a sutable ZIP program"
+ << std::endl);
+ return 0;
+ }
+ this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: " << pkgPath.c_str()
+ << std::endl);
+ return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackZIPGenerator::CompressFiles(const char* outFileName,
+ const char* toplevel, const std::vector<std::string>& files)
+{
+ cmOStringStream dmgCmd;
+ switch ( this->ZipStyle )
+ {
+ case cmCPackZIPGenerator::StyleWinZip:
+ dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
+ << "\" -P \"" << outFileName
+ << "\"";
+ break;
+ case cmCPackZIPGenerator::StyleUnixZip:
+ dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
+ << "\" \"" << outFileName
+ << "\"";
+ break;
+ default:
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style"
+ << std::endl);
+ return 0;
+ }
+ std::vector<std::string>::const_iterator fileIt;
+ for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
+ {
+ dmgCmd << " \""
+ << cmSystemTools::RelativePath(toplevel, fileIt->c_str())
+ << "\"";
+ }
+ std::string output;
+ int retVal = -1;
+ int res = cmSystemTools::RunSingleCommand(dmgCmd.str().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
+ << "# Output:" << std::endl
+ << output.c_str() << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
+ << dmgCmd.str().c_str() << std::endl
+ << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
+ return 0;
+ }
+ return 1;
+}
diff --git a/Source/CPack/cmCPackZIPGenerator.h b/Source/CPack/cmCPackZIPGenerator.h
new file mode 100644
index 0000000..2bb75fe
--- /dev/null
+++ b/Source/CPack/cmCPackZIPGenerator.h
@@ -0,0 +1,59 @@
+/*=========================================================================
+
+ Program: CMake - Cross-Platform Makefile Generator
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc. All rights reserved.
+ See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+
+#ifndef cmCPackZIPGenerator_h
+#define cmCPackZIPGenerator_h
+
+#include "cmCPackGenericGenerator.h"
+
+class cmCPackZIPGeneratorForward;
+
+/** \class cmCPackZIPGenerator
+ * \brief A generator for ZIP files
+ */
+class cmCPackZIPGenerator : public cmCPackGenericGenerator
+{
+public:
+ friend class cmCPackZIPGeneratorForward;
+ cmCPackTypeMacro(cmCPackZIPGenerator, cmCPackGenericGenerator);
+
+ /**
+ * Initialize generator
+ */
+ virtual int Initialize(const char* name, cmMakefile* mf);
+ /**
+ * Construct generator
+ */
+ cmCPackZIPGenerator();
+ virtual ~cmCPackZIPGenerator();
+
+ enum ZipStyles
+ {
+ StyleUnkown,
+ StyleWinZip,
+ StyleUnixZip
+ };
+
+protected:
+ int CompressFiles(const char* outFileName, const char* toplevel,
+ const std::vector<std::string>& files);
+ virtual const char* GetOutputExtension() { return "zip"; }
+
+ int ZipStyle;
+};
+
+#endif
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index c44959a..8dff672 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -338,7 +338,7 @@ int main (int argc, char *argv[])
<< generator.c_str() << std::endl);
parsed = 0;
}
- if ( !cpackGenerator->Initialize(gen, mf) )
+ if ( parsed && !cpackGenerator->Initialize(gen, mf) )
{
parsed = 0;
}