cmGlobalGeneratorFactory.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <string>
  6. #include <vector>
  7. #include <cm/memory>
  8. class cmGlobalGenerator;
  9. class cmake;
  10. struct cmDocumentationEntry;
  11. /** \class cmGlobalGeneratorFactory
  12. * \brief Responable for creating cmGlobalGenerator instances
  13. *
  14. * Subclasses of this class generate instances of cmGlobalGenerator.
  15. */
  16. class cmGlobalGeneratorFactory
  17. {
  18. public:
  19. virtual ~cmGlobalGeneratorFactory() = default;
  20. /** Create a GlobalGenerator */
  21. virtual std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  22. const std::string& n, bool allowArch, cmake* cm) const = 0;
  23. /** Get the documentation entry for this factory */
  24. virtual void GetDocumentation(cmDocumentationEntry& entry) const = 0;
  25. /** Get the names of the current registered generators */
  26. virtual std::vector<std::string> GetGeneratorNames() const = 0;
  27. virtual std::vector<std::string> GetGeneratorNamesWithPlatform() const = 0;
  28. /** Determine whether or not this generator supports toolsets */
  29. virtual bool SupportsToolset() const = 0;
  30. /** Determine whether or not this generator supports platforms */
  31. virtual bool SupportsPlatform() const = 0;
  32. /** Get the list of supported platforms name for this generator */
  33. virtual std::vector<std::string> GetKnownPlatforms() const = 0;
  34. /** If the generator supports platforms, get its default. */
  35. virtual std::string GetDefaultPlatformName() const = 0;
  36. };
  37. template <typename T>
  38. class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory
  39. {
  40. public:
  41. /** Create a GlobalGenerator */
  42. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  43. const std::string& name, bool /*allowArch*/, cmake* cm) const override
  44. {
  45. if (name != T::GetActualName()) {
  46. return std::unique_ptr<cmGlobalGenerator>();
  47. }
  48. return std::unique_ptr<cmGlobalGenerator>(cm::make_unique<T>(cm));
  49. }
  50. /** Get the documentation entry for this factory */
  51. void GetDocumentation(cmDocumentationEntry& entry) const override
  52. {
  53. T::GetDocumentation(entry);
  54. }
  55. /** Get the names of the current registered generators */
  56. std::vector<std::string> GetGeneratorNames() const override
  57. {
  58. return { T::GetActualName() };
  59. }
  60. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  61. {
  62. return {};
  63. }
  64. /** Determine whether or not this generator supports toolsets */
  65. bool SupportsToolset() const override { return T::SupportsToolset(); }
  66. /** Determine whether or not this generator supports platforms */
  67. bool SupportsPlatform() const override { return T::SupportsPlatform(); }
  68. /** Get the list of supported platforms name for this generator */
  69. std::vector<std::string> GetKnownPlatforms() const override
  70. {
  71. // default is no platform supported
  72. return {};
  73. }
  74. std::string GetDefaultPlatformName() const override { return {}; }
  75. };