cmCPackCygwinBinaryGenerator.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "cmCPackCygwinBinaryGenerator.h"
  14. #include "cmake.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmSystemTools.h"
  18. #include "cmMakefile.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include "cmCPackLog.h"
  21. #include <cmsys/SystemTools.hxx>
  22. //----------------------------------------------------------------------
  23. cmCPackCygwinBinaryGenerator::cmCPackCygwinBinaryGenerator()
  24. {
  25. this->Compress = false;
  26. }
  27. //----------------------------------------------------------------------
  28. cmCPackCygwinBinaryGenerator::~cmCPackCygwinBinaryGenerator()
  29. {
  30. }
  31. //----------------------------------------------------------------------
  32. int cmCPackCygwinBinaryGenerator::InitializeInternal()
  33. {
  34. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
  35. this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
  36. std::vector<std::string> path;
  37. std::string pkgPath = cmSystemTools::FindProgram("bzip2", path, false);
  38. if ( pkgPath.empty() )
  39. {
  40. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find BZip2" << std::endl);
  41. return 0;
  42. }
  43. this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  44. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Compress program: "
  45. << pkgPath.c_str()
  46. << std::endl);
  47. return this->Superclass::InitializeInternal();
  48. }
  49. //----------------------------------------------------------------------
  50. int cmCPackCygwinBinaryGenerator::CompressFiles(const char* outFileName,
  51. const char* toplevel, const std::vector<std::string>& files)
  52. {
  53. std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
  54. packageName += "-";
  55. packageName += this->GetOption("CPACK_PACKAGE_VERSION");
  56. packageName = cmsys::SystemTools::LowerCase(packageName);
  57. std::string manifest = "/usr/share/doc/";
  58. manifest += packageName;
  59. manifest += "/MANIFEST";
  60. std::string manifestFile
  61. = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  62. // Create a MANIFEST file that contains all of the files in
  63. // the tar file
  64. std::string tempdir = manifestFile;
  65. manifestFile += manifest;
  66. // create an extra scope to force the stream
  67. // to create the file before the super class is called
  68. {
  69. cmGeneratedFileStream ofs(manifestFile.c_str());
  70. for(std::vector<std::string>::const_iterator i = files.begin();
  71. i != files.end(); ++i)
  72. {
  73. // remove the temp dir and replace with /usr
  74. ofs << (*i).substr(tempdir.size()) << "\n";
  75. }
  76. ofs << manifest << "\n";
  77. }
  78. // add the manifest file to the list of all files
  79. std::vector<std::string> filesWithManifest = files;
  80. filesWithManifest.push_back(manifestFile);
  81. // create the bzip2 tar file
  82. return this->Superclass::CompressFiles(outFileName, toplevel,
  83. filesWithManifest);
  84. }
  85. const char* cmCPackCygwinBinaryGenerator::GetOutputExtension()
  86. {
  87. this->OutputExtension = "-";
  88. const char* patchNumber =this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  89. if(!patchNumber)
  90. {
  91. patchNumber = "1";
  92. cmCPackLogger(cmCPackLog::LOG_WARNING,
  93. "CPACK_CYGWIN_PATCH_NUMBER not specified using 1"
  94. << std::endl);
  95. }
  96. this->OutputExtension +=
  97. this->OutputExtension += ".tar.bz2";
  98. return this->OutputExtension.c_str();
  99. }