cmExperimental.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmExperimental.h"
  4. #include <cassert>
  5. #include <cstddef>
  6. #include <string>
  7. #include "cmGlobalGenerator.h"
  8. #include "cmMakefile.h"
  9. #include "cmMessageType.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmValue.h"
  12. namespace {
  13. /*
  14. * The `Uuid` fields of these objects should change periodically.
  15. * Search for other instances to keep the documentation and test suite
  16. * up-to-date.
  17. */
  18. cmExperimental::FeatureData const LookupTable[] = {
  19. // ExportPackageDependencies
  20. { "ExportPackageDependencies",
  21. "1942b4fa-b2c5-4546-9385-83f254070067",
  22. "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES",
  23. "CMake's EXPORT_PACKAGE_DEPENDENCIES support is experimental. It is meant "
  24. "only for experimentation and feedback to CMake developers.",
  25. {},
  26. cmExperimental::TryCompileCondition::Always },
  27. // WindowsKernelModeDriver
  28. { "WindowsKernelModeDriver",
  29. "9157bf90-2313-44d6-aefa-67cd83c8be7c",
  30. "CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER",
  31. "CMake's Windows kernel-mode driver support is experimental. It is meant "
  32. "only for experimentation and feedback to CMake developers.",
  33. {},
  34. cmExperimental::TryCompileCondition::Always },
  35. // CxxImportStd
  36. { "CxxImportStd",
  37. "d0edc3af-4c50-42ea-a356-e2862fe7a444",
  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. // ImportPackageInfo
  44. { "ImportPackageInfo",
  45. "e82e467b-f997-4464-8ace-b00808fff261",
  46. "CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES",
  47. "CMake's support for importing package information in the Common Package "
  48. "Specification format (via find_package) is experimental. It is meant "
  49. "only for experimentation and feedback to CMake developers.",
  50. {},
  51. cmExperimental::TryCompileCondition::Always },
  52. // ExportPackageInfo
  53. { "ExportPackageInfo",
  54. "b80be207-778e-46ba-8080-b23bba22639e",
  55. "CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO",
  56. "CMake's support for exporting package information in the Common Package "
  57. "Specification format is experimental. It is meant only for "
  58. "experimentation and feedback to CMake developers.",
  59. {},
  60. cmExperimental::TryCompileCondition::Always },
  61. // ExportBuildDatabase
  62. { "ExportBuildDatabase",
  63. "73194a1d-c0b5-41b9-9190-a4512925e192",
  64. "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE",
  65. "CMake's support for exporting build databases is experimental. It is "
  66. "meant only for experimentation and feedback to CMake developers.",
  67. {},
  68. cmExperimental::TryCompileCondition::Never },
  69. // Instrumentation
  70. { "Instrumentation",
  71. "a37d1069-1972-4901-b9c9-f194aaf2b6e0",
  72. "CMAKE_EXPERIMENTAL_INSTRUMENTATION",
  73. "CMake's support for collecting instrumentation data is experimental. It "
  74. "is meant only for experimentation and feedback to CMake developers.",
  75. {},
  76. cmExperimental::TryCompileCondition::Never },
  77. };
  78. static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
  79. static_cast<size_t>(cmExperimental::Feature::Sentinel),
  80. "Experimental feature lookup table mismatch");
  81. cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f)
  82. {
  83. assert(f != cmExperimental::Feature::Sentinel);
  84. return LookupTable[static_cast<size_t>(f)];
  85. }
  86. }
  87. cmExperimental::FeatureData const& cmExperimental::DataForFeature(Feature f)
  88. {
  89. return ::DataForFeature(f);
  90. }
  91. cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
  92. std::string const& name)
  93. {
  94. size_t idx = 0;
  95. for (auto const& feature : LookupTable) {
  96. if (feature.Name == name) {
  97. return static_cast<Feature>(idx);
  98. }
  99. ++idx;
  100. }
  101. return {};
  102. }
  103. bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
  104. {
  105. bool enabled = false;
  106. FeatureData const& data = cmExperimental::DataForFeature(f);
  107. if (cmValue value = mf.GetDefinition(data.Variable)) {
  108. enabled = *value == data.Uuid;
  109. if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) {
  110. if (enabled) {
  111. mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
  112. } else {
  113. mf.IssueMessage(
  114. MessageType::AUTHOR_WARNING,
  115. cmStrCat(
  116. data.Variable, " is set to incorrect value\n ", value, '\n',
  117. "See 'Help/dev/experimental.rst' in the source tree of this "
  118. "version of CMake for documentation of the experimental feature "
  119. "and the corresponding activation value. This project's code "
  120. "may require changes to work with this CMake's version of the "
  121. "feature."));
  122. }
  123. }
  124. }
  125. return enabled;
  126. }