cmExportInstallFileGenerator.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. virtual char GetConfigFileNameSeparator() const = 0;
  68. void HandleMissingTarget(std::string& link_libs,
  69. cmGeneratorTarget const* depender,
  70. cmGeneratorTarget* dependee) override;
  71. void ReplaceInstallPrefix(std::string& input) const override;
  72. void ComplainAboutMissingTarget(
  73. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  74. std::vector<std::string> const& exportFiles) const;
  75. void ComplainAboutDuplicateTarget(
  76. std::string const& targetName) const override;
  77. ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
  78. void ReportError(std::string const& errorMessage) const override;
  79. /** Generate a per-configuration file for the targets. */
  80. virtual bool GenerateImportFileConfig(std::string const& config);
  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. };