cmExperimental.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. "9157bf90-2313-44d6-aefa-67cd83c8be7c",
  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. // ImportPackageInfo
  45. { "ImportPackageInfo",
  46. "e82e467b-f997-4464-8ace-b00808fff261",
  47. "CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES",
  48. "CMake's support for importing package information in the Common Package "
  49. "Specification format (via find_package) is experimental. It is meant "
  50. "only for experimentation and feedback to CMake developers.",
  51. {},
  52. cmExperimental::TryCompileCondition::Always,
  53. false },
  54. // ExportPackageInfo
  55. { "ExportPackageInfo",
  56. "b80be207-778e-46ba-8080-b23bba22639e",
  57. "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO",
  58. "CMake's support for exporting package information in the Common Package "
  59. "Specification format is experimental. It is meant only for "
  60. "experimentation and feedback to CMake developers.",
  61. {},
  62. cmExperimental::TryCompileCondition::Always,
  63. false },
  64. // ExportBuildDatabase
  65. { "ExportBuildDatabase",
  66. "4bd552e2-b7fb-429a-ab23-c83ef53f3f13",
  67. "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE",
  68. "CMake's support for exporting build databases is experimental. It is "
  69. "meant only for experimentation and feedback to CMake developers.",
  70. {},
  71. cmExperimental::TryCompileCondition::Never,
  72. false },
  73. // Instrumentation
  74. { "Instrumentation",
  75. "a37d1069-1972-4901-b9c9-f194aaf2b6e0",
  76. "CMAKE_EXPERIMENTAL_INSTRUMENTATION",
  77. "CMake's support for collecting instrumentation data is experimental. It "
  78. "is meant only for experimentation and feedback to CMake developers.",
  79. {},
  80. cmExperimental::TryCompileCondition::Never,
  81. false },
  82. };
  83. static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
  84. static_cast<size_t>(cmExperimental::Feature::Sentinel),
  85. "Experimental feature lookup table mismatch");
  86. cmExperimental::FeatureData& DataForFeature(cmExperimental::Feature f)
  87. {
  88. assert(f != cmExperimental::Feature::Sentinel);
  89. return LookupTable[static_cast<size_t>(f)];
  90. }
  91. }
  92. const cmExperimental::FeatureData& cmExperimental::DataForFeature(Feature f)
  93. {
  94. return ::DataForFeature(f);
  95. }
  96. cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
  97. std::string const& name)
  98. {
  99. size_t idx = 0;
  100. for (auto const& feature : LookupTable) {
  101. if (feature.Name == name) {
  102. return static_cast<Feature>(idx);
  103. }
  104. ++idx;
  105. }
  106. return {};
  107. }
  108. bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
  109. {
  110. bool enabled = false;
  111. auto& data = ::DataForFeature(f);
  112. auto value = mf.GetDefinition(data.Variable);
  113. if (value == data.Uuid) {
  114. enabled = true;
  115. }
  116. if (enabled && !data.Warned) {
  117. mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
  118. data.Warned = true;
  119. }
  120. return enabled;
  121. }