cmInstallTargetGenerator.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 <vector>
  8. #include "cmInstallGenerator.h"
  9. #include "cmInstallType.h"
  10. #include "cmListFileCache.h"
  11. class cmGeneratorTarget;
  12. class cmLocalGenerator;
  13. /** \class cmInstallTargetGenerator
  14. * \brief Generate target installation rules.
  15. */
  16. class cmInstallTargetGenerator : public cmInstallGenerator
  17. {
  18. public:
  19. cmInstallTargetGenerator(
  20. std::string targetName, std::string const& dest, bool implib,
  21. std::string file_permissions,
  22. std::vector<std::string> const& configurations,
  23. std::string const& component, MessageLevel message, bool exclude_from_all,
  24. bool optional, cmListFileBacktrace backtrace = cmListFileBacktrace());
  25. ~cmInstallTargetGenerator() override;
  26. /** Select the policy for installing shared library linkable name
  27. symlinks. */
  28. enum NamelinkModeType
  29. {
  30. NamelinkModeNone,
  31. NamelinkModeOnly,
  32. NamelinkModeSkip
  33. };
  34. void SetNamelinkMode(NamelinkModeType mode) { this->NamelinkMode = mode; }
  35. void SetImportlinkMode(NamelinkModeType mode)
  36. {
  37. this->ImportlinkMode = mode;
  38. }
  39. std::string GetInstallFilename(const std::string& config) const;
  40. void GetInstallObjectNames(std::string const& config,
  41. std::vector<std::string>& objects) const;
  42. enum NameType
  43. {
  44. NameNormal,
  45. NameImplib,
  46. NameSO,
  47. NameReal,
  48. NameImplibReal
  49. };
  50. static std::string GetInstallFilename(const cmGeneratorTarget* target,
  51. const std::string& config,
  52. NameType nameType = NameNormal);
  53. bool Compute(cmLocalGenerator* lg) override;
  54. cmGeneratorTarget* GetTarget() const { return this->Target; }
  55. bool IsImportLibrary() const { return this->ImportLibrary; }
  56. std::string GetDestination(std::string const& config) const;
  57. struct Files
  58. {
  59. // Names or paths of files to be read from the source or build tree.
  60. // The paths may be computed as [FromDir/] + From[i].
  61. std::vector<std::string> From;
  62. // Corresponding names of files to be written in the install directory.
  63. // The paths may be computed as Destination/ + [ToDir/] + To[i].
  64. std::vector<std::string> To;
  65. // Prefix for all files in From.
  66. std::string FromDir;
  67. // Prefix for all files in To.
  68. std::string ToDir;
  69. NamelinkModeType NamelinkMode = NamelinkModeNone;
  70. bool NoTweak = false;
  71. bool UseSourcePermissions = false;
  72. cmInstallType Type = cmInstallType();
  73. };
  74. Files GetFiles(std::string const& config) const;
  75. bool GetOptional() const { return this->Optional; }
  76. protected:
  77. void GenerateScriptForConfig(std::ostream& os, const std::string& config,
  78. Indent indent) override;
  79. void PreReplacementTweaks(std::ostream& os, Indent indent,
  80. const std::string& config,
  81. std::string const& file);
  82. void PostReplacementTweaks(std::ostream& os, Indent indent,
  83. const std::string& config,
  84. std::string const& file);
  85. void AddInstallNamePatchRule(std::ostream& os, Indent indent,
  86. const std::string& config,
  87. const std::string& toDestDirPath);
  88. void AddChrpathPatchRule(std::ostream& os, Indent indent,
  89. const std::string& config,
  90. std::string const& toDestDirPath);
  91. void AddRPathCheckRule(std::ostream& os, Indent indent,
  92. const std::string& config,
  93. std::string const& toDestDirPath);
  94. void AddStripRule(std::ostream& os, Indent indent,
  95. const std::string& toDestDirPath);
  96. void AddRanlibRule(std::ostream& os, Indent indent,
  97. const std::string& toDestDirPath);
  98. void AddUniversalInstallRule(std::ostream& os, Indent indent,
  99. const std::string& toDestDirPath);
  100. void IssueCMP0095Warning(const std::string& unescapedRpath);
  101. std::string const TargetName;
  102. cmGeneratorTarget* Target = nullptr;
  103. std::string const FilePermissions;
  104. NamelinkModeType NamelinkMode;
  105. NamelinkModeType ImportlinkMode;
  106. bool const ImportLibrary;
  107. bool const Optional;
  108. };