cmCPackCygwinBinaryGenerator.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCPackCygwinBinaryGenerator.h"
  4. #include "cmsys/SystemTools.hxx"
  5. #include "cmCPackLog.h"
  6. #include "cmGeneratedFileStream.h"
  7. #include "cmGlobalGenerator.h"
  8. #include "cmMakefile.h"
  9. #include "cmSystemTools.h"
  10. #include "cmake.h"
  11. cmCPackCygwinBinaryGenerator::cmCPackCygwinBinaryGenerator()
  12. : cmCPackArchiveGenerator(cmArchiveWrite::CompressBZip2, "paxr", ".tar.bz2")
  13. {
  14. }
  15. cmCPackCygwinBinaryGenerator::~cmCPackCygwinBinaryGenerator()
  16. {
  17. }
  18. int cmCPackCygwinBinaryGenerator::InitializeInternal()
  19. {
  20. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
  21. this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
  22. return this->Superclass::InitializeInternal();
  23. }
  24. int cmCPackCygwinBinaryGenerator::PackageFiles()
  25. {
  26. std::string packageName =
  27. cmStrCat(this->GetOption("CPACK_PACKAGE_NAME"), '-',
  28. this->GetOption("CPACK_PACKAGE_VERSION"));
  29. packageName = cmsys::SystemTools::LowerCase(packageName);
  30. std::string manifest = cmStrCat("/usr/share/doc/", packageName, "/MANIFEST");
  31. std::string manifestFile = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  32. // Create a MANIFEST file that contains all of the files in
  33. // the tar file
  34. std::string tempdir = manifestFile;
  35. manifestFile += manifest;
  36. // create an extra scope to force the stream
  37. // to create the file before the super class is called
  38. {
  39. cmGeneratedFileStream ofs(manifestFile.c_str());
  40. for (std::string const& file : files) {
  41. // remove the temp dir and replace with /usr
  42. ofs << file.substr(tempdir.size()) << "\n";
  43. }
  44. ofs << manifest << "\n";
  45. }
  46. // add the manifest file to the list of all files
  47. files.push_back(manifestFile);
  48. // create the bzip2 tar file
  49. return this->Superclass::PackageFiles();
  50. }
  51. const char* cmCPackCygwinBinaryGenerator::GetOutputExtension()
  52. {
  53. this->OutputExtension = "-";
  54. const char* patchNumber = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  55. if (!patchNumber) {
  56. patchNumber = "1";
  57. cmCPackLogger(cmCPackLog::LOG_WARNING,
  58. "CPACK_CYGWIN_PATCH_NUMBER not specified using 1"
  59. << std::endl);
  60. }
  61. this->OutputExtension += patchNumber;
  62. this->OutputExtension += ".tar.bz2";
  63. return this->OutputExtension.c_str();
  64. }