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