cmExportInstallFileGenerator.h 5.3 KB

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