cmInstallTargetGenerator.h 4.9 KB

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