cmGlobalGeneratorFactory.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. // TODO The following headers are parts of the `cmGlobalGeneratorFactory`
  7. // public API, so could be defined as export to IWYU
  8. #include <string>
  9. #include <vector>
  10. #include <cm/memory>
  11. class cmGlobalGenerator;
  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, bool allowArch, 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. virtual std::vector<std::string> GetGeneratorNamesWithPlatform() const = 0;
  30. /** Determine whether or not this generator supports toolsets */
  31. virtual bool SupportsToolset() const = 0;
  32. /** Determine whether or not this generator supports platforms */
  33. virtual bool SupportsPlatform() const = 0;
  34. /** Get the list of supported platforms name for this generator */
  35. virtual std::vector<std::string> GetKnownPlatforms() const = 0;
  36. /** If the generator supports platforms, get its default. */
  37. virtual std::string GetDefaultPlatformName() const = 0;
  38. };
  39. template <typename T>
  40. class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory
  41. {
  42. public:
  43. /** Create a GlobalGenerator */
  44. std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
  45. const std::string& name, bool /*allowArch*/, cmake* cm) const override
  46. {
  47. if (name != T::GetActualName()) {
  48. return std::unique_ptr<cmGlobalGenerator>();
  49. }
  50. return std::unique_ptr<cmGlobalGenerator>(cm::make_unique<T>(cm));
  51. }
  52. /** Get the documentation entry for this factory */
  53. cmDocumentationEntry GetDocumentation() const override
  54. {
  55. return T::GetDocumentation();
  56. }
  57. /** Get the names of the current registered generators */
  58. std::vector<std::string> GetGeneratorNames() const override
  59. {
  60. return { T::GetActualName() };
  61. }
  62. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  63. {
  64. return {};
  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 {};
  75. }
  76. std::string GetDefaultPlatformName() const override { return {}; }
  77. };