summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2006-05-04 01:42:51 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2006-05-04 01:42:51 (GMT)
commitd4e84f8c5b0deea6d1559a0894662965ff9b7edc (patch)
treef6a5bfe0cbb78ac1b01944cdc583002bcefb0093
parent9600c0a189662dc0f5ffc03d9ac5555f133ed724 (diff)
downloadCMake-d4e84f8c5b0deea6d1559a0894662965ff9b7edc.zip
CMake-d4e84f8c5b0deea6d1559a0894662965ff9b7edc.tar.gz
CMake-d4e84f8c5b0deea6d1559a0894662965ff9b7edc.tar.bz2
ENH: Add BZip2 support, add better documentation
-rw-r--r--Source/CMakeLists.txt1
-rw-r--r--Source/CPack/cmCPackGenerators.cxx3
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.cxx169
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.h47
-rw-r--r--Source/CPack/cpack.cxx17
5 files changed, 224 insertions, 13 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index c21316e..3f8bb1a 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -276,6 +276,7 @@ SET(CPACK_SRCS
CPack/cmCPackNSISGenerator.cxx
CPack/cmCPackPackageMakerGenerator.cxx
CPack/cmCPackZIPGenerator.cxx
+ CPack/cmCPackTarBZip2Generator.cxx
CPack/cmCPackTarCompressGenerator.cxx
CPack/cmCPackGenericGenerator.cxx
CPack/cmCPackLog.cxx
diff --git a/Source/CPack/cmCPackGenerators.cxx b/Source/CPack/cmCPackGenerators.cxx
index 79c0430..3515e0e 100644
--- a/Source/CPack/cmCPackGenerators.cxx
+++ b/Source/CPack/cmCPackGenerators.cxx
@@ -19,6 +19,7 @@
#include "cmCPackGenericGenerator.h"
#include "cmCPackTGZGenerator.h"
+#include "cmCPackTarBZip2Generator.h"
#include "cmCPackTarCompressGenerator.h"
#include "cmCPackZIPGenerator.h"
#include "cmCPackSTGZGenerator.h"
@@ -40,6 +41,8 @@ cmCPackGenerators::cmCPackGenerators()
#endif
this->RegisterGenerator("ZIP", "ZIP file format",
cmCPackZIPGenerator::CreateGenerator);
+ this->RegisterGenerator("TBZ2", "Tar BZip2 compression",
+ cmCPackTarBZip2Generator::CreateGenerator);
this->RegisterGenerator("TZ", "Tar Compress compression",
cmCPackTarCompressGenerator::CreateGenerator);
#ifdef __APPLE__
diff --git a/Source/CPack/cmCPackTarBZip2Generator.cxx b/Source/CPack/cmCPackTarBZip2Generator.cxx
new file mode 100644
index 0000000..f58dc0f
--- /dev/null
+++ b/Source/CPack/cmCPackTarBZip2Generator.cxx
@@ -0,0 +1,169 @@
+/*=========================================================================
+
+ 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 "cmCPackTarBZip2Generator.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>
+
+// Includes needed for implementation of RenameFile. This is not in
+// system tools because it is not implemented robustly enough to move
+// files across directories.
+#ifdef _WIN32
+# include <windows.h>
+# include <sys/stat.h>
+#endif
+
+//----------------------------------------------------------------------
+cmCPackTarBZip2Generator::cmCPackTarBZip2Generator()
+{
+ this->Compress = false;
+}
+
+//----------------------------------------------------------------------
+cmCPackTarBZip2Generator::~cmCPackTarBZip2Generator()
+{
+}
+
+//----------------------------------------------------------------------
+int cmCPackTarBZip2Generator::InitializeInternal()
+{
+ this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
+ std::vector<std::string> path;
+ std::string pkgPath = cmSystemTools::FindProgram("bzip2", path, false);
+ if ( pkgPath.empty() )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find BZip2" << std::endl);
+ return 0;
+ }
+ this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Compress program: "
+ << pkgPath.c_str()
+ << std::endl);
+
+ return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackTarBZip2Generator::CompressFiles(const char* outFileName,
+ const char* toplevel, const std::vector<std::string>& files)
+{
+ std::string packageDirFileName
+ = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+ packageDirFileName += ".tar";
+ std::string output;
+ int retVal = -1;
+ if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(),
+ toplevel, files) )
+ {
+ return 0;
+ }
+
+ cmOStringStream dmgCmd1;
+ dmgCmd1 << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
+ << "\" \"" << packageDirFileName
+ << "\"";
+ retVal = -1;
+ int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output,
+ &retVal, toplevel, this->GeneratorVerbose, 0);
+ if ( !res || retVal )
+ {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/CompressBZip2.log";
+ cmGeneratedFileStream ofs(tmpFile.c_str());
+ ofs << "# Run command: " << dmgCmd1.str().c_str() << std::endl
+ << "# Output:" << std::endl
+ << output.c_str() << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running BZip2 command: "
+ << dmgCmd1.str().c_str() << std::endl
+ << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
+ return 0;
+ }
+
+ std::string compressOutFile = packageDirFileName + ".bz2";
+ if ( !cmSystemTools::SameFile(compressOutFile.c_str(), outFileName ) )
+ {
+ if ( !this->RenameFile(compressOutFile.c_str(), outFileName) )
+ {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem renaming: \""
+ << compressOutFile.c_str() << "\" to \""
+ << outFileName << std::endl);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+int cmCPackTarBZip2Generator::RenameFile(const char* oldname,
+ const char* newname)
+{
+#ifdef _WIN32
+ /* On Windows the move functions will not replace existing files.
+ Check if the destination exists. */
+ struct stat newFile;
+ if(stat(newname, &newFile) == 0)
+ {
+ /* The destination exists. We have to replace it carefully. The
+ MoveFileEx function does what we need but is not available on
+ Win9x. */
+ OSVERSIONINFO osv;
+ DWORD attrs;
+
+ /* Make sure the destination is not read only. */
+ attrs = GetFileAttributes(newname);
+ if(attrs & FILE_ATTRIBUTE_READONLY)
+ {
+ SetFileAttributes(newname, attrs & ~FILE_ATTRIBUTE_READONLY);
+ }
+
+ /* Check the windows version number. */
+ osv.dwOSVersionInfoSize = sizeof(osv);
+ GetVersionEx(&osv);
+ if(osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
+ {
+ /* This is Win9x. There is no MoveFileEx implementation. We
+ cannot quite rename the file atomically. Just delete the
+ destination and then move the file. */
+ DeleteFile(newname);
+ return MoveFile(oldname, newname);
+ }
+ else
+ {
+ /* This is not Win9x. Use the MoveFileEx implementation. */
+ return MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING);
+ }
+ }
+ else
+ {
+ /* The destination does not exist. Just move the file. */
+ return MoveFile(oldname, newname);
+ }
+#else
+ /* On UNIX we have an OS-provided call to do this atomically. */
+ return rename(oldname, newname) == 0;
+#endif
+}
+
diff --git a/Source/CPack/cmCPackTarBZip2Generator.h b/Source/CPack/cmCPackTarBZip2Generator.h
new file mode 100644
index 0000000..c5c404b
--- /dev/null
+++ b/Source/CPack/cmCPackTarBZip2Generator.h
@@ -0,0 +1,47 @@
+/*=========================================================================
+
+ 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 cmCPackTarBZip2Generator_h
+#define cmCPackTarBZip2Generator_h
+
+#include "cmCPackTGZGenerator.h"
+
+/** \class cmCPackTarBZip2Generator
+ * \brief A generator for TarBZip2 files
+ */
+class cmCPackTarBZip2Generator : public cmCPackTGZGenerator
+{
+public:
+ friend class cmCPackTarBZip2GeneratorForward;
+ cmCPackTypeMacro(cmCPackTarBZip2Generator, cmCPackTGZGenerator);
+
+ /**
+ * Construct generator
+ */
+ cmCPackTarBZip2Generator();
+ virtual ~cmCPackTarBZip2Generator();
+
+protected:
+ virtual int InitializeInternal();
+ int CompressFiles(const char* outFileName, const char* toplevel,
+ const std::vector<std::string>& files);
+ virtual const char* GetOutputExtension() { return "tar.bz2"; }
+
+ int RenameFile(const char* oldname, const char* newname);
+};
+
+#endif
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index 8111d22..3143c2a 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -42,7 +42,7 @@ static const cmDocumentationEntry cmDocumentationName[] =
static const cmDocumentationEntry cmDocumentationUsage[] =
{
{0,
- " cpack -G <generator> -P <ProjectName> -R <ReleaseVersion> [options]",
+ " cpack -G <generator> [options]",
0},
{0,0,0}
};
@@ -67,23 +67,14 @@ static const cmDocumentationEntry cmDocumentationOptions[] =
"platforms. A generator is responsible for generating input files for "
"particular system and invoking that systems. Possible generator names "
"are specified in the Generators section." },
- {"-P <ProjectName>", "Specify the project name.",
- "This option specifies the project name that will be used to generate "
- "the installer." },
{"-C <Configuration>", "Specify the project configuration",
"This option specifies the configuration that the project was build "
"with, for example 'Debug', 'Release'." },
- {"-R <ReleaseVersion>", "Specify the release version of the project.",
- "This option specifies the release version of the project that will be "
- "used by installer." },
{"-D <var>=<value>", "Set a CPack variable.", \
"Set a variable that can be used by the generator."}, \
- {"--patch <ReleasePatch>", "Specify the patch of the project.",
- "This option specifies the patch of the project that will be "
- "used by installer." },
- {"--vendor <ProjectVendor>", "Specify the vendor of the project.",
- "This option specifies the vendor of the project that will be "
- "used by installer." },
+ {"--config <config file>", "Specify the config file.",
+ "Specify the config file to use to create the package. By default "
+ "CPackConfig.cmake in the current directory will be used." },
{0,0,0}
};