summaryrefslogtreecommitdiffstats
path: root/Source/cmCMakePresetsFile.h
blob: f6b159a02ca9378783e6885641983f2ece07939c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#pragma once

#include <map>
#include <string>
#include <utility>
#include <vector>

#include <cm/optional>

class cmCMakePresetsFile
{
public:
  enum class ArchToolsetStrategy
  {
    Set,
    External,
  };

  class CacheVariable
  {
  public:
    std::string Type;
    std::string Value;
  };

  class Preset
  {
  public:
#if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)
    Preset() = default;
    Preset(const Preset& /*other*/) = default;
    Preset(Preset&& /*other*/) = default;

    Preset& operator=(const Preset& /*other*/) = default;

    // The move assignment operators for several STL classes did not become
    // noexcept until C++17, which causes some tools to warn about this move
    // assignment operator throwing an exception when it shouldn't. Disable the
    // move assignment operator until C++17 is enabled.
    Preset& operator=(Preset&& /*other*/) = delete;
#endif

    std::string Name;
    std::vector<std::string> Inherits;
    bool Hidden;
    bool User;
    std::string DisplayName;
    std::string Description;
    std::string Generator;
    std::string Architecture;
    cm::optional<ArchToolsetStrategy> ArchitectureStrategy;
    std::string Toolset;
    cm::optional<ArchToolsetStrategy> ToolsetStrategy;
    std::string BinaryDir;

    std::map<std::string, cm::optional<CacheVariable>> CacheVariables;
    std::map<std::string, cm::optional<std::string>> Environment;

    cm::optional<bool> WarnDev;
    cm::optional<bool> ErrorDev;
    cm::optional<bool> WarnDeprecated;
    cm::optional<bool> ErrorDeprecated;
    cm::optional<bool> WarnUninitialized;
    cm::optional<bool> WarnUnusedCli;
    cm::optional<bool> WarnSystemVars;

    cm::optional<bool> DebugOutput;
    cm::optional<bool> DebugTryCompile;
    cm::optional<bool> DebugFind;
  };

  class UnexpandedPreset : public Preset
  {
  public:
    using Preset::Preset;

    UnexpandedPreset() = default;
    UnexpandedPreset(const Preset& preset)
      : Preset(preset)
    {
    }
    UnexpandedPreset(Preset&& preset)
      : Preset(std::move(preset))
    {
    }
  };

  class ExpandedPreset : public Preset
  {
  public:
    using Preset::Preset;

    ExpandedPreset() = default;
    ExpandedPreset(const Preset& preset)
      : Preset(preset)
    {
    }
    ExpandedPreset(Preset&& preset)
      : Preset(std::move(preset))
    {
    }
  };

  class PresetPair
  {
  public:
    UnexpandedPreset Unexpanded;
    cm::optional<ExpandedPreset> Expanded;
  };

  std::string SourceDir;
  std::map<std::string, PresetPair> Presets;
  std::vector<std::string> PresetOrder;

  enum class ReadFileResult
  {
    READ_OK,
    FILE_NOT_FOUND,
    JSON_PARSE_ERROR,
    INVALID_ROOT,
    NO_VERSION,
    INVALID_VERSION,
    UNRECOGNIZED_VERSION,
    INVALID_CMAKE_VERSION,
    UNRECOGNIZED_CMAKE_VERSION,
    INVALID_PRESETS,
    INVALID_PRESET,
    INVALID_VARIABLE,
    DUPLICATE_PRESETS,
    CYCLIC_PRESET_INHERITANCE,
    USER_PRESET_INHERITANCE,
    INVALID_MACRO_EXPANSION,
  };

  static std::string GetFilename(const std::string& sourceDir);
  static std::string GetUserFilename(const std::string& sourceDir);
  ReadFileResult ReadProjectPresets(const std::string& sourceDir,
                                    bool allowNoFiles = false);
  static const char* ResultToString(ReadFileResult result);

private:
  ReadFileResult ReadJSONFile(const std::string& filename,
                              std::vector<std::string>& presetOrder,
                              std::map<std::string, PresetPair>& presetMap,
                              bool user);
};