cmCMakePresetsFile.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include <map>
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include <cm/optional>
  9. class cmCMakePresetsFile
  10. {
  11. public:
  12. enum class CMakeGeneratorConfig
  13. {
  14. Default,
  15. Ignore,
  16. };
  17. class CacheVariable
  18. {
  19. public:
  20. std::string Type;
  21. std::string Value;
  22. };
  23. class Preset
  24. {
  25. public:
  26. #if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)
  27. Preset() = default;
  28. Preset(const Preset& /*other*/) = default;
  29. Preset(Preset&& /*other*/) = default;
  30. Preset& operator=(const Preset& /*other*/) = default;
  31. // The move assignment operators for several STL classes did not become
  32. // noexcept until C++17, which causes some tools to warn about this move
  33. // assignment operator throwing an exception when it shouldn't. Disable the
  34. // move assignment operator until C++17 is enabled.
  35. Preset& operator=(Preset&& /*other*/) = delete;
  36. #endif
  37. std::string Name;
  38. std::vector<std::string> Inherits;
  39. bool Hidden;
  40. bool User;
  41. std::string DisplayName;
  42. std::string Description;
  43. std::string Generator;
  44. std::string Architecture;
  45. std::string Toolset;
  46. cm::optional<CMakeGeneratorConfig> GeneratorConfig;
  47. std::string BinaryDir;
  48. std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
  49. std::map<std::string, cm::optional<std::string>> Environment;
  50. cm::optional<bool> WarnDev;
  51. cm::optional<bool> ErrorDev;
  52. cm::optional<bool> WarnDeprecated;
  53. cm::optional<bool> ErrorDeprecated;
  54. cm::optional<bool> WarnUninitialized;
  55. cm::optional<bool> WarnUnusedCli;
  56. cm::optional<bool> WarnSystemVars;
  57. cm::optional<bool> DebugOutput;
  58. cm::optional<bool> DebugTryCompile;
  59. cm::optional<bool> DebugFind;
  60. };
  61. class UnexpandedPreset : public Preset
  62. {
  63. public:
  64. using Preset::Preset;
  65. UnexpandedPreset() = default;
  66. UnexpandedPreset(const Preset& preset)
  67. : Preset(preset)
  68. {
  69. }
  70. UnexpandedPreset(Preset&& preset)
  71. : Preset(std::move(preset))
  72. {
  73. }
  74. };
  75. class ExpandedPreset : public Preset
  76. {
  77. public:
  78. using Preset::Preset;
  79. ExpandedPreset() = default;
  80. ExpandedPreset(const Preset& preset)
  81. : Preset(preset)
  82. {
  83. }
  84. ExpandedPreset(Preset&& preset)
  85. : Preset(std::move(preset))
  86. {
  87. }
  88. };
  89. std::string SourceDir;
  90. std::map<std::string, UnexpandedPreset> Presets;
  91. std::vector<std::string> PresetOrder;
  92. enum class ReadFileResult
  93. {
  94. READ_OK,
  95. FILE_NOT_FOUND,
  96. JSON_PARSE_ERROR,
  97. INVALID_ROOT,
  98. NO_VERSION,
  99. INVALID_VERSION,
  100. UNRECOGNIZED_VERSION,
  101. INVALID_CMAKE_VERSION,
  102. UNRECOGNIZED_CMAKE_VERSION,
  103. INVALID_PRESETS,
  104. INVALID_PRESET,
  105. INVALID_VARIABLE,
  106. DUPLICATE_PRESETS,
  107. CYCLIC_PRESET_INHERITANCE,
  108. USER_PRESET_INHERITANCE,
  109. };
  110. static std::string GetFilename(const std::string& sourceDir);
  111. static std::string GetUserFilename(const std::string& sourceDir);
  112. ReadFileResult ReadProjectPresets(const std::string& sourceDir,
  113. bool allowNoFiles = false);
  114. static const char* ResultToString(ReadFileResult result);
  115. cm::optional<ExpandedPreset> ExpandMacros(
  116. const UnexpandedPreset& preset) const;
  117. private:
  118. ReadFileResult ReadJSONFile(
  119. const std::string& filename, std::vector<std::string>& presetOrder,
  120. std::map<std::string, UnexpandedPreset>& presetMap, bool user);
  121. };