cmInstallGenerator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <functional>
  6. #include <iosfwd>
  7. #include <string>
  8. #include <vector>
  9. #include "cmInstallType.h"
  10. #include "cmListFileCache.h"
  11. #include "cmScriptGenerator.h"
  12. class cmLocalGenerator;
  13. class cmMakefile;
  14. /** \class cmInstallGenerator
  15. * \brief Support class for generating install scripts.
  16. *
  17. */
  18. class cmInstallGenerator : public cmScriptGenerator
  19. {
  20. public:
  21. enum MessageLevel
  22. {
  23. MessageDefault,
  24. MessageAlways,
  25. MessageLazy,
  26. MessageNever
  27. };
  28. cmInstallGenerator(std::string destination,
  29. std::vector<std::string> const& configurations,
  30. std::string component, MessageLevel message,
  31. bool exclude_from_all, bool all_components,
  32. cmListFileBacktrace backtrace);
  33. ~cmInstallGenerator() override;
  34. cmInstallGenerator(cmInstallGenerator const&) = delete;
  35. cmInstallGenerator& operator=(cmInstallGenerator const&) = delete;
  36. virtual bool HaveInstall();
  37. virtual void CheckCMP0082(bool& haveSubdirectoryInstall,
  38. bool& haveInstallAfterSubdirectory);
  39. void AddInstallRule(
  40. std::ostream& os, std::string const& dest, cmInstallType type,
  41. std::vector<std::string> const& files, bool optional = false,
  42. const char* permissions_file = nullptr,
  43. const char* permissions_dir = nullptr, const char* rename = nullptr,
  44. const char* literal_args = nullptr, Indent indent = Indent(),
  45. const char* files_var = nullptr);
  46. /** Get the install destination as it should appear in the
  47. installation script. */
  48. static std::string ConvertToAbsoluteDestination(std::string const& dest);
  49. /** Test if this generator installs something for a given configuration. */
  50. bool InstallsForConfig(const std::string& config);
  51. /** Select message level from CMAKE_INSTALL_MESSAGE or 'never'. */
  52. static MessageLevel SelectMessageLevel(cmMakefile* mf, bool never = false);
  53. virtual bool Compute(cmLocalGenerator*) { return true; }
  54. std::string const& GetComponent() const { return this->Component; }
  55. bool GetExcludeFromAll() const { return this->ExcludeFromAll; }
  56. bool GetAllComponentsFlag() const { return this->AllComponents; }
  57. cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; }
  58. static std::string GetDestDirPath(std::string const& file);
  59. protected:
  60. void GenerateScript(std::ostream& os) override;
  61. std::string CreateComponentTest(const std::string& component,
  62. bool exclude_from_all);
  63. using TweakMethod =
  64. std::function<void(std::ostream& os, Indent indent,
  65. const std::string& config, const std::string& file)>;
  66. static void AddTweak(std::ostream& os, Indent indent,
  67. const std::string& config, std::string const& file,
  68. const TweakMethod& tweak);
  69. static void AddTweak(std::ostream& os, Indent indent,
  70. const std::string& config, std::string const& dir,
  71. std::vector<std::string> const& files,
  72. const TweakMethod& tweak);
  73. // Information shared by most generator types.
  74. std::string const Destination;
  75. std::string const Component;
  76. MessageLevel const Message;
  77. bool const ExcludeFromAll;
  78. bool const AllComponents;
  79. cmListFileBacktrace const Backtrace;
  80. };