cmake/Source/QtDialog/QCMake.h

215 lines
6.9 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2016-07-09 11:21:54 +02:00
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
2022-03-29 21:10:50 +02:00
#include "cmCMakePresetsGraph.h"
2016-07-09 11:21:54 +02:00
#include "cmake.h"
#ifdef _MSC_VER
2018-08-09 18:06:22 +02:00
# pragma warning(disable : 4127)
# pragma warning(disable : 4512)
#endif
2020-08-30 11:54:41 +02:00
#include <memory>
2016-03-13 13:35:51 +01:00
#include <vector>
2021-09-14 00:13:48 +02:00
#include "QCMakePreset.h"
2016-07-09 11:21:54 +02:00
#include <QAtomicInt>
#include <QList>
#include <QMetaType>
#include <QObject>
2021-09-14 00:13:48 +02:00
#include <QProcessEnvironment>
#include <QString>
#include <QStringList>
2021-09-14 00:13:48 +02:00
#include <QTimer>
2016-07-09 11:21:54 +02:00
#include <QVariant>
/// struct to represent cmake properties in Qt
/// Value is of type String or Bool
struct QCMakeProperty
{
2016-07-09 11:21:54 +02:00
enum PropertyType
{
BOOL,
PATH,
FILEPATH,
STRING
};
QString Key;
QVariant Value;
2009-10-04 10:30:41 +03:00
QStringList Strings;
QString Help;
PropertyType Type;
bool Advanced;
2013-03-16 19:13:01 +02:00
bool operator==(const QCMakeProperty& other) const
2016-07-09 11:21:54 +02:00
{
return this->Key == other.Key;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
bool operator<(const QCMakeProperty& other) const
2016-07-09 11:21:54 +02:00
{
return this->Key < other.Key;
2016-07-09 11:21:54 +02:00
}
};
// list of properties
2020-02-01 23:06:01 +01:00
using QCMakePropertyList = QList<QCMakeProperty>;
// allow QVariant to be a property or list of properties
Q_DECLARE_METATYPE(QCMakeProperty)
Q_DECLARE_METATYPE(QCMakePropertyList)
2021-09-14 00:13:48 +02:00
Q_DECLARE_METATYPE(QProcessEnvironment)
2022-03-29 21:10:50 +02:00
Q_DECLARE_METATYPE(cmCMakePresetsGraph::ReadFileResult)
/// Qt API for CMake library.
2013-03-16 19:13:01 +02:00
/// Wrapper like class allows for easier integration with
/// Qt features such as, signal/slot connections, multi-threading, etc..
class QCMake : public QObject
{
Q_OBJECT
public:
2018-01-26 17:06:56 +01:00
QCMake(QObject* p = nullptr);
~QCMake();
public slots:
/// load the cache file in a directory
void loadCache(const QString& dir);
/// set the source directory containing the source
void setSourceDirectory(const QString& dir);
/// set the binary directory to build in
void setBinaryDirectory(const QString& dir);
2021-09-14 00:13:48 +02:00
/// set the preset name to use
void setPreset(const QString& name, bool setBinary = true);
/// set the desired generator to use
void setGenerator(const QString& generator);
2016-03-13 13:35:51 +01:00
/// set the desired generator to use
2019-11-11 23:01:05 +01:00
void setPlatform(const QString& platform);
/// set the desired generator to use
2016-03-13 13:35:51 +01:00
void setToolset(const QString& toolset);
2021-09-14 00:13:48 +02:00
/// set the configure and generate environment
void setEnvironment(const QProcessEnvironment& environment);
/// do the configure step
void configure();
/// generate the files
void generate();
2018-04-23 21:13:27 +02:00
/// open the project
void open();
/// set the property values
void setProperties(const QCMakePropertyList&);
2016-07-09 11:21:54 +02:00
/// interrupt the configure or generate process (if connecting, make a direct
/// connection)
void interrupt();
/// delete the cache in binary directory
void deleteCache();
/// reload the cache in binary directory
void reloadCache();
/// set whether to do debug output
void setDebugOutput(bool);
2016-03-13 13:35:51 +01:00
/// get whether to do suppress dev warnings
bool getSuppressDevWarnings();
/// set whether to do suppress dev warnings
void setSuppressDevWarnings(bool value);
2016-03-13 13:35:51 +01:00
/// get whether to do suppress deprecated warnings
bool getSuppressDeprecatedWarnings();
/// set whether to do suppress deprecated warnings
void setSuppressDeprecatedWarnings(bool value);
/// get whether to treat developer (author) warnings as errors
bool getDevWarningsAsErrors();
/// set whether to treat developer (author) warnings as errors
void setDevWarningsAsErrors(bool value);
/// get whether to treat deprecated warnings as errors
bool getDeprecatedWarningsAsErrors();
/// set whether to treat deprecated warnings as errors
void setDeprecatedWarningsAsErrors(bool value);
2011-02-07 16:37:25 +01:00
/// set whether to run cmake with warnings about uninitialized variables
void setWarnUninitializedMode(bool value);
2018-04-23 21:13:27 +02:00
/// check if project IDE open is possible and emit openPossible signal
void checkOpenPossible();
public:
/// get the list of cache properties
QCMakePropertyList properties() const;
/// get the current binary directory
QString binaryDirectory() const;
/// get the current source directory
QString sourceDirectory() const;
/// get the current generator
QString generator() const;
2021-09-14 00:13:48 +02:00
/// get the configure and generate environment
QProcessEnvironment environment() const;
/// get the available generators
2016-03-13 13:35:51 +01:00
std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
/// get whether to do debug output
bool getDebugOutput() const;
signals:
2016-07-09 11:21:54 +02:00
/// signal when properties change (during read from disk or configure
/// process)
void propertiesChanged(const QCMakePropertyList& vars);
/// signal when the generator changes
void generatorChanged(const QString& gen);
/// signal when the source directory changes (binary directory already
/// containing a CMakeCache.txt file)
void sourceDirChanged(const QString& dir);
/// signal when the binary directory changes
void binaryDirChanged(const QString& dir);
2021-09-14 00:13:48 +02:00
/// signal when the preset list changes
void presetsChanged(const QVector<QCMakePreset>& presets);
/// signal when the selected preset changes
void presetChanged(const QString& name);
/// signal when there's an error reading the presets files
void presetLoadError(const QString& dir,
2022-03-29 21:10:50 +02:00
cmCMakePresetsGraph::ReadFileResult error);
2021-09-14 00:13:48 +02:00
/// signal when uninitialized warning changes
void warnUninitializedModeChanged(bool value);
/// signal for progress events
void progressChanged(const QString& msg, float percent);
/// signal when configure is done
void configureDone(int error);
/// signal when generate is done
void generateDone(int error);
/// signal when there is an output message
void outputMessage(const QString& msg);
/// signal when there is an error message
void errorMessage(const QString& msg);
/// signal when debug output changes
void debugOutputChanged(bool);
2016-03-13 13:35:51 +01:00
/// signal when the toolset changes
void toolsetChanged(const QString& toolset);
2019-11-11 23:01:05 +01:00
/// signal when the platform changes
void platformChanged(const QString& platform);
2018-04-23 21:13:27 +02:00
/// signal when open is done
void openDone(bool successful);
/// signal when open is done
void openPossible(bool possible);
protected:
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmake> CMakeInstance;
2019-11-11 23:01:05 +01:00
bool interruptCallback();
void progressCallback(std::string const& msg, float percent);
void messageCallback(std::string const& msg, const char* title);
void stdoutCallback(std::string const& msg);
void stderrCallback(std::string const& msg);
2021-09-14 00:13:48 +02:00
void setUpEnvironment() const;
void loadPresets();
2019-11-11 23:01:05 +01:00
2011-02-07 16:37:25 +01:00
bool WarnUninitializedMode;
QString SourceDirectory;
QString BinaryDirectory;
QString Generator;
2019-11-11 23:01:05 +01:00
QString Platform;
2016-03-13 13:35:51 +01:00
QString Toolset;
std::vector<cmake::GeneratorInfo> AvailableGenerators;
2022-03-29 21:10:50 +02:00
cmCMakePresetsGraph CMakePresetsGraph;
cmCMakePresetsGraph::ReadFileResult LastLoadPresetsResult =
cmCMakePresetsGraph::ReadFileResult::READ_OK;
2021-09-14 00:13:48 +02:00
QString PresetName;
QString CMakeExecutable;
2012-04-19 19:04:21 +03:00
QAtomicInt InterruptFlag;
2021-09-14 00:13:48 +02:00
QProcessEnvironment StartEnvironment;
QProcessEnvironment Environment;
QTimer LoadPresetsTimer;
};