cmExperimental.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. // MappedPackageInfo
  54. { "MappedPackageInfo",
  55. "ababa1b5-7099-495f-a9cd-e22d38f274f2",
  56. "CMAKE_EXPERIMENTAL_MAPPED_PACKAGE_INFO",
  57. "CMake's support for generating package information in the Common Package "
  58. "Specification format from CMake script exports is experimental. It is "
  59. "meant only for experimentation and feedback to CMake developers.",
  60. {},
  61. cmExperimental::TryCompileCondition::Always },
  62. // ExportBuildDatabase
  63. { "ExportBuildDatabase",
  64. "73194a1d-c0b5-41b9-9190-a4512925e192",
  65. "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE",
  66. "CMake's support for exporting build databases is experimental. It is "
  67. "meant only for experimentation and feedback to CMake developers.",
  68. {},
  69. cmExperimental::TryCompileCondition::Never },
  70. // Instrumentation
  71. { "Instrumentation",
  72. "ec7aa2dc-b87f-45a3-8022-fe01c5f59984",
  73. "CMAKE_EXPERIMENTAL_INSTRUMENTATION",
  74. "CMake's support for collecting instrumentation data is experimental. It "
  75. "is meant only for experimentation and feedback to CMake developers.",
  76. {},
  77. cmExperimental::TryCompileCondition::Never },
  78. };
  79. static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
  80. static_cast<size_t>(cmExperimental::Feature::Sentinel),
  81. "Experimental feature lookup table mismatch");
  82. cmExperimental::FeatureData const& DataForFeature(cmExperimental::Feature f)
  83. {
  84. assert(f != cmExperimental::Feature::Sentinel);
  85. return LookupTable[static_cast<size_t>(f)];
  86. }
  87. }
  88. cmExperimental::FeatureData const& cmExperimental::DataForFeature(Feature f)
  89. {
  90. return ::DataForFeature(f);
  91. }
  92. cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
  93. std::string const& name)
  94. {
  95. size_t idx = 0;
  96. for (auto const& feature : LookupTable) {
  97. if (feature.Name == name) {
  98. return static_cast<Feature>(idx);
  99. }
  100. ++idx;
  101. }
  102. return {};
  103. }
  104. bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
  105. {
  106. bool enabled = false;
  107. FeatureData const& data = cmExperimental::DataForFeature(f);
  108. if (cmValue value = mf.GetDefinition(data.Variable)) {
  109. enabled = *value == data.Uuid;
  110. if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) {
  111. if (enabled) {
  112. mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
  113. } else {
  114. mf.IssueMessage(
  115. MessageType::AUTHOR_WARNING,
  116. cmStrCat(
  117. data.Variable, " is set to incorrect value\n ", value,
  118. "\n"
  119. "See 'Help/dev/experimental.rst' in the source tree of this "
  120. "version of CMake for documentation of the experimental feature "
  121. "and the corresponding activation value. This project's code "
  122. "may require changes to work with this CMake's version of the "
  123. "feature."));
  124. }
  125. }
  126. }
  127. return enabled;
  128. }