cmGlobalGeneratorFactory.h 2.9 KB

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