diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-07-24 16:52:39 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-07-24 16:52:39 (GMT) |
commit | 919265516ea3233e6a4e29a17ad4ec24150eefda (patch) | |
tree | 1d2beab70b483ab0f2153d6766763094c7b11331 /Source/CPack/cmCPackZIPGenerator.cxx | |
parent | 4ae802d9c19d1f021970215d992b6aebc4165ec8 (diff) | |
download | CMake-919265516ea3233e6a4e29a17ad4ec24150eefda.zip CMake-919265516ea3233e6a4e29a17ad4ec24150eefda.tar.gz CMake-919265516ea3233e6a4e29a17ad4ec24150eefda.tar.bz2 |
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
Diffstat (limited to 'Source/CPack/cmCPackZIPGenerator.cxx')
-rw-r--r-- | Source/CPack/cmCPackZIPGenerator.cxx | 138 |
1 files changed, 26 insertions, 112 deletions
diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx index 34db2f3..8af17c5 100644 --- a/Source/CPack/cmCPackZIPGenerator.cxx +++ b/Source/CPack/cmCPackZIPGenerator.cxx @@ -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 @@ cmCPackZIPGenerator::~cmCPackZIPGenerator() 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 @@ int cmCPackZIPGenerator::CompressFiles(const char* outFileName, 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@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; } |