cmExportBuildFileGenerator.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <string>
  7. #include <utility>
  8. #include <vector>
  9. #include <cmext/algorithm>
  10. #include "cmExportFileGenerator.h"
  11. #include "cmStateTypes.h"
  12. class cmExportSet;
  13. class cmGeneratorTarget;
  14. class cmLocalGenerator;
  15. /** \class cmExportBuildCMakeConfigGenerator
  16. * \brief Generate a file exporting targets from a build tree.
  17. *
  18. * cmExportBuildCMakeConfigGenerator is the interface class for generating a
  19. * file exporting targets from a build tree.
  20. *
  21. * This is used to implement the export() command.
  22. */
  23. class cmExportBuildFileGenerator : virtual public cmExportFileGenerator
  24. {
  25. public:
  26. struct TargetExport
  27. {
  28. TargetExport(std::string name, std::string xcFrameworkLocation)
  29. : Name(std::move(name))
  30. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  31. {
  32. }
  33. std::string Name;
  34. std::string XcFrameworkLocation;
  35. };
  36. cmExportBuildFileGenerator();
  37. /** Set the list of targets to export. */
  38. void SetTargets(std::vector<TargetExport> const& targets)
  39. {
  40. this->Targets = targets;
  41. }
  42. void GetTargets(std::vector<TargetExport>& targets) const;
  43. void AppendTargets(std::vector<TargetExport> const& targets)
  44. {
  45. cm::append(this->Targets, targets);
  46. }
  47. void SetExportSet(cmExportSet*);
  48. /** Set the name of the C++ module directory. */
  49. void SetCxxModuleDirectory(std::string cxx_module_dir)
  50. {
  51. this->CxxModulesDirectory = std::move(cxx_module_dir);
  52. }
  53. std::string const& GetCxxModuleDirectory() const
  54. {
  55. return this->CxxModulesDirectory;
  56. }
  57. void Compute(cmLocalGenerator* lg);
  58. protected:
  59. cmStateEnums::TargetType GetExportTargetType(
  60. cmGeneratorTarget const* target) const;
  61. /** Walk the list of targets to be exported. Returns true iff no duplicates
  62. are found. */
  63. bool CollectExports(std::function<void(cmGeneratorTarget const*)> visitor);
  64. void HandleMissingTarget(std::string& link_libs,
  65. cmGeneratorTarget const* depender,
  66. cmGeneratorTarget* dependee) override;
  67. void ComplainAboutMissingTarget(cmGeneratorTarget const* depender,
  68. cmGeneratorTarget const* dependee,
  69. ExportInfo const& exportInfo) const;
  70. void ComplainAboutDuplicateTarget(
  71. std::string const& targetName) const override;
  72. void IssueMessage(MessageType type,
  73. std::string const& message) const override;
  74. /** Fill in properties indicating built file locations. */
  75. void SetImportLocationProperty(std::string const& config,
  76. std::string const& suffix,
  77. cmGeneratorTarget* target,
  78. ImportPropertyMap& properties);
  79. std::string InstallNameDir(cmGeneratorTarget const* target,
  80. std::string const& config) override;
  81. cmExportSet* GetExportSet() const override { return this->ExportSet; }
  82. std::string GetCxxModulesDirectory() const override
  83. {
  84. return this->CxxModulesDirectory;
  85. }
  86. ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
  87. using cmExportFileGenerator::PopulateInterfaceProperties;
  88. bool PopulateInterfaceProperties(cmGeneratorTarget const* target,
  89. ImportPropertyMap& properties);
  90. struct TargetExportPrivate
  91. {
  92. TargetExportPrivate(cmGeneratorTarget* target,
  93. std::string xcFrameworkLocation)
  94. : Target(target)
  95. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  96. {
  97. }
  98. cmGeneratorTarget* Target;
  99. std::string XcFrameworkLocation;
  100. };
  101. std::vector<TargetExport> Targets;
  102. cmExportSet* ExportSet;
  103. std::vector<TargetExportPrivate> Exports;
  104. cmLocalGenerator* LG;
  105. // The directory for C++ module information.
  106. std::string CxxModulesDirectory;
  107. };