cmCMakePresetsFile.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. class PresetPair
  90. {
  91. public:
  92. UnexpandedPreset Unexpanded;
  93. cm::optional<ExpandedPreset> Expanded;
  94. };
  95. std::string SourceDir;
  96. std::map<std::string, PresetPair> Presets;
  97. std::vector<std::string> PresetOrder;
  98. enum class ReadFileResult
  99. {
  100. READ_OK,
  101. FILE_NOT_FOUND,
  102. JSON_PARSE_ERROR,
  103. INVALID_ROOT,
  104. NO_VERSION,
  105. INVALID_VERSION,
  106. UNRECOGNIZED_VERSION,
  107. INVALID_CMAKE_VERSION,
  108. UNRECOGNIZED_CMAKE_VERSION,
  109. INVALID_PRESETS,
  110. INVALID_PRESET,
  111. INVALID_VARIABLE,
  112. DUPLICATE_PRESETS,
  113. CYCLIC_PRESET_INHERITANCE,
  114. USER_PRESET_INHERITANCE,
  115. INVALID_MACRO_EXPANSION,
  116. };
  117. static std::string GetFilename(const std::string& sourceDir);
  118. static std::string GetUserFilename(const std::string& sourceDir);
  119. ReadFileResult ReadProjectPresets(const std::string& sourceDir,
  120. bool allowNoFiles = false);
  121. static const char* ResultToString(ReadFileResult result);
  122. private:
  123. ReadFileResult ReadJSONFile(const std::string& filename,
  124. std::vector<std::string>& presetOrder,
  125. std::map<std::string, PresetPair>& presetMap,
  126. bool user);
  127. };