aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cmakeprojectmanager/presetsparser.h
blob: cfbf5654895565ed692cb30e2e11e915940b4bc0 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "cmakeconfigitem.h"

#include <utils/environment.h>
#include <utils/filepath.h>

#include <QHash>
#include <QVersionNumber>

namespace CMakeProjectManager::Internal {

namespace PresetsDetails {

class ValueStrategyPair {
public:
    std::optional<QString> value;
    enum class Strategy : bool { set, external };
    std::optional<Strategy> strategy;
};

class Warnings {
public:
    std::optional<bool> dev;
    std::optional<bool> deprecated;
    std::optional<bool> uninitialized = false;
    std::optional<bool> unusedCli = true;
    std::optional<bool> systemVars = false;
};

class Errors {
public:
    std::optional<bool> dev;
    std::optional<bool> deprecated;
};

class Debug {
public:
    std::optional<bool> output = false;
    std::optional<bool> tryCompile = false;
    std::optional<bool> find = false;
};

class Condition {
public:
    QString type;

    bool isNull() const { return type == "null"; }
    bool isConst() const  { return type == "const"; }
    bool isEquals() const  { return type == "equals"; }
    bool isNotEquals() const  { return type == "notEquals"; }
    bool isInList() const  { return type == "inList"; }
    bool isNotInList() const { return type == "notInList"; }
    bool isMatches() const { return type == "matches"; }
    bool isNotMatches() const { return type == "notMatches"; }
    bool isAnyOf() const { return type == "anyOf"; }
    bool isAllOf() const { return type == "allOf"; }
    bool isNot() const { return type == "not"; }

    bool evaluate() const;

    // const
    std::optional<bool> constValue;

    // equals, notEquals
    std::optional<QString> lhs;
    std::optional<QString> rhs;

    // inList, notInList
    std::optional<QString> string;
    std::optional<QStringList> list;

    // matches, notMatches
    std::optional<QString> regex;

    using ConditionPtr = std::shared_ptr<Condition>;

    // anyOf, allOf
    std::optional<std::vector<ConditionPtr>> conditions;

    // not
    std::optional<ConditionPtr> condition;
};

class ConfigurePreset {
public:
    void inheritFrom(const ConfigurePreset &other);

    QString name;
    Utils::FilePath fileDir;
    std::optional<bool> hidden = false;
    std::optional<QStringList> inherits;
    std::optional<Condition> condition;
    std::optional<QVariantMap> vendor;
    std::optional<QString> displayName;
    std::optional<QString> description;
    std::optional<QString> generator;
    std::optional<ValueStrategyPair> architecture;
    std::optional<ValueStrategyPair> toolset;
    std::optional<QString> toolchainFile;
    std::optional<QString> binaryDir;
    std::optional<QString> installDir;
    std::optional<QString> cmakeExecutable;
    std::optional<CMakeConfig> cacheVariables;
    std::optional<Utils::Environment> environment;
    std::optional<Warnings> warnings;
    std::optional<Errors> errors;
    std::optional<Debug> debug;
};

class BuildPreset {
public:
    void inheritFrom(const BuildPreset &other);

    QString name;
    Utils::FilePath fileDir;
    std::optional<bool> hidden = false;
    std::optional<QStringList> inherits;
    std::optional<Condition> condition;
    std::optional<QVariantMap> vendor;
    std::optional<QString> displayName;
    std::optional<QString> description;
    std::optional<Utils::Environment> environment;
    std::optional<QString> configurePreset;
    std::optional<bool> inheritConfigureEnvironment = true;
    std::optional<int> jobs;
    std::optional<QStringList> targets;
    std::optional<QString> configuration;
    std::optional<bool> verbose;
    std::optional<bool> cleanFirst;
    std::optional<QStringList> nativeToolOptions;
};

} // namespace PresetsDetails

class PresetsData
{
public:
    int version = 0;
    bool havePresets = false;
    QVersionNumber cmakeMinimimRequired;
    std::optional<QVariantMap> vendor;
    std::optional<QStringList> include;
    Utils::FilePath fileDir;
    QList<PresetsDetails::ConfigurePreset> configurePresets;
    QList<PresetsDetails::BuildPreset> buildPresets;
};

class PresetsParser
{
    PresetsData m_presetsData;
public:
    bool parse(Utils::FilePath const &jsonFile, QString &errorMessage, int &errorLine);

    const PresetsData &presetsData() const;
};

} // CMakeProjectManager::Internal