cmGlobalGeneratorFactory.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmGlobalGeneratorFactory_h
  4. #define cmGlobalGeneratorFactory_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <vector>
  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() {}
  20. /** Create a GlobalGenerator */
  21. virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& n,
  22. 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 void GetGenerators(std::vector<std::string>& names) const = 0;
  27. /** Determine whether or not this generator supports toolsets */
  28. virtual bool SupportsToolset() const = 0;
  29. /** Determine whether or not this generator supports platforms */
  30. virtual bool SupportsPlatform() const = 0;
  31. };
  32. template <class T>
  33. class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory
  34. {
  35. public:
  36. /** Create a GlobalGenerator */
  37. cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
  38. cmake* cm) const override
  39. {
  40. if (name != T::GetActualName()) {
  41. return nullptr;
  42. }
  43. return new T(cm);
  44. }
  45. /** Get the documentation entry for this factory */
  46. void GetDocumentation(cmDocumentationEntry& entry) const override
  47. {
  48. T::GetDocumentation(entry);
  49. }
  50. /** Get the names of the current registered generators */
  51. void GetGenerators(std::vector<std::string>& names) const override
  52. {
  53. names.push_back(T::GetActualName());
  54. }
  55. /** Determine whether or not this generator supports toolsets */
  56. bool SupportsToolset() const override { return T::SupportsToolset(); }
  57. /** Determine whether or not this generator supports platforms */
  58. bool SupportsPlatform() const override { return T::SupportsPlatform(); }
  59. };
  60. #endif