cmCMakePresetsFile.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 ArchToolsetStrategy
  13. {
  14. Set,
  15. External,
  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. cm::optional<ArchToolsetStrategy> ArchitectureStrategy;
  46. std::string Toolset;
  47. cm::optional<ArchToolsetStrategy> ToolsetStrategy;
  48. std::string BinaryDir;
  49. std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
  50. std::map<std::string, cm::optional<std::string>> Environment;
  51. cm::optional<bool> WarnDev;
  52. cm::optional<bool> ErrorDev;
  53. cm::optional<bool> WarnDeprecated;
  54. cm::optional<bool> ErrorDeprecated;
  55. cm::optional<bool> WarnUninitialized;
  56. cm::optional<bool> WarnUnusedCli;
  57. cm::optional<bool> WarnSystemVars;
  58. cm::optional<bool> DebugOutput;
  59. cm::optional<bool> DebugTryCompile;
  60. cm::optional<bool> DebugFind;
  61. };
  62. class UnexpandedPreset : public Preset
  63. {
  64. public:
  65. using Preset::Preset;
  66. UnexpandedPreset() = default;
  67. UnexpandedPreset(const Preset& preset)
  68. : Preset(preset)
  69. {
  70. }
  71. UnexpandedPreset(Preset&& preset)
  72. : Preset(std::move(preset))
  73. {
  74. }
  75. };
  76. class ExpandedPreset : public Preset
  77. {
  78. public:
  79. using Preset::Preset;
  80. ExpandedPreset() = default;
  81. ExpandedPreset(const Preset& preset)
  82. : Preset(preset)
  83. {
  84. }
  85. ExpandedPreset(Preset&& preset)
  86. : Preset(std::move(preset))
  87. {
  88. }
  89. };
  90. class PresetPair
  91. {
  92. public:
  93. UnexpandedPreset Unexpanded;
  94. cm::optional<ExpandedPreset> Expanded;
  95. };
  96. std::string SourceDir;
  97. std::map<std::string, PresetPair> Presets;
  98. std::vector<std::string> PresetOrder;
  99. enum class ReadFileResult
  100. {
  101. READ_OK,
  102. FILE_NOT_FOUND,
  103. JSON_PARSE_ERROR,
  104. INVALID_ROOT,
  105. NO_VERSION,
  106. INVALID_VERSION,
  107. UNRECOGNIZED_VERSION,
  108. INVALID_CMAKE_VERSION,
  109. UNRECOGNIZED_CMAKE_VERSION,
  110. INVALID_PRESETS,
  111. INVALID_PRESET,
  112. INVALID_VARIABLE,
  113. DUPLICATE_PRESETS,
  114. CYCLIC_PRESET_INHERITANCE,
  115. USER_PRESET_INHERITANCE,
  116. INVALID_MACRO_EXPANSION,
  117. };
  118. static std::string GetFilename(const std::string& sourceDir);
  119. static std::string GetUserFilename(const std::string& sourceDir);
  120. ReadFileResult ReadProjectPresets(const std::string& sourceDir,
  121. bool allowNoFiles = false);
  122. static const char* ResultToString(ReadFileResult result);
  123. private:
  124. ReadFileResult ReadJSONFile(const std::string& filename,
  125. std::vector<std::string>& presetOrder,
  126. std::map<std::string, PresetPair>& presetMap,
  127. bool user);
  128. };