cmGlobalGeneratorFactory.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <class 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. std::vector<std::string> names;
  59. names.push_back(T::GetActualName());
  60. return names;
  61. }
  62. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  63. {
  64. return std::vector<std::string>();
  65. }
  66. /** Determine whether or not this generator supports toolsets */
  67. bool SupportsToolset() const override { return T::SupportsToolset(); }
  68. /** Determine whether or not this generator supports platforms */
  69. bool SupportsPlatform() const override { return T::SupportsPlatform(); }
  70. /** Get the list of supported platforms name for this generator */
  71. std::vector<std::string> GetKnownPlatforms() const override
  72. {
  73. // default is no platform supported
  74. return std::vector<std::string>();
  75. }
  76. std::string GetDefaultPlatformName() const override { return std::string(); }
  77. };