diff options
Diffstat (limited to 'Source/CPack')
-rw-r--r-- | Source/CPack/cmCPackGenerators.cxx | 26 | ||||
-rw-r--r-- | Source/CPack/cmCPackGenerators.h | 6 | ||||
-rw-r--r-- | Source/CPack/cmCPackGenericGenerator.cxx | 69 | ||||
-rw-r--r-- | Source/CPack/cmCPackNSISGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/CPack/cmCPackPackageMakerGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/CPack/cmCPackSTGZGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/CPack/cmCPackTGZGenerator.cxx | 136 | ||||
-rw-r--r-- | Source/CPack/cmCPackTGZGenerator.h | 2 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarBZip2Generator.cxx | 169 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarBZip2Generator.h | 47 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarCompressGenerator.cxx | 168 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarCompressGenerator.h | 47 | ||||
-rw-r--r-- | Source/CPack/cmCPackZIPGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/CPack/cpack.cxx | 34 |
14 files changed, 638 insertions, 95 deletions
diff --git a/Source/CPack/cmCPackGenerators.cxx b/Source/CPack/cmCPackGenerators.cxx index e120c2b..3515e0e 100644 --- a/Source/CPack/cmCPackGenerators.cxx +++ b/Source/CPack/cmCPackGenerators.cxx @@ -19,6 +19,8 @@ #include "cmCPackGenericGenerator.h" #include "cmCPackTGZGenerator.h" +#include "cmCPackTarBZip2Generator.h" +#include "cmCPackTarCompressGenerator.h" #include "cmCPackZIPGenerator.h" #include "cmCPackSTGZGenerator.h" #include "cmCPackNSISGenerator.h" @@ -29,12 +31,24 @@ //---------------------------------------------------------------------- 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", + this->RegisterGenerator("TGZ", "Tar GZip compression", + cmCPackTGZGenerator::CreateGenerator); + this->RegisterGenerator("STGZ", "Self extracting Tar GZip compression", + cmCPackSTGZGenerator::CreateGenerator); +#ifdef _WIN32 + this->RegisterGenerator("NSIS", "Null Soft Installer", + cmCPackNSISGenerator::CreateGenerator); +#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__ + this->RegisterGenerator("PackageMaker", "Mac OSX Package Maker compression", cmCPackPackageMakerGenerator::CreateGenerator); +#endif } //---------------------------------------------------------------------- @@ -79,6 +93,7 @@ cmCPackGenericGenerator* cmCPackGenerators::NewGeneratorInternal( //---------------------------------------------------------------------- void cmCPackGenerators::RegisterGenerator(const char* name, + const char* generatorDescription, CreateGeneratorCall* createGenerator) { if ( !name || !createGenerator ) @@ -88,4 +103,5 @@ void cmCPackGenerators::RegisterGenerator(const char* name, return; } this->GeneratorCreators[name] = createGenerator; + this->GeneratorDescriptions[name] = generatorDescription; } diff --git a/Source/CPack/cmCPackGenerators.h b/Source/CPack/cmCPackGenerators.h index d100e9b..76a1697 100644 --- a/Source/CPack/cmCPackGenerators.h +++ b/Source/CPack/cmCPackGenerators.h @@ -42,16 +42,22 @@ public: typedef cmCPackGenericGenerator* CreateGeneratorCall(); void RegisterGenerator(const char* name, + const char* generatorDescription, CreateGeneratorCall* createGenerator); void SetLogger(cmCPackLog* logger) { this->Logger = logger; } + typedef std::map<cmStdString, cmStdString> DescriptionsMap; + const DescriptionsMap& GetGeneratorsList() const + { return this->GeneratorDescriptions; } + private: cmCPackGenericGenerator* NewGeneratorInternal(const char* name); std::vector<cmCPackGenericGenerator*> Generators; typedef std::map<cmStdString, CreateGeneratorCall*> t_GeneratorCreatorsMap; t_GeneratorCreatorsMap GeneratorCreators; + DescriptionsMap GeneratorDescriptions; cmCPackLog* Logger; }; diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx index 6bf578e..8d5c832 100644 --- a/Source/CPack/cmCPackGenericGenerator.cxx +++ b/Source/CPack/cmCPackGenericGenerator.cxx @@ -68,15 +68,15 @@ int cmCPackGenericGenerator::PrepareNames() std::string outFile = topDirectory + "/" + outName; std::string installPrefix = tempDirectory + this->GetInstallPrefix(); - this->SetOption("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str()); - this->SetOption("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str()); - this->SetOption("CPACK_OUTPUT_FILE_NAME", outName.c_str()); - this->SetOption("CPACK_OUTPUT_FILE_PATH", destFile.c_str()); - this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str()); - this->SetOption("CPACK_INSTALL_DIRECTORY", this->GetInstallPath()); - this->SetOption("CPACK_NATIVE_INSTALL_DIRECTORY", + this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str()); + this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str()); + this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str()); + this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str()); + this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str()); + this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath()); + this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY", cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str()); - this->SetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY", installPrefix.c_str()); + this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY", installPrefix.c_str()); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl); @@ -108,7 +108,7 @@ int cmCPackGenericGenerator::PrepareNames() { ostr << cmSystemTools::MakeXMLSafe(line.c_str()) << std::endl; } - this->SetOption("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str()); + this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str()); } if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") ) { @@ -119,6 +119,13 @@ int cmCPackGenericGenerator::PrepareNames() return 0; } + std::vector<std::string> path; + std::string pkgPath = cmSystemTools::FindProgram("strip", path, false); + if ( !pkgPath.empty() ) + { + this->SetOptionIfNotSet("CPACK_STRIP_COMMAND", pkgPath.c_str()); + } + return 1; } @@ -318,7 +325,11 @@ int cmCPackGenericGenerator::InstallProject() cmGlobalGenerator* globalGenerator = 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 + // on windows. + cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths()); + // Does this generator require pre-install? if ( globalGenerator->GetPreinstallTargetName() ) { @@ -432,6 +443,44 @@ int cmCPackGenericGenerator::InstallProject() { cmSystemTools::PutEnv("DESTDIR="); } + + const char* stripExecutable = this->GetOption("CPACK_STRIP_COMMAND"); + const char* stripFiles + = this->GetOption("CPACK_STRIP_FILES"); + if ( stripFiles && *stripFiles && stripExecutable && *stripExecutable ) + { + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Strip files" << std::endl); + std::vector<std::string> stripFilesVector; + cmSystemTools::ExpandListArgument(stripFiles, + stripFilesVector); + std::vector<std::string>::iterator it; + for ( it = stripFilesVector.begin(); + it != stripFilesVector.end(); + ++it ) + { + std::string fileName = tempInstallDirectory; + fileName += "/" + *it; + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + " Strip file: " << fileName.c_str() + << std::endl); + std::string stripCommand = stripExecutable; + stripCommand += " \""; + stripCommand += fileName + "\""; + int retVal = 1; + std::string output; + bool resB = cmSystemTools::RunSingleCommand(stripCommand.c_str(), &output, + &retVal, 0, this->GeneratorVerbose, 0); + if ( !resB || retVal ) + { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Problem running install command: " << stripCommand.c_str() + << std::endl + << "Error was: \"" << output.c_str() << "\"" + << std::endl); + return 0; + } + } + } return res; } diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 31345f3..5f2541f 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -78,7 +78,7 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName, } cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " << str.str().c_str() << std::endl); - this->SetOption("CPACK_NSIS_DELETE_FILES", str.str().c_str()); + this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str()); std::vector<std::string> dirs; this->GetListOfSubdirectories(toplevel, dirs); std::vector<std::string>::const_iterator sit; @@ -96,7 +96,7 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName, } cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: " << dstr.str().c_str() << std::endl); - this->SetOption("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str()); + this->SetOptionIfNotSet("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str()); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName << " to " << nsisFileName << std::endl); @@ -193,7 +193,7 @@ int cmCPackNSISGenerator::InitializeInternal() return 0; } - this->SetOption("CPACK_INSTALLER_PROGRAM", nsisPath.c_str()); + this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", nsisPath.c_str()); const char* cpackPackageExecutables = this->GetOption("CPACK_PACKAGE_EXECUTABLES"); if ( cpackPackageExecutables ) @@ -226,8 +226,8 @@ int cmCPackNSISGenerator::InitializeInternal() deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName << ".lnk\"" << std::endl; } - this->SetOption("CPACK_NSIS_CREATE_ICONS", str.str().c_str()); - this->SetOption("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str()); + this->SetOptionIfNotSet("CPACK_NSIS_CREATE_ICONS", str.str().c_str()); + this->SetOptionIfNotSet("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str()); } return this->Superclass::InitializeInternal(); diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 1d6cb35..dff1413 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -213,7 +213,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal() << std::endl); return 0; } - this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); + this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); pkgPath = cmSystemTools::FindProgram("hdiutil", path, false); if ( pkgPath.empty() ) { @@ -221,7 +221,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal() << std::endl); return 0; } - this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str()); + this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str()); return this->Superclass::InitializeInternal(); } diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index 9346b3e..5044d3a 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -51,7 +51,7 @@ int cmCPackSTGZGenerator::InitializeInternal() return 0; } this->SetOptionIfNotSet("CPACK_STGZ_HEADER_FILE", inFile.c_str()); - this->SetOption("CPACK_AT_SIGN", "@"); + this->SetOptionIfNotSet("CPACK_AT_SIGN", "@"); return this->Superclass::InitializeInternal(); } @@ -84,11 +84,20 @@ int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os) cmsys_ios::ostringstream str; int counter = 0; + std::string inLicFile = this->GetOption("CPACK_RESOURCE_FILE_LICENSE"); + std::string line; + std::ifstream ilfs(inLicFile.c_str()); + std::string licenseText; + while ( cmSystemTools::GetLineFromStream(ilfs, line) ) + { + licenseText += line + "\n"; + } + this->SetOptionIfNotSet("CPACK_RESOURCE_FILE_LICENSE_CONTENT", licenseText.c_str()); + const char headerLengthTag[] = "###CPACK_HEADER_LENGTH###"; // Create the header std::string inFile = this->GetOption("CPACK_STGZ_HEADER_FILE"); - std::string line; std::ifstream ifs(inFile.c_str()); std::string packageHeaderText; while ( cmSystemTools::GetLineFromStream(ifs, line) ) diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx index 1daaee9..d4663db 100644 --- a/Source/CPack/cmCPackTGZGenerator.cxx +++ b/Source/CPack/cmCPackTGZGenerator.cxx @@ -45,6 +45,7 @@ class cmCPackTGZGeneratorForward //---------------------------------------------------------------------- cmCPackTGZGenerator::cmCPackTGZGenerator() { + this->Compress = true; } //---------------------------------------------------------------------- @@ -58,15 +59,17 @@ static const size_t cmCPackTGZ_Data_BlockSize = 16384; class cmCPackTGZ_Data { public: - cmCPackTGZ_Data(cmCPackTGZGenerator* gen) : + cmCPackTGZ_Data(cmCPackTGZGenerator* gen, bool compress) : OutputStream(0), Generator(gen), - CompressionLevel(Z_DEFAULT_COMPRESSION) {} + CompressionLevel(Z_DEFAULT_COMPRESSION), + Compress(compress) {} std::ostream* OutputStream; cmCPackTGZGenerator* Generator; char CompressedBuffer[cmCPackTGZ_Data_BlockSize]; int CompressionLevel; z_stream ZLibStream; uLong CRC; + bool Compress; }; //---------------------------------------------------------------------- @@ -84,14 +87,17 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname, { cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data; - mydata->ZLibStream.zalloc = Z_NULL; - mydata->ZLibStream.zfree = Z_NULL; - mydata->ZLibStream.opaque = Z_NULL; - int strategy = Z_DEFAULT_STRATEGY; - if ( deflateInit2(&mydata->ZLibStream, mydata->CompressionLevel, - Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy) != Z_OK ) + if ( mydata->Compress ) { - return -1; + mydata->ZLibStream.zalloc = Z_NULL; + mydata->ZLibStream.zfree = Z_NULL; + mydata->ZLibStream.opaque = Z_NULL; + int strategy = Z_DEFAULT_STRATEGY; + if ( deflateInit2(&mydata->ZLibStream, mydata->CompressionLevel, + Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy) != Z_OK ) + { + return -1; + } } cmGeneratedFileStream* gf = new cmGeneratedFileStream; @@ -108,7 +114,10 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname, return -1; } - mydata->CRC = crc32(0L, Z_NULL, 0); + if ( mydata->Compress ) + { + mydata->CRC = crc32(0L, Z_NULL, 0); + } return 0; } @@ -118,35 +127,42 @@ ssize_t cmCPackTGZ_Data_Write(void *client_data, void *buff, size_t n) { cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data; - mydata->ZLibStream.avail_in = n; - mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff); - - do { - mydata->ZLibStream.avail_out = cmCPackTGZ_Data_BlockSize; - mydata->ZLibStream.next_out - = reinterpret_cast<Bytef*>(mydata->CompressedBuffer); - // no bad return value - int ret = deflate(&mydata->ZLibStream, (n?Z_NO_FLUSH:Z_FINISH)); - if(ret == Z_STREAM_ERROR) + if ( mydata->Compress ) + { + mydata->ZLibStream.avail_in = n; + mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff); + + do { + mydata->ZLibStream.avail_out = cmCPackTGZ_Data_BlockSize; + mydata->ZLibStream.next_out + = reinterpret_cast<Bytef*>(mydata->CompressedBuffer); + // no bad return value + int ret = deflate(&mydata->ZLibStream, (n?Z_NO_FLUSH:Z_FINISH)); + if(ret == Z_STREAM_ERROR) + { + return 0; + } + + size_t compressedSize + = cmCPackTGZ_Data_BlockSize - mydata->ZLibStream.avail_out; + + mydata->OutputStream->write( + reinterpret_cast<const char*>(mydata->CompressedBuffer), + compressedSize); + } while ( mydata->ZLibStream.avail_out == 0 ); + + if ( !*mydata->OutputStream ) { return 0; } - - size_t compressedSize - = cmCPackTGZ_Data_BlockSize - mydata->ZLibStream.avail_out; - - mydata->OutputStream->write( - reinterpret_cast<const char*>(mydata->CompressedBuffer), - compressedSize); - } while ( mydata->ZLibStream.avail_out == 0 ); - - if ( !*mydata->OutputStream ) - { - return 0; + if ( n ) + { + mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n); + } } - if ( n ) + else { - mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n); + mydata->OutputStream->write(reinterpret_cast<char*>(buff), n); } return n; } @@ -156,23 +172,26 @@ int cmCPackTGZ_Data_Close(void *client_data) { cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data; - cmCPackTGZ_Data_Write(client_data, 0, 0); - - char buffer[8]; - int n; - uLong x = mydata->CRC; - for (n = 0; n < 4; n++) { - buffer[n] = (int)(x & 0xff); - x >>= 8; - } - x = mydata->ZLibStream.total_in; - for (n = 0; n < 4; n++) { - buffer[n+4] = (int)(x & 0xff); - x >>= 8; - } - - mydata->OutputStream->write(buffer, 8); - (void)deflateEnd(&mydata->ZLibStream); + if ( mydata->Compress ) + { + cmCPackTGZ_Data_Write(client_data, 0, 0); + + char buffer[8]; + int n; + uLong x = mydata->CRC; + for (n = 0; n < 4; n++) { + buffer[n] = (int)(x & 0xff); + x >>= 8; + } + x = mydata->ZLibStream.total_in; + for (n = 0; n < 4; n++) { + buffer[n+4] = (int)(x & 0xff); + x >>= 8; + } + + mydata->OutputStream->write(buffer, 8); + (void)deflateEnd(&mydata->ZLibStream); + } delete mydata->OutputStream; mydata->OutputStream = 0; return (0); @@ -190,7 +209,7 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName, const char* toplevel, const std::vector<std::string>& files) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); - cmCPackTGZ_Data mydata(this); + cmCPackTGZ_Data mydata(this, this->Compress); TAR *t; char buf[TAR_MAXPATHLEN]; char pathname[TAR_MAXPATHLEN]; @@ -257,10 +276,13 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName, //---------------------------------------------------------------------- int cmCPackTGZGenerator::GenerateHeader(std::ostream* os) { - const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ - char header[11]; - sprintf(header, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], - Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); - os->write(header, 10); + if ( this->Compress ) + { + const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ + char header[11]; + sprintf(header, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], + Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); + os->write(header, 10); + } return 1; } diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h index 7dd5875..4323a53 100644 --- a/Source/CPack/cmCPackTGZGenerator.h +++ b/Source/CPack/cmCPackTGZGenerator.h @@ -45,6 +45,8 @@ protected: int CompressFiles(const char* outFileName, const char* toplevel, const std::vector<std::string>& files); virtual const char* GetOutputExtension() { return "tar.gz"; } + + bool Compress; }; #endif 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/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx new file mode 100644 index 0000000..59527cd --- /dev/null +++ b/Source/CPack/cmCPackTarCompressGenerator.cxx @@ -0,0 +1,168 @@ +/*========================================================================= + + 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 "cmCPackTarCompressGenerator.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 + +//---------------------------------------------------------------------- +cmCPackTarCompressGenerator::cmCPackTarCompressGenerator() +{ + this->Compress = false; +} + +//---------------------------------------------------------------------- +cmCPackTarCompressGenerator::~cmCPackTarCompressGenerator() +{ +} + +//---------------------------------------------------------------------- +int cmCPackTarCompressGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); + std::vector<std::string> path; + std::string pkgPath = cmSystemTools::FindProgram("compress", path, false); + if ( pkgPath.empty() ) + { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find Compress" << 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 cmCPackTarCompressGenerator::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 += "/CompressCompress.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 Compress command: " + << dmgCmd1.str().c_str() << std::endl + << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + return 0; + } + + std::string compressOutFile = packageDirFileName + ".Z"; + 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 cmCPackTarCompressGenerator::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/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h new file mode 100644 index 0000000..efd5579 --- /dev/null +++ b/Source/CPack/cmCPackTarCompressGenerator.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 cmCPackTarCompressGenerator_h +#define cmCPackTarCompressGenerator_h + +#include "cmCPackTGZGenerator.h" + +/** \class cmCPackTarCompressGenerator + * \brief A generator for TarCompress files + */ +class cmCPackTarCompressGenerator : public cmCPackTGZGenerator +{ +public: + friend class cmCPackTarCompressGeneratorForward; + cmCPackTypeMacro(cmCPackTarCompressGenerator, cmCPackTGZGenerator); + + /** + * Construct generator + */ + cmCPackTarCompressGenerator(); + virtual ~cmCPackTarCompressGenerator(); + +protected: + virtual int InitializeInternal(); + int CompressFiles(const char* outFileName, const char* toplevel, + const std::vector<std::string>& files); + virtual const char* GetOutputExtension() { return "tar.Z"; } + + int RenameFile(const char* oldname, const char* newname); +}; + +#endif diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx index 8297cc4..d8ad47f 100644 --- a/Source/CPack/cmCPackZIPGenerator.cxx +++ b/Source/CPack/cmCPackZIPGenerator.cxx @@ -79,7 +79,7 @@ int cmCPackZIPGenerator::InitializeInternal() << std::endl); return 0; } - this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); + this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: " << pkgPath.c_str() << std::endl); diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index fa4afb1..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} }; @@ -376,6 +367,23 @@ int main (int argc, char *argv[]) doc.SetUsageSection(cmDocumentationUsage); doc.SetDescriptionSection(cmDocumentationDescription); doc.SetOptionsSection(cmDocumentationOptions); + + std::vector<cmDocumentationEntry> v; + cmCPackGenerators::DescriptionsMap::const_iterator generatorIt; + for( generatorIt = generators.GetGeneratorsList().begin(); + generatorIt != generators.GetGeneratorsList().end(); + ++ generatorIt ) + { + cmDocumentationEntry e; + e.name = generatorIt->first.c_str(); + e.brief = generatorIt->second.c_str(); + e.full = ""; + v.push_back(e); + } + cmDocumentationEntry empty = {0,0,0}; + v.push_back(empty); + doc.SetGeneratorsSection(&v[0]); + doc.SetSeeAlsoList(cmDocumentationSeeAlso); #undef cout return doc.PrintRequestedDocumentation(std::cout)? 0:1; |