Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/QtDialog/QCMake.h
5000 views
1
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
file LICENSE.rst or https://cmake.org/licensing for details. */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include "cmCMakePresetsGraph.h"
8
#include "cmake.h"
9
10
#ifdef _MSC_VER
11
# pragma warning(disable : 4127)
12
# pragma warning(disable : 4512)
13
#endif
14
15
#include <memory>
16
#include <vector>
17
18
#include "QCMakePreset.h"
19
#include <QAtomicInt>
20
#include <QList>
21
#include <QMetaType>
22
#include <QObject>
23
#include <QProcessEnvironment>
24
#include <QString>
25
#include <QStringList>
26
#include <QTimer>
27
#include <QVariant>
28
29
/// struct to represent cmake properties in Qt
30
/// Value is of type String or Bool
31
struct QCMakeProperty
32
{
33
enum PropertyType
34
{
35
BOOL,
36
PATH,
37
FILEPATH,
38
STRING
39
};
40
QString Key;
41
QVariant Value;
42
QStringList Strings;
43
QString Help;
44
PropertyType Type;
45
bool Advanced;
46
bool operator==(QCMakeProperty const& other) const
47
{
48
return this->Key == other.Key;
49
}
50
bool operator<(QCMakeProperty const& other) const
51
{
52
return this->Key < other.Key;
53
}
54
};
55
56
// list of properties
57
using QCMakePropertyList = QList<QCMakeProperty>;
58
59
// allow QVariant to be a property or list of properties
60
Q_DECLARE_METATYPE(QCMakeProperty)
61
Q_DECLARE_METATYPE(QCMakePropertyList)
62
Q_DECLARE_METATYPE(QProcessEnvironment)
63
64
/// Qt API for CMake library.
65
/// Wrapper like class allows for easier integration with
66
/// Qt features such as, signal/slot connections, multi-threading, etc..
67
class QCMake : public QObject
68
{
69
Q_OBJECT
70
public:
71
QCMake(QObject* p = nullptr);
72
~QCMake();
73
public slots:
74
/// load the cache file in a directory
75
void loadCache(QString const& dir);
76
/// set the source directory containing the source
77
void setSourceDirectory(QString const& dir);
78
/// set the binary directory to build in
79
void setBinaryDirectory(QString const& dir);
80
/// set the preset name to use
81
void setPreset(QString const& name, bool setBinary = true);
82
/// set the desired generator to use
83
void setGenerator(QString const& generator);
84
/// set the desired generator to use
85
void setPlatform(QString const& platform);
86
/// set the desired generator to use
87
void setToolset(QString const& toolset);
88
/// set the configure and generate environment
89
void setEnvironment(QProcessEnvironment const& environment);
90
/// do the configure step
91
void configure();
92
/// generate the files
93
void generate();
94
/// open the project
95
void open();
96
/// set the property values
97
void setProperties(QCMakePropertyList const&);
98
/// interrupt the configure or generate process (if connecting, make a direct
99
/// connection)
100
void interrupt();
101
/// delete the cache in binary directory
102
void deleteCache();
103
/// reload the cache in binary directory
104
void reloadCache();
105
/// set whether to do debug output
106
void setDebugOutput(bool);
107
/// get whether to do suppress dev warnings
108
bool getSuppressDevWarnings();
109
/// set whether to do suppress dev warnings
110
void setSuppressDevWarnings(bool value);
111
/// get whether to do suppress deprecated warnings
112
bool getSuppressDeprecatedWarnings();
113
/// set whether to do suppress deprecated warnings
114
void setSuppressDeprecatedWarnings(bool value);
115
/// get whether to treat developer (author) warnings as errors
116
bool getDevWarningsAsErrors();
117
/// set whether to treat developer (author) warnings as errors
118
void setDevWarningsAsErrors(bool value);
119
/// get whether to treat deprecated warnings as errors
120
bool getDeprecatedWarningsAsErrors();
121
/// set whether to treat deprecated warnings as errors
122
void setDeprecatedWarningsAsErrors(bool value);
123
/// set whether to run cmake with warnings about uninitialized variables
124
void setWarnUninitializedMode(bool value);
125
/// check if project IDE open is possible and emit openPossible signal
126
void checkOpenPossible();
127
/// Reload the preset files and tree
128
void loadPresets();
129
130
public:
131
/// get the list of cache properties
132
QCMakePropertyList properties() const;
133
/// get the current binary directory
134
QString binaryDirectory() const;
135
/// get the current binary directory, possibly a relative path
136
QString relativeBinaryDirectory() const;
137
/// get the current source directory
138
QString sourceDirectory() const;
139
/// get the current generator
140
QString generator() const;
141
/// get the configure and generate environment
142
QProcessEnvironment environment() const;
143
/// get the available generators
144
std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
145
/// get whether to do debug output
146
bool getDebugOutput() const;
147
148
signals:
149
/// signal when properties change (during read from disk or configure
150
/// process)
151
void propertiesChanged(QCMakePropertyList const& vars);
152
/// signal when the generator changes
153
void generatorChanged(QString const& gen);
154
/// signal when the source directory changes (binary directory already
155
/// containing a CMakeCache.txt file)
156
void sourceDirChanged(QString const& dir);
157
/// signal when the binary directory changes
158
void binaryDirChanged(QString const& dir);
159
/// signal when the preset list changes
160
void presetsChanged(QVector<QCMakePreset> const& presets);
161
/// signal when the selected preset changes
162
void presetChanged(QString const& name);
163
/// signal when there's an error reading the presets files
164
void presetLoadError(QString const& dir, QString const& error);
165
/// signal when uninitialized warning changes
166
void warnUninitializedModeChanged(bool value);
167
/// signal for progress events
168
void progressChanged(QString const& msg, float percent);
169
/// signal when configure is done
170
void configureDone(int error);
171
/// signal when generate is done
172
void generateDone(int error);
173
/// signal when there is an output message
174
void outputMessage(QString const& msg);
175
/// signal when there is an error message
176
void errorMessage(QString const& msg);
177
/// signal when debug output changes
178
void debugOutputChanged(bool);
179
/// signal when the toolset changes
180
void toolsetChanged(QString const& toolset);
181
/// signal when the platform changes
182
void platformChanged(QString const& platform);
183
/// signal when open is done
184
void openDone(bool successful);
185
/// signal when open is done
186
void openPossible(bool possible);
187
188
protected:
189
std::unique_ptr<cmake> CMakeInstance;
190
191
bool interruptCallback();
192
void progressCallback(std::string const& msg, float percent);
193
void messageCallback(std::string const& msg, char const* title);
194
void stdoutCallback(std::string const& msg);
195
void stderrCallback(std::string const& msg);
196
void setUpEnvironment() const;
197
198
bool WarnUninitializedMode;
199
QString SourceDirectory;
200
QString BinaryDirectory;
201
QString MaybeRelativeBinaryDirectory;
202
QString Generator;
203
QString Platform;
204
QString Toolset;
205
std::vector<cmake::GeneratorInfo> AvailableGenerators;
206
cmCMakePresetsGraph CMakePresetsGraph;
207
QString PresetName;
208
QString CMakeExecutable;
209
QAtomicInt InterruptFlag;
210
QProcessEnvironment StartEnvironment;
211
QProcessEnvironment Environment;
212
};
213
214