cmExportInstallFileGenerator.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <map>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include <cm/string_view>
  11. #include "cmExportFileGenerator.h"
  12. #include "cmGeneratorExpression.h"
  13. #include "cmInstallExportGenerator.h"
  14. #include "cmStateTypes.h"
  15. class cmExportSet;
  16. class cmGeneratorTarget;
  17. class cmInstallTargetGenerator;
  18. class cmTargetExport;
  19. /** \class cmExportInstallFileGenerator
  20. * \brief Generate a file exporting targets from an install tree.
  21. *
  22. * cmExportInstallFileGenerator is the generic interface class for generating
  23. * export files for an install tree.
  24. */
  25. class cmExportInstallFileGenerator : virtual public cmExportFileGenerator
  26. {
  27. public:
  28. /** Construct with the export installer that will install the
  29. files. */
  30. cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
  31. /** Get the per-config file generated for each configuration. This
  32. maps from the configuration name to the file temporary location
  33. for installation. */
  34. std::map<std::string, std::string> const& GetConfigImportFiles()
  35. {
  36. return this->ConfigImportFiles;
  37. }
  38. /** Get the temporary location of the config-agnostic C++ module file. */
  39. std::string GetCxxModuleFile() const;
  40. /** Get the per-config C++ module file generated for each configuration.
  41. This maps from the configuration name to the file temporary location
  42. for installation. */
  43. std::map<std::string, std::string> const& GetConfigCxxModuleFiles()
  44. {
  45. return this->ConfigCxxModuleFiles;
  46. }
  47. /** Get the per-config C++ module file generated for each configuration.
  48. This maps from the configuration name to the file temporary location
  49. for installation for each target in the export set. */
  50. std::map<std::string, std::vector<std::string>> const&
  51. GetConfigCxxModuleTargetFiles()
  52. {
  53. return this->ConfigCxxModuleTargetFiles;
  54. }
  55. /** Compute the globbing expression used to load per-config import
  56. files from the main file. */
  57. virtual std::string GetConfigImportFileGlob() const = 0;
  58. protected:
  59. cmStateEnums::TargetType GetExportTargetType(
  60. cmTargetExport const* targetExport) const;
  61. virtual std::string const& GetExportName() const;
  62. std::string GetInstallPrefix() const
  63. {
  64. cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash();
  65. return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
  66. }
  67. void HandleMissingTarget(std::string& link_libs,
  68. cmGeneratorTarget const* depender,
  69. cmGeneratorTarget* dependee) override;
  70. void ReplaceInstallPrefix(std::string& input) const override;
  71. void ComplainAboutMissingTarget(
  72. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  73. std::vector<std::string> const& exportFiles) const;
  74. void ComplainAboutDuplicateTarget(
  75. std::string const& targetName) const override;
  76. ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
  77. void ReportError(std::string const& errorMessage) const override;
  78. /** Fill in properties indicating installed file locations. */
  79. void SetImportLocationProperty(std::string const& config,
  80. std::string const& suffix,
  81. cmInstallTargetGenerator* itgen,
  82. ImportPropertyMap& properties,
  83. std::set<std::string>& importedLocations);
  84. std::string InstallNameDir(cmGeneratorTarget const* target,
  85. std::string const& config) override;
  86. using cmExportFileGenerator::GetCxxModuleFile;
  87. /** Walk the list of targets to be exported. Returns true iff no duplicates
  88. are found. */
  89. bool CollectExports(
  90. std::function<void(cmTargetExport const*)> const& visitor);
  91. cmExportSet* GetExportSet() const override
  92. {
  93. return this->IEGen->GetExportSet();
  94. }
  95. std::string GetImportXcFrameworkLocation(
  96. std::string const& config, cmTargetExport const* targetExport) const;
  97. using cmExportFileGenerator::PopulateInterfaceProperties;
  98. bool PopulateInterfaceProperties(cmTargetExport const* targetExport,
  99. ImportPropertyMap& properties);
  100. void PopulateImportProperties(std::string const& config,
  101. std::string const& suffix,
  102. cmTargetExport const* targetExport,
  103. ImportPropertyMap& properties,
  104. std::set<std::string>& importedLocations);
  105. cmInstallExportGenerator* IEGen;
  106. // The import file generated for each configuration.
  107. std::map<std::string, std::string> ConfigImportFiles;
  108. // The C++ module property file generated for each configuration.
  109. std::map<std::string, std::string> ConfigCxxModuleFiles;
  110. // The C++ module property target files generated for each configuration.
  111. std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
  112. private:
  113. void PopulateCompatibleInterfaceProperties(cmGeneratorTarget const* target,
  114. ImportPropertyMap& properties);
  115. void PopulateCustomTransitiveInterfaceProperties(
  116. cmGeneratorTarget const* target,
  117. cmGeneratorExpression::PreprocessContext preprocessRule,
  118. ImportPropertyMap& properties);
  119. void PopulateIncludeDirectoriesInterface(
  120. cmGeneratorTarget const* target,
  121. cmGeneratorExpression::PreprocessContext preprocessRule,
  122. ImportPropertyMap& properties, cmTargetExport const& te,
  123. std::string& includesDestinationDirs);
  124. void PopulateSourcesInterface(
  125. cmGeneratorTarget const* target,
  126. cmGeneratorExpression::PreprocessContext preprocessRule,
  127. ImportPropertyMap& properties);
  128. void PopulateLinkDirectoriesInterface(
  129. cmGeneratorTarget const* target,
  130. cmGeneratorExpression::PreprocessContext preprocessRule,
  131. ImportPropertyMap& properties);
  132. void PopulateLinkDependsInterface(
  133. cmGeneratorTarget const* target,
  134. cmGeneratorExpression::PreprocessContext preprocessRule,
  135. ImportPropertyMap& properties);
  136. };