cmExperimental.cxx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. struct FeatureData
  17. {
  18. std::string const Uuid;
  19. std::string const Variable;
  20. std::string const Description;
  21. bool Warned;
  22. } LookupTable[] = {
  23. // CxxModuleCMakeApi
  24. { "17be90bd-a850-44e0-be50-448de847d652",
  25. "CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API",
  26. "CMake's C++ module support is experimental. It is meant only for "
  27. "experimentation and feedback to CMake developers.",
  28. false },
  29. };
  30. static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) ==
  31. static_cast<size_t>(cmExperimental::Feature::Sentinel),
  32. "Experimental feature lookup table mismatch");
  33. FeatureData& DataForFeature(cmExperimental::Feature f)
  34. {
  35. assert(f != cmExperimental::Feature::Sentinel);
  36. return LookupTable[static_cast<size_t>(f)];
  37. }
  38. }
  39. bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
  40. {
  41. bool enabled = false;
  42. auto& data = DataForFeature(f);
  43. auto value = mf.GetDefinition(data.Variable);
  44. if (value == data.Uuid) {
  45. enabled = true;
  46. }
  47. if (enabled && !data.Warned) {
  48. mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
  49. data.Warned = true;
  50. }
  51. return enabled;
  52. }