cmExportBuildFileGenerator.h 4.0 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 <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 cmGlobalGenerator;
  15. class cmLocalGenerator;
  16. /** \class cmExportBuildCMakeConfigGenerator
  17. * \brief Generate a file exporting targets from a build tree.
  18. *
  19. * cmExportBuildCMakeConfigGenerator is the interface class for generating a
  20. * file exporting targets from a build tree.
  21. *
  22. * This is used to implement the export() command.
  23. */
  24. class cmExportBuildFileGenerator : virtual public cmExportFileGenerator
  25. {
  26. public:
  27. struct TargetExport
  28. {
  29. TargetExport(std::string name, std::string xcFrameworkLocation)
  30. : Name(std::move(name))
  31. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  32. {
  33. }
  34. std::string Name;
  35. std::string XcFrameworkLocation;
  36. };
  37. cmExportBuildFileGenerator();
  38. /** Set the list of targets to export. */
  39. void SetTargets(std::vector<TargetExport> const& targets)
  40. {
  41. this->Targets = targets;
  42. }
  43. void GetTargets(std::vector<TargetExport>& targets) const;
  44. void AppendTargets(std::vector<TargetExport> const& targets)
  45. {
  46. cm::append(this->Targets, targets);
  47. }
  48. void SetExportSet(cmExportSet*);
  49. /** Set the name of the C++ module directory. */
  50. void SetCxxModuleDirectory(std::string cxx_module_dir)
  51. {
  52. this->CxxModulesDirectory = std::move(cxx_module_dir);
  53. }
  54. std::string const& GetCxxModuleDirectory() const
  55. {
  56. return this->CxxModulesDirectory;
  57. }
  58. void Compute(cmLocalGenerator* lg);
  59. protected:
  60. cmStateEnums::TargetType GetExportTargetType(
  61. cmGeneratorTarget const* target) const;
  62. /** Walk the list of targets to be exported. Returns true iff no duplicates
  63. are found. */
  64. bool CollectExports(std::function<void(cmGeneratorTarget const*)> visitor);
  65. void HandleMissingTarget(std::string& link_libs,
  66. cmGeneratorTarget const* depender,
  67. cmGeneratorTarget* dependee) override;
  68. void ComplainAboutMissingTarget(
  69. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  70. std::vector<std::string> const& namespaces) const;
  71. void ComplainAboutDuplicateTarget(
  72. std::string const& targetName) const override;
  73. void ReportError(std::string const& errorMessage) 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. std::pair<std::vector<std::string>, std::string> FindBuildExportInfo(
  87. cmGlobalGenerator* gg, std::string const& name);
  88. using cmExportFileGenerator::PopulateInterfaceProperties;
  89. bool PopulateInterfaceProperties(cmGeneratorTarget const* target,
  90. ImportPropertyMap& properties);
  91. struct TargetExportPrivate
  92. {
  93. TargetExportPrivate(cmGeneratorTarget* target,
  94. std::string xcFrameworkLocation)
  95. : Target(target)
  96. , XcFrameworkLocation(std::move(xcFrameworkLocation))
  97. {
  98. }
  99. cmGeneratorTarget* Target;
  100. std::string XcFrameworkLocation;
  101. };
  102. std::vector<TargetExport> Targets;
  103. cmExportSet* ExportSet;
  104. std::vector<TargetExportPrivate> Exports;
  105. cmLocalGenerator* LG;
  106. // The directory for C++ module information.
  107. std::string CxxModulesDirectory;
  108. };