cmCPackArchiveGenerator.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <iosfwd>
  6. #include <string>
  7. #include "cmArchiveWrite.h"
  8. #include "cmCPackGenerator.h"
  9. class cmCPackComponent;
  10. /** \class cmCPackArchiveGenerator
  11. * \brief A generator base for libarchive generation.
  12. * The generator itself uses the libarchive wrapper
  13. * \ref cmArchiveWrite.
  14. *
  15. */
  16. class cmCPackArchiveGenerator : public cmCPackGenerator
  17. {
  18. public:
  19. using Superclass = cmCPackGenerator;
  20. static cmCPackGenerator* Create7ZGenerator();
  21. static cmCPackGenerator* CreateTBZ2Generator();
  22. static cmCPackGenerator* CreateTGZGenerator();
  23. static cmCPackGenerator* CreateTXZGenerator();
  24. static cmCPackGenerator* CreateTZGenerator();
  25. static cmCPackGenerator* CreateTZSTGenerator();
  26. static cmCPackGenerator* CreateZIPGenerator();
  27. /**
  28. * Construct generator
  29. */
  30. cmCPackArchiveGenerator(cmArchiveWrite::Compress t, std::string format,
  31. std::string extension);
  32. ~cmCPackArchiveGenerator() override;
  33. // Used to add a header to the archive
  34. virtual int GenerateHeader(std::ostream* os);
  35. // component support
  36. bool SupportsComponentInstallation() const override;
  37. private:
  38. // get archive component filename
  39. std::string GetArchiveComponentFileName(std::string const& component,
  40. bool isGroupName);
  41. class Deduplicator;
  42. protected:
  43. int InitializeInternal() override;
  44. /**
  45. * Add the files belonging to the specified component
  46. * to the provided (already opened) archive.
  47. * @param[in,out] archive the archive object
  48. * @param[in] component the component whose file will be added to archive
  49. * @param[in] deduplicator file deduplicator utility.
  50. */
  51. int addOneComponentToArchive(cmArchiveWrite& archive,
  52. cmCPackComponent* component,
  53. Deduplicator* deduplicator);
  54. /**
  55. * The main package file method.
  56. * If component install was required this
  57. * method will call either PackageComponents or
  58. * PackageComponentsAllInOne.
  59. */
  60. int PackageFiles() override;
  61. /**
  62. * The method used to package files when component
  63. * install is used. This will create one
  64. * archive for each component group.
  65. */
  66. int PackageComponents(bool ignoreGroup);
  67. /**
  68. * Special case of component install where all
  69. * components will be put in a single installer.
  70. */
  71. int PackageComponentsAllInOne();
  72. private:
  73. char const* GetNameOfClass() override { return "cmCPackArchiveGenerator"; }
  74. char const* GetOutputExtension() override
  75. {
  76. return this->OutputExtension.c_str();
  77. }
  78. int GetThreadCount() const;
  79. private:
  80. cmArchiveWrite::Compress Compress;
  81. std::string ArchiveFormat;
  82. std::string OutputExtension;
  83. };