cmExportBuildFileGenerator.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <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(
  68. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  69. std::vector<std::string> const& exportFiles) const;
  70. void ComplainAboutDuplicateTarget(
  71. std::string const& targetName) const override;
  72. void ReportError(std::string const& errorMessage) const override;
  73. /** Fill in properties indicating built file locations. */
  74. void SetImportLocationProperty(std::string const& config,
  75. std::string const& suffix,
  76. cmGeneratorTarget* target,
  77. ImportPropertyMap& properties);
  78. std::string InstallNameDir(cmGeneratorTarget const* target,
  79. std::string const& config) override;
  80. cmExportSet* GetExportSet() const override { return this->ExportSet; }
  81. std::string GetCxxModulesDirectory() const override
  82. {
  83. return this->CxxModulesDirectory;
  84. }
  85. ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override;
  86. using cmExportFileGenerator::PopulateInterfaceProperties;
  87. bool PopulateInterfaceProperties(cmGeneratorTarget const* target,
  88. ImportPropertyMap& properties);
  89. struct TargetExportPrivate
  90. {
  91. TargetExportPrivate(cmGeneratorTarget* target,
  92. std::string xcFrameworkLocation)
  93. : Target(target)
  94. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  95. {
  96. }
  97. cmGeneratorTarget* Target;
  98. std::string XcFrameworkLocation;
  99. };
  100. std::vector<TargetExport> Targets;
  101. cmExportSet* ExportSet;
  102. std::vector<TargetExportPrivate> Exports;
  103. cmLocalGenerator* LG;
  104. // The directory for C++ module information.
  105. std::string CxxModulesDirectory;
  106. };