cmExportInstallFileGenerator.h 6.7 KB

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