cmExportBuildCMakeConfigGenerator.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <string>
  7. #include <utility>
  8. #include <vector>
  9. #include <cmext/algorithm>
  10. #include "cmExportFileGenerator.h"
  11. #include "cmStateTypes.h"
  12. class cmExportSet;
  13. class cmFileSet;
  14. class cmGeneratorTarget;
  15. class cmGlobalGenerator;
  16. class cmLocalGenerator;
  17. class cmTargetExport;
  18. /** \class cmExportBuildCMakeConfigGenerator
  19. * \brief Generate a file exporting targets from a build tree.
  20. *
  21. * cmExportBuildCMakeConfigGenerator generates a file exporting targets from
  22. * a build tree. A single file exports information for all
  23. * configurations built.
  24. *
  25. * This is used to implement the export() command.
  26. */
  27. class cmExportBuildCMakeConfigGenerator : public cmExportFileGenerator
  28. {
  29. public:
  30. struct TargetExport
  31. {
  32. TargetExport(std::string name, std::string xcFrameworkLocation)
  33. : Name(std::move(name))
  34. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  35. {
  36. }
  37. std::string Name;
  38. std::string XcFrameworkLocation;
  39. };
  40. cmExportBuildCMakeConfigGenerator();
  41. /** Set the list of targets to export. */
  42. void SetTargets(std::vector<TargetExport> const& targets)
  43. {
  44. this->Targets = targets;
  45. }
  46. void GetTargets(std::vector<TargetExport>& targets) const;
  47. void AppendTargets(std::vector<TargetExport> const& targets)
  48. {
  49. cm::append(this->Targets, targets);
  50. }
  51. void SetExportSet(cmExportSet*);
  52. /** Set the name of the C++ module directory. */
  53. void SetCxxModuleDirectory(std::string cxx_module_dir)
  54. {
  55. this->CxxModulesDirectory = std::move(cxx_module_dir);
  56. }
  57. std::string const& GetCxxModuleDirectory() const
  58. {
  59. return this->CxxModulesDirectory;
  60. }
  61. /** Set whether to append generated code to the output file. */
  62. void SetAppendMode(bool append) { this->AppendMode = append; }
  63. void Compute(cmLocalGenerator* lg);
  64. protected:
  65. // Implement virtual methods from the superclass.
  66. bool GenerateMainFile(std::ostream& os) override;
  67. void GenerateImportTargetsConfig(std::ostream& os, std::string const& config,
  68. std::string const& suffix) override;
  69. cmStateEnums::TargetType GetExportTargetType(
  70. cmGeneratorTarget const* target) const;
  71. void HandleMissingTarget(std::string& link_libs,
  72. cmGeneratorTarget const* depender,
  73. cmGeneratorTarget* dependee) override;
  74. void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
  75. cmGeneratorTarget const* dependee,
  76. std::vector<std::string> const& namespaces);
  77. /** Fill in properties indicating built file locations. */
  78. void SetImportLocationProperty(std::string const& config,
  79. std::string const& suffix,
  80. cmGeneratorTarget* target,
  81. ImportPropertyMap& properties);
  82. std::string InstallNameDir(cmGeneratorTarget const* target,
  83. std::string const& config) override;
  84. std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet,
  85. cmTargetExport* te) override;
  86. std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
  87. cmTargetExport* te) override;
  88. cmExportSet* GetExportSet() const override { return this->ExportSet; }
  89. std::string GetCxxModulesDirectory() const override;
  90. void GenerateCxxModuleConfigInformation(std::string const&,
  91. std::ostream&) const override;
  92. bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&,
  93. std::string) const;
  94. std::pair<std::vector<std::string>, std::string> FindBuildExportInfo(
  95. cmGlobalGenerator* gg, std::string const& name);
  96. struct TargetExportPrivate
  97. {
  98. TargetExportPrivate(cmGeneratorTarget* target,
  99. std::string xcFrameworkLocation)
  100. : Target(target)
  101. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  102. {
  103. }
  104. cmGeneratorTarget* Target;
  105. std::string XcFrameworkLocation;
  106. };
  107. std::vector<TargetExport> Targets;
  108. cmExportSet* ExportSet;
  109. std::vector<TargetExportPrivate> Exports;
  110. cmLocalGenerator* LG;
  111. // The directory for C++ module information.
  112. std::string CxxModulesDirectory;
  113. };