cmCPackCygwinBinaryGenerator.cxx 2.4 KB

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