cmCPackZIPGenerator.cxx 3.1 KB

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