cmExportInstallFileGenerator.h 6.2 KB

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