cmCPackZIPGenerator.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCPackZIPGenerator.h"
  14. #include "cmSystemTools.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmCPackLog.h"
  17. #include <cmsys/SystemTools.hxx>
  18. //----------------------------------------------------------------------
  19. cmCPackZIPGenerator::cmCPackZIPGenerator()
  20. {
  21. }
  22. //----------------------------------------------------------------------
  23. cmCPackZIPGenerator::~cmCPackZIPGenerator()
  24. {
  25. }
  26. //----------------------------------------------------------------------
  27. int cmCPackZIPGenerator::InitializeInternal()
  28. {
  29. this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
  30. this->ReadListFile("CPackZIP.cmake");
  31. if ((!this->IsSet("ZIP_EXECUTABLE"))
  32. || (!this->IsSet("CPACK_ZIP_COMMAND")))
  33. {
  34. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a suitable ZIP program"
  35. << std::endl);
  36. return 0;
  37. }
  38. return this->Superclass::InitializeInternal();
  39. }
  40. //----------------------------------------------------------------------
  41. int cmCPackZIPGenerator::CompressFiles(const char* outFileName,
  42. const char* toplevel, const std::vector<std::string>& files)
  43. {
  44. std::string tempFileName;
  45. tempFileName = toplevel;
  46. tempFileName += "/winZip.filelist";
  47. bool needQuotesInFile = cmSystemTools::IsOn(
  48. this->GetOption("CPACK_ZIP_NEED_QUOTES"));
  49. std::string cmd = this->GetOption("CPACK_ZIP_COMMAND");
  50. cmsys::SystemTools::ReplaceString(cmd, "<ARCHIVE>", outFileName);
  51. cmsys::SystemTools::ReplaceString(cmd, "<FILELIST>", "winZip.filelist");
  52. { // the scope is needed for cmGeneratedFileStream
  53. cmGeneratedFileStream out(tempFileName.c_str());
  54. std::vector<std::string>::const_iterator fileIt;
  55. for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
  56. {
  57. if ( needQuotesInFile )
  58. {
  59. out << "\"";
  60. }
  61. out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
  62. if ( needQuotesInFile )
  63. {
  64. out << "\"";
  65. }
  66. out << std::endl;
  67. }
  68. }
  69. std::string output;
  70. int retVal = -1;
  71. int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
  72. &retVal, toplevel, this->GeneratorVerbose, 0);
  73. if ( !res || retVal )
  74. {
  75. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  76. tmpFile += "/CompressZip.log";
  77. cmGeneratedFileStream ofs(tmpFile.c_str());
  78. ofs << "# Run command: " << cmd.c_str() << std::endl
  79. << "# Output:" << std::endl
  80. << output.c_str() << std::endl;
  81. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
  82. << cmd.c_str() << std::endl
  83. << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
  84. return 0;
  85. }
  86. return 1;
  87. }