cmInstallTargetGenerator.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. void SetImportlinkMode(NamelinkModeType mode)
  37. {
  38. this->ImportlinkMode = mode;
  39. }
  40. std::string GetInstallFilename(const std::string& config) const;
  41. void GetInstallObjectNames(std::string const& config,
  42. std::vector<std::string>& objects) const;
  43. enum NameType
  44. {
  45. NameNormal,
  46. NameImplib,
  47. NameSO,
  48. NameReal,
  49. NameImplibReal
  50. };
  51. static std::string GetInstallFilename(const cmGeneratorTarget* target,
  52. const std::string& config,
  53. NameType nameType = NameNormal);
  54. bool Compute(cmLocalGenerator* lg) override;
  55. cmGeneratorTarget* GetTarget() const { return this->Target; }
  56. bool IsImportLibrary() const { return this->ImportLibrary; }
  57. std::string GetDestination(std::string const& config) const;
  58. struct Files
  59. {
  60. // Names or paths of files to be read from the source or build tree.
  61. // The paths may be computed as [FromDir/] + From[i].
  62. std::vector<std::string> From;
  63. // Corresponding names of files to be written in the install directory.
  64. // The paths may be computed as Destination/ + [ToDir/] + To[i].
  65. std::vector<std::string> To;
  66. // Prefix for all files in From.
  67. std::string FromDir;
  68. // Prefix for all files in To.
  69. std::string ToDir;
  70. NamelinkModeType NamelinkMode = NamelinkModeNone;
  71. bool NoTweak = false;
  72. bool UseSourcePermissions = false;
  73. cmInstallType Type = cmInstallType();
  74. };
  75. Files GetFiles(std::string const& config) const;
  76. bool GetOptional() const { return this->Optional; }
  77. protected:
  78. void GenerateScriptForConfig(std::ostream& os, const std::string& config,
  79. Indent indent) override;
  80. void PreReplacementTweaks(std::ostream& os, Indent indent,
  81. const std::string& config,
  82. std::string const& file);
  83. void PostReplacementTweaks(std::ostream& os, Indent indent,
  84. const std::string& config,
  85. std::string const& file);
  86. void AddInstallNamePatchRule(std::ostream& os, Indent indent,
  87. const std::string& config,
  88. const std::string& toDestDirPath);
  89. void AddChrpathPatchRule(std::ostream& os, Indent indent,
  90. const std::string& config,
  91. std::string const& toDestDirPath);
  92. void AddRPathCheckRule(std::ostream& os, Indent indent,
  93. const std::string& config,
  94. std::string const& toDestDirPath);
  95. void AddStripRule(std::ostream& os, Indent indent,
  96. const std::string& toDestDirPath);
  97. void AddRanlibRule(std::ostream& os, Indent indent,
  98. const std::string& toDestDirPath);
  99. void AddUniversalInstallRule(std::ostream& os, Indent indent,
  100. const std::string& toDestDirPath);
  101. void IssueCMP0095Warning(const std::string& unescapedRpath);
  102. std::string const TargetName;
  103. cmGeneratorTarget* Target = nullptr;
  104. std::string const FilePermissions;
  105. NamelinkModeType NamelinkMode;
  106. NamelinkModeType ImportlinkMode;
  107. bool const ImportLibrary;
  108. bool const Optional;
  109. };