cmExperimental.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmExperimental.h"
  4. #include <cassert>
  5. #include <cstddef>
  6. #include <string>
  7. #include "cmMakefile.h"
  8. #include "cmMessageType.h"
  9. #include "cmValue.h"
  10. namespace {
  11. /*
  12. * The `Uuid` fields of these objects should change periodically.
  13. * Search for other instances to keep the documentation and test suite
  14. * up-to-date.
  15. */
  16. cmExperimental::FeatureData LookupTable[] = {
  17. // ExportPackageDependencies
  18. { "ExportPackageDependencies",
  19. "1942b4fa-b2c5-4546-9385-83f254070067",
  20. "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES",
  21. "CMake's EXPORT_PACKAGE_DEPENDENCIES support is experimental. It is meant "
  22. "only for experimentation and feedback to CMake developers.",
  23. {},
  24. cmExperimental::TryCompileCondition::Always,
  25. false },
  26. // WindowsKernelModeDriver
  27. { "WindowsKernelModeDriver",
  28. "5c2d848d-4efa-4529-a768-efd57171bf68",
  29. "CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER",
  30. "CMake's Windows kernel-mode driver support is experimental. It is meant "
  31. "only for experimentation and feedback to CMake developers.",
  32. {},
  33. cmExperimental::TryCompileCondition::Always,
  34. false },
  35. // CxxImportStd
  36. { "CxxImportStd",
  37. "0e5b6991-d74f-4b3d-a41c-cf096e0b2508",
  38. "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD",
  39. "CMake's support for `import std;` in C++23 and newer is experimental. It "
  40. "is meant only for experimentation and feedback to CMake developers.",
  41. {},
  42. cmExperimental::TryCompileCondition::Always,
  43. false },
  44. // ExportPackageInfo
  45. { "ExportPackageInfo",
  46. "b80be207-778e-46ba-8080-b23bba22639e",
  47. "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO",
  48. "CMake's support for exporting package information in the Common Package "
  49. "Specification format. It is meant only for experimentation and feedback "
  50. "to CMake developers.",
  51. {},
  52. cmExperimental::TryCompileCondition::Always,
  53. false },
  54. // ExportBuildDatabase
  55. { "ExportBuildDatabase",
  56. "4bd552e2-b7fb-429a-ab23-c83ef53f3f13",
  57. "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE",
  58. "CMake's support for exporting build databases is experimental. It is "
  59. "meant only for experimentation and feedback to CMake developers.",
  60. {},
  61. cmExperimental::TryCompileCondition::Never,
  62. false },
  63. };
  64. static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
  65. static_cast<size_t>(cmExperimental::Feature::Sentinel),
  66. "Experimental feature lookup table mismatch");
  67. cmExperimental::FeatureData& DataForFeature(cmExperimental::Feature f)
  68. {
  69. assert(f != cmExperimental::Feature::Sentinel);
  70. return LookupTable[static_cast<size_t>(f)];
  71. }
  72. }
  73. const cmExperimental::FeatureData& cmExperimental::DataForFeature(Feature f)
  74. {
  75. return ::DataForFeature(f);
  76. }
  77. cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
  78. std::string const& name)
  79. {
  80. size_t idx = 0;
  81. for (auto const& feature : LookupTable) {
  82. if (feature.Name == name) {
  83. return static_cast<Feature>(idx);
  84. }
  85. ++idx;
  86. }
  87. return {};
  88. }
  89. bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
  90. {
  91. bool enabled = false;
  92. auto& data = ::DataForFeature(f);
  93. auto value = mf.GetDefinition(data.Variable);
  94. if (value == data.Uuid) {
  95. enabled = true;
  96. }
  97. if (enabled && !data.Warned) {
  98. mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
  99. data.Warned = true;
  100. }
  101. return enabled;
  102. }