cmInstallGenerator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst 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. char const* permissions_file = nullptr,
  43. char const* permissions_dir = nullptr, char const* rename = nullptr,
  44. char const* literal_args = nullptr, Indent indent = Indent(),
  45. char const* 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(std::string const& 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(std::string const& component,
  62. bool exclude_from_all,
  63. bool all_components = false);
  64. using TweakMethod =
  65. std::function<void(std::ostream& os, Indent indent,
  66. std::string const& config, std::string const& file)>;
  67. static void AddTweak(std::ostream& os, Indent indent,
  68. std::string const& config, std::string const& file,
  69. TweakMethod const& tweak);
  70. static void AddTweak(std::ostream& os, Indent indent,
  71. std::string const& config, std::string const& dir,
  72. std::vector<std::string> const& files,
  73. TweakMethod const& tweak);
  74. // Information shared by most generator types.
  75. std::string Destination;
  76. std::string const Component;
  77. MessageLevel const Message;
  78. bool const ExcludeFromAll;
  79. bool const AllComponents;
  80. cmListFileBacktrace const Backtrace;
  81. };