cmExportInstallFileGenerator.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <map>
  7. #include <set>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include "cmExportFileGenerator.h"
  12. #include "cmInstallExportGenerator.h"
  13. #include "cmStateTypes.h"
  14. class cmExportSet;
  15. class cmFileSet;
  16. class cmGeneratorTarget;
  17. class cmGlobalGenerator;
  18. class cmInstallTargetGenerator;
  19. class cmTargetExport;
  20. /** \class cmExportInstallFileGenerator
  21. * \brief Generate a file exporting targets from an install tree.
  22. *
  23. * cmExportInstallFileGenerator generates files exporting targets from
  24. * install an installation tree. The files are placed in a temporary
  25. * location for installation by cmInstallExportGenerator. One main
  26. * file is generated that creates the imported targets and loads
  27. * per-configuration files. Target locations and settings for each
  28. * configuration are written to these per-configuration files. After
  29. * installation the main file loads the configurations that have been
  30. * installed.
  31. *
  32. * This is used to implement the INSTALL(EXPORT) command.
  33. */
  34. class cmExportInstallFileGenerator : public cmExportFileGenerator
  35. {
  36. public:
  37. /** Construct with the export installer that will install the
  38. files. */
  39. cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
  40. /** Get the per-config file generated for each configuration. This
  41. maps from the configuration name to the file temporary location
  42. for installation. */
  43. std::map<std::string, std::string> const& GetConfigImportFiles()
  44. {
  45. return this->ConfigImportFiles;
  46. }
  47. /** Get the temporary location of the config-agnostic C++ module file. */
  48. std::string GetCxxModuleFile() const;
  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. */
  52. std::map<std::string, std::string> const& GetConfigCxxModuleFiles()
  53. {
  54. return this->ConfigCxxModuleFiles;
  55. }
  56. /** Get the per-config C++ module file generated for each configuration.
  57. This maps from the configuration name to the file temporary location
  58. for installation for each target in the export set. */
  59. std::map<std::string, std::vector<std::string>> const&
  60. GetConfigCxxModuleTargetFiles()
  61. {
  62. return this->ConfigCxxModuleTargetFiles;
  63. }
  64. /** Compute the globbing expression used to load per-config import
  65. files from the main file. */
  66. std::string GetConfigImportFileGlob();
  67. protected:
  68. // Implement virtual methods from the superclass.
  69. bool GenerateMainFile(std::ostream& os) override;
  70. void GenerateImportTargetsConfig(std::ostream& os, const std::string& config,
  71. std::string const& suffix) override;
  72. cmStateEnums::TargetType GetExportTargetType(
  73. cmTargetExport const* targetExport) const;
  74. void HandleMissingTarget(std::string& link_libs,
  75. cmGeneratorTarget const* depender,
  76. cmGeneratorTarget* dependee) override;
  77. void ReplaceInstallPrefix(std::string& input) override;
  78. void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
  79. cmGeneratorTarget const* dependee,
  80. std::vector<std::string> const& exportFiles);
  81. std::pair<std::vector<std::string>, std::string> FindNamespaces(
  82. cmGlobalGenerator* gg, const std::string& name);
  83. /** Generate the relative import prefix. */
  84. virtual void GenerateImportPrefix(std::ostream&);
  85. /** Generate the relative import prefix. */
  86. virtual void LoadConfigFiles(std::ostream&);
  87. virtual void CleanupTemporaryVariables(std::ostream&);
  88. /** Generate a per-configuration file for the targets. */
  89. virtual bool GenerateImportFileConfig(const std::string& config);
  90. /** Fill in properties indicating installed file locations. */
  91. void SetImportLocationProperty(const std::string& config,
  92. std::string const& suffix,
  93. cmInstallTargetGenerator* itgen,
  94. ImportPropertyMap& properties,
  95. std::set<std::string>& importedLocations);
  96. std::string InstallNameDir(cmGeneratorTarget const* target,
  97. const std::string& config) override;
  98. std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet,
  99. cmTargetExport* te) override;
  100. std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
  101. cmTargetExport* te) override;
  102. using cmExportFileGenerator::GetCxxModuleFile;
  103. std::string GetCxxModulesDirectory() const override;
  104. void GenerateCxxModuleConfigInformation(std::string const&,
  105. std::ostream&) const override;
  106. bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&,
  107. std::string const&);
  108. cmExportSet* GetExportSet() const override
  109. {
  110. return this->IEGen->GetExportSet();
  111. }
  112. cmInstallExportGenerator* IEGen;
  113. // The import file generated for each configuration.
  114. std::map<std::string, std::string> ConfigImportFiles;
  115. // The C++ module property file generated for each configuration.
  116. std::map<std::string, std::string> ConfigCxxModuleFiles;
  117. // The C++ module property target files generated for each configuration.
  118. std::map<std::string, std::vector<std::string>> ConfigCxxModuleTargetFiles;
  119. };