cmExperimental.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // CxxImportStd
  28. { "CxxImportStd",
  29. "d0edc3af-4c50-42ea-a356-e2862fe7a444",
  30. "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD",
  31. "CMake's support for `import std;` in C++23 and newer is experimental. It "
  32. "is meant only for experimentation and feedback to CMake developers.",
  33. {},
  34. cmExperimental::TryCompileCondition::Always },
  35. // ImportPackageInfo
  36. { "ImportPackageInfo",
  37. "e82e467b-f997-4464-8ace-b00808fff261",
  38. "CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES",
  39. "CMake's support for importing package information in the Common Package "
  40. "Specification format (via find_package) is experimental. It is meant "
  41. "only for experimentation and feedback to CMake developers.",
  42. {},
  43. cmExperimental::TryCompileCondition::Always },
  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 is experimental. It is meant only for "
  50. "experimentation and feedback to CMake developers.",
  51. {},
  52. cmExperimental::TryCompileCondition::Always },
  53. // ExportBuildDatabase
  54. { "ExportBuildDatabase",
  55. "73194a1d-c0b5-41b9-9190-a4512925e192",
  56. "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE",
  57. "CMake's support for exporting build databases is experimental. It is "
  58. "meant only for experimentation and feedback to CMake developers.",
  59. {},
  60. cmExperimental::TryCompileCondition::Never },
  61. // Instrumentation
  62. { "Instrumentation",
  63. "ec7aa2dc-b87f-45a3-8022-fe01c5f59984",
  64. "CMAKE_EXPERIMENTAL_INSTRUMENTATION",
  65. "CMake's support for collecting instrumentation data is experimental. It "
  66. "is meant only for experimentation and feedback to CMake developers.",
  67. {},
  68. cmExperimental::TryCompileCondition::Never },
  69. };
  70. static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
  71. static_cast<size_t>(cmExperimental::Feature::Sentinel),
  72. "Experimental feature lookup table mismatch");
  73. cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f)
  74. {
  75. assert(f != cmExperimental::Feature::Sentinel);
  76. return LookupTable[static_cast<size_t>(f)];
  77. }
  78. }
  79. cmExperimental::FeatureData const& cmExperimental::DataForFeature(Feature f)
  80. {
  81. return ::DataForFeature(f);
  82. }
  83. cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
  84. std::string const& name)
  85. {
  86. size_t idx = 0;
  87. for (auto const& feature : LookupTable) {
  88. if (feature.Name == name) {
  89. return static_cast<Feature>(idx);
  90. }
  91. ++idx;
  92. }
  93. return {};
  94. }
  95. bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
  96. {
  97. bool enabled = false;
  98. FeatureData const& data = cmExperimental::DataForFeature(f);
  99. if (cmValue value = mf.GetDefinition(data.Variable)) {
  100. enabled = *value == data.Uuid;
  101. if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) {
  102. if (enabled) {
  103. mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
  104. } else {
  105. mf.IssueMessage(
  106. MessageType::AUTHOR_WARNING,
  107. cmStrCat(
  108. data.Variable, " is set to incorrect value\n ", value,
  109. "\n"
  110. "See 'Help/dev/experimental.rst' in the source tree of this "
  111. "version of CMake for documentation of the experimental feature "
  112. "and the corresponding activation value. This project's code "
  113. "may require changes to work with this CMake's version of the "
  114. "feature."));
  115. }
  116. }
  117. }
  118. return enabled;
  119. }