浏览代码

CPack: add generators for .7z and .tar.xz (#13072, #14519)

Daniel Pfeifer 11 年之前
父节点
当前提交
f931a18c33

+ 5 - 0
Help/release/dev/cpack-add-lzma.rst

@@ -0,0 +1,5 @@
+cpack-add-lzma
+--------------
+
+* :manual:`cpack(1)` gained ``7Z`` and ``TXZ`` generators supporting
+  lzma-compressed archives.

+ 2 - 0
Source/CMakeLists.txt

@@ -580,9 +580,11 @@ set(CPACK_SRCS
   CPack/cmCPackIFWGenerator.cxx
   CPack/cmCPackSTGZGenerator.cxx
   CPack/cmCPackTGZGenerator.cxx
+  CPack/cmCPackTXZGenerator.cxx
   CPack/cmCPackTarBZip2Generator.cxx
   CPack/cmCPackTarCompressGenerator.cxx
   CPack/cmCPackZIPGenerator.cxx
+  CPack/cmCPack7zGenerator.cxx
   )
 
 if(CYGWIN)

+ 25 - 0
Source/CPack/cmCPack7zGenerator.cxx

@@ -0,0 +1,25 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "cmCPack7zGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPack7zGenerator::cmCPack7zGenerator()
+  :cmCPackArchiveGenerator(cmArchiveWrite::CompressNone,
+                           cmArchiveWrite::Type7Zip)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPack7zGenerator::~cmCPack7zGenerator()
+{
+}

+ 36 - 0
Source/CPack/cmCPack7zGenerator.h

@@ -0,0 +1,36 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc.
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef cmCPack7zGenerator_h
+#define cmCPack7zGenerator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPack7zGenerator
+ * \brief A generator for 7z files
+ */
+class cmCPack7zGenerator : public cmCPackArchiveGenerator
+{
+public:
+  cmCPackTypeMacro(cmCPack7zGenerator, cmCPackArchiveGenerator);
+
+  /**
+   * Construct generator
+   */
+  cmCPack7zGenerator();
+  virtual ~cmCPack7zGenerator();
+
+protected:
+  virtual const char* GetOutputExtension() { return ".7z"; }
+};
+
+#endif

+ 12 - 0
Source/CPack/cmCPackGeneratorFactory.cxx

@@ -14,9 +14,11 @@
 
 #include "cmCPackGenerator.h"
 #include "cmCPackTGZGenerator.h"
+#include "cmCPackTXZGenerator.h"
 #include "cmCPackTarBZip2Generator.h"
 #include "cmCPackTarCompressGenerator.h"
 #include "cmCPackZIPGenerator.h"
+#include "cmCPack7zGenerator.h"
 #include "cmCPackSTGZGenerator.h"
 #include "cmCPackNSISGenerator.h"
 #include "cmCPackIFWGenerator.h"
@@ -57,6 +59,11 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
     this->RegisterGenerator("TGZ", "Tar GZip compression",
       cmCPackTGZGenerator::CreateGenerator);
     }
+  if (cmCPackTXZGenerator::CanGenerate())
+    {
+    this->RegisterGenerator("TXZ", "Tar XZ compression",
+      cmCPackTXZGenerator::CreateGenerator);
+    }
   if (cmCPackSTGZGenerator::CanGenerate())
     {
     this->RegisterGenerator("STGZ", "Self extracting Tar GZip compression",
@@ -92,6 +99,11 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
     this->RegisterGenerator("ZIP", "ZIP file format",
       cmCPackZIPGenerator::CreateGenerator);
     }
+  if (cmCPack7zGenerator::CanGenerate())
+    {
+    this->RegisterGenerator("7Z", "7-Zip file format",
+      cmCPack7zGenerator::CreateGenerator);
+    }
 #ifdef _WIN32
   if (cmCPackWIXGenerator::CanGenerate())
     {

+ 25 - 0
Source/CPack/cmCPackTXZGenerator.cxx

@@ -0,0 +1,25 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "cmCPackTXZGenerator.h"
+
+//----------------------------------------------------------------------
+cmCPackTXZGenerator::cmCPackTXZGenerator()
+  :cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ,
+                           cmArchiveWrite::TypeTAR)
+{
+}
+
+//----------------------------------------------------------------------
+cmCPackTXZGenerator::~cmCPackTXZGenerator()
+{
+}

+ 35 - 0
Source/CPack/cmCPackTXZGenerator.h

@@ -0,0 +1,35 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc.
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef cmCPackTXZGenerator_h
+#define cmCPackTXZGenerator_h
+
+#include "cmCPackArchiveGenerator.h"
+
+/** \class cmCPackTXZGenerator
+ * \brief A generator for TXZ files
+ *
+ */
+class cmCPackTXZGenerator : public cmCPackArchiveGenerator
+{
+public:
+  cmCPackTypeMacro(cmCPackTXZGenerator, cmCPackArchiveGenerator);
+  /**
+   * Construct generator
+   */
+  cmCPackTXZGenerator();
+  virtual ~cmCPackTXZGenerator();
+protected:
+  virtual const char* GetOutputExtension() { return ".tar.xz"; }
+};
+
+#endif

+ 9 - 1
Source/cmArchiveWrite.cxx

@@ -159,7 +159,15 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
         this->Error += cm_archive_error_string(this->Archive);
         return;
         }
-    break;
+      break;
+    case Type7Zip:
+      if(archive_write_set_format_7zip(this->Archive) != ARCHIVE_OK)
+        {
+        this->Error = "archive_write_set_format_7zip: ";
+        this->Error += cm_archive_error_string(this->Archive);
+        return;
+        }
+      break;
     }
 
   // do not pad the last block!!

+ 2 - 1
Source/cmArchiveWrite.h

@@ -42,7 +42,8 @@ public:
   enum Type
   {
     TypeTAR,
-    TypeZIP
+    TypeZIP,
+    Type7Zip
   };
 
   /** Construct with output stream to which to write archive.  */