cmake/Source/QtDialog/QCMake.cxx

691 lines
20 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. */
#include "QCMake.h"
2021-09-14 00:13:48 +02:00
#include <algorithm>
2020-08-30 11:54:41 +02:00
#include <cm/memory>
#include <QCoreApplication>
2016-07-09 11:21:54 +02:00
#include <QDir>
2021-09-14 00:13:48 +02:00
#include <QString>
#include <QVector>
2016-07-09 11:21:54 +02:00
#include "cmExternalMakefileProjectGenerator.h"
2020-08-30 11:54:41 +02:00
#include "cmGlobalGenerator.h"
2021-09-14 00:13:48 +02:00
#include "cmMessageMetadata.h"
2015-08-17 11:37:30 +02:00
#include "cmState.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
2009-11-06 22:07:41 +02:00
#ifdef Q_OS_WIN
2018-08-09 18:06:22 +02:00
# include "qt_windows.h" // For SetErrorMode
2009-11-06 22:07:41 +02:00
#endif
QCMake::QCMake(QObject* p)
: QObject(p)
2021-09-14 00:13:48 +02:00
, StartEnvironment(QProcessEnvironment::systemEnvironment())
, Environment(QProcessEnvironment::systemEnvironment())
{
2011-02-07 16:37:25 +01:00
this->WarnUninitializedMode = false;
qRegisterMetaType<QCMakeProperty>();
qRegisterMetaType<QCMakePropertyList>();
2021-09-14 00:13:48 +02:00
qRegisterMetaType<QProcessEnvironment>();
qRegisterMetaType<QVector<QCMakePreset>>();
qRegisterMetaType<cmCMakePresetsFile::ReadFileResult>();
2013-03-16 19:13:01 +02:00
cmSystemTools::DisableRunCommandOutput();
cmSystemTools::SetRunCommandHideConsole(true);
2019-11-11 23:01:05 +01:00
cmSystemTools::SetMessageCallback(
2021-09-14 00:13:48 +02:00
[this](std::string const& msg, const cmMessageMetadata& md) {
this->messageCallback(msg, md.title);
2019-11-11 23:01:05 +01:00
});
cmSystemTools::SetStdoutCallback(
[this](std::string const& msg) { this->stdoutCallback(msg); });
cmSystemTools::SetStderrCallback(
[this](std::string const& msg) { this->stderrCallback(msg); });
2020-08-30 11:54:41 +02:00
this->CMakeInstance =
cm::make_unique<cmake>(cmake::RoleProject, cmState::Project);
2014-08-03 19:52:23 +02:00
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeGUICommand());
2019-11-11 23:01:05 +01:00
this->CMakeInstance->SetProgressCallback(
[this](const std::string& msg, float percent) {
this->progressCallback(msg, percent);
});
2019-11-11 23:01:05 +01:00
cmSystemTools::SetInterruptCallback(
[this] { return this->interruptCallback(); });
2012-04-19 19:04:21 +03:00
2016-03-13 13:35:51 +01:00
std::vector<cmake::GeneratorInfo> generators;
2019-11-11 23:01:05 +01:00
this->CMakeInstance->GetRegisteredGenerators(
generators, /*includeNamesWithPlatform=*/false);
2016-03-13 13:35:51 +01:00
2019-11-11 23:01:05 +01:00
for (cmake::GeneratorInfo const& gen : generators) {
this->AvailableGenerators.push_back(gen);
2016-07-09 11:21:54 +02:00
}
2021-09-14 00:13:48 +02:00
connect(&this->LoadPresetsTimer, &QTimer::timeout, this, [this]() {
this->loadPresets();
if (!this->PresetName.isEmpty() &&
this->CMakePresetsFile.ConfigurePresets.find(
std::string(this->PresetName.toLocal8Bit())) ==
this->CMakePresetsFile.ConfigurePresets.end()) {
this->setPreset(QString{});
}
});
this->LoadPresetsTimer.start(1000);
}
2020-08-30 11:54:41 +02:00
QCMake::~QCMake() = default;
void QCMake::loadCache(const QString& dir)
{
this->setBinaryDirectory(dir);
}
2009-10-04 10:30:41 +03:00
void QCMake::setSourceDirectory(const QString& _dir)
{
2016-07-09 11:21:54 +02:00
QString dir = QString::fromLocal8Bit(
cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str());
if (this->SourceDirectory != dir) {
this->SourceDirectory = QDir::fromNativeSeparators(dir);
emit this->sourceDirChanged(this->SourceDirectory);
2021-09-14 00:13:48 +02:00
this->loadPresets();
this->setPreset(QString{});
2016-07-09 11:21:54 +02:00
}
}
2009-10-04 10:30:41 +03:00
void QCMake::setBinaryDirectory(const QString& _dir)
{
2016-07-09 11:21:54 +02:00
QString dir = QString::fromLocal8Bit(
cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str());
if (this->BinaryDirectory != dir) {
this->BinaryDirectory = QDir::fromNativeSeparators(dir);
emit this->binaryDirChanged(this->BinaryDirectory);
2015-08-17 11:37:30 +02:00
cmState* state = this->CMakeInstance->GetState();
this->setGenerator(QString());
2016-03-13 13:35:51 +01:00
this->setToolset(QString());
2019-11-11 23:01:05 +01:00
this->setPlatform(QString());
2016-07-09 11:21:54 +02:00
if (!this->CMakeInstance->LoadCache(
this->BinaryDirectory.toLocal8Bit().data())) {
QDir testDir(this->BinaryDirectory);
2016-07-09 11:21:54 +02:00
if (testDir.exists("CMakeCache.txt")) {
cmSystemTools::Error(
"There is a CMakeCache.txt file for the current binary "
"tree but cmake does not have permission to read it. "
"Please check the permissions of the directory you are trying to "
"run CMake on.");
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
QCMakePropertyList props = this->properties();
emit this->propertiesChanged(props);
2020-08-30 11:54:41 +02:00
cmProp homeDir = state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY");
2016-07-09 11:21:54 +02:00
if (homeDir) {
2020-08-30 11:54:41 +02:00
setSourceDirectory(QString::fromLocal8Bit(homeDir->c_str()));
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
cmProp gen = state->GetCacheEntryValue("CMAKE_GENERATOR");
2016-07-09 11:21:54 +02:00
if (gen) {
2018-10-28 12:09:07 +01:00
const std::string* extraGen =
2016-07-09 11:21:54 +02:00
state->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
std::string curGen =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
2020-08-30 11:54:41 +02:00
*gen, extraGen ? *extraGen : "");
2012-08-04 10:26:08 +03:00
this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
2020-08-30 11:54:41 +02:00
cmProp platform = state->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
2019-11-11 23:01:05 +01:00
if (platform) {
2020-08-30 11:54:41 +02:00
this->setPlatform(QString::fromLocal8Bit(platform->c_str()));
2019-11-11 23:01:05 +01:00
}
2020-08-30 11:54:41 +02:00
cmProp toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
2016-07-09 11:21:54 +02:00
if (toolset) {
2020-08-30 11:54:41 +02:00
this->setToolset(QString::fromLocal8Bit(toolset->c_str()));
}
2018-04-23 21:13:27 +02:00
checkOpenPossible();
2016-07-09 11:21:54 +02:00
}
}
2021-09-14 00:13:48 +02:00
void QCMake::setPreset(const QString& name, bool setBinary)
{
if (this->PresetName != name) {
this->PresetName = name;
emit this->presetChanged(this->PresetName);
if (!name.isNull()) {
std::string presetName(name.toLocal8Bit());
auto const& expandedPreset =
this->CMakePresetsFile.ConfigurePresets[presetName].Expanded;
if (expandedPreset) {
if (setBinary && !expandedPreset->BinaryDir.empty()) {
QString binaryDir =
QString::fromLocal8Bit(expandedPreset->BinaryDir.data());
this->setBinaryDirectory(binaryDir);
}
if (expandedPreset->WarnDev) {
this->CMakeInstance->SetSuppressDevWarnings(
!*expandedPreset->WarnDev);
}
if (expandedPreset->ErrorDev) {
this->CMakeInstance->SetDevWarningsAsErrors(
*expandedPreset->ErrorDev);
}
if (expandedPreset->WarnDeprecated) {
this->CMakeInstance->SetSuppressDeprecatedWarnings(
!*expandedPreset->WarnDeprecated);
}
if (expandedPreset->ErrorDeprecated) {
this->CMakeInstance->SetDeprecatedWarningsAsErrors(
*expandedPreset->ErrorDeprecated);
}
if (expandedPreset->WarnUninitialized) {
this->WarnUninitializedMode = *expandedPreset->WarnUninitialized;
emit this->warnUninitializedModeChanged(
*expandedPreset->WarnUninitialized);
}
this->Environment = this->StartEnvironment;
for (auto const& v : expandedPreset->Environment) {
if (v.second) {
this->Environment.insert(QString::fromLocal8Bit(v.first.data()),
QString::fromLocal8Bit(v.second->data()));
}
}
}
}
emit this->propertiesChanged(this->properties());
}
}
void QCMake::setGenerator(const QString& gen)
{
2016-07-09 11:21:54 +02:00
if (this->Generator != gen) {
this->Generator = gen;
emit this->generatorChanged(this->Generator);
2016-07-09 11:21:54 +02:00
}
}
2019-11-11 23:01:05 +01:00
void QCMake::setPlatform(const QString& platform)
{
if (this->Platform != platform) {
this->Platform = platform;
emit this->platformChanged(this->Platform);
}
}
2016-03-13 13:35:51 +01:00
void QCMake::setToolset(const QString& toolset)
{
2016-07-09 11:21:54 +02:00
if (this->Toolset != toolset) {
2016-03-13 13:35:51 +01:00
this->Toolset = toolset;
emit this->toolsetChanged(this->Toolset);
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
}
2021-09-14 00:13:48 +02:00
void QCMake::setEnvironment(const QProcessEnvironment& environment)
{
this->Environment = environment;
}
void QCMake::configure()
{
2021-09-14 00:13:48 +02:00
int err;
{
cmSystemTools::SaveRestoreEnvironment restoreEnv;
this->setUpEnvironment();
2009-11-06 22:07:41 +02:00
#ifdef Q_OS_WIN
2021-09-14 00:13:48 +02:00
UINT lastErrorMode = SetErrorMode(0);
2009-11-06 22:07:41 +02:00
#endif
2021-09-14 00:13:48 +02:00
this->CMakeInstance->SetHomeDirectory(
this->SourceDirectory.toLocal8Bit().data());
this->CMakeInstance->SetHomeOutputDirectory(
this->BinaryDirectory.toLocal8Bit().data());
this->CMakeInstance->SetGlobalGenerator(
this->CMakeInstance->CreateGlobalGenerator(
this->Generator.toLocal8Bit().data()));
this->CMakeInstance->SetGeneratorPlatform(
this->Platform.toLocal8Bit().data());
this->CMakeInstance->SetGeneratorToolset(
this->Toolset.toLocal8Bit().data());
this->CMakeInstance->LoadCache();
this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
this->CMakeInstance->PreLoadCMakeFiles();
InterruptFlag = 0;
cmSystemTools::ResetErrorOccuredFlag();
err = this->CMakeInstance->Configure();
2009-11-06 22:07:41 +02:00
#ifdef Q_OS_WIN
2021-09-14 00:13:48 +02:00
SetErrorMode(lastErrorMode);
2009-11-06 22:07:41 +02:00
#endif
2021-09-14 00:13:48 +02:00
}
2009-11-06 22:07:41 +02:00
emit this->propertiesChanged(this->properties());
emit this->configureDone(err);
}
void QCMake::generate()
{
2021-09-14 00:13:48 +02:00
int err;
{
cmSystemTools::SaveRestoreEnvironment restoreEnv;
this->setUpEnvironment();
2009-11-06 22:07:41 +02:00
#ifdef Q_OS_WIN
2021-09-14 00:13:48 +02:00
UINT lastErrorMode = SetErrorMode(0);
2009-11-06 22:07:41 +02:00
#endif
2021-09-14 00:13:48 +02:00
InterruptFlag = 0;
cmSystemTools::ResetErrorOccuredFlag();
2012-04-19 19:04:21 +03:00
2021-09-14 00:13:48 +02:00
err = this->CMakeInstance->Generate();
2009-11-06 22:07:41 +02:00
#ifdef Q_OS_WIN
2021-09-14 00:13:48 +02:00
SetErrorMode(lastErrorMode);
2009-11-06 22:07:41 +02:00
#endif
2021-09-14 00:13:48 +02:00
}
2009-11-06 22:07:41 +02:00
emit this->generateDone(err);
2018-04-23 21:13:27 +02:00
checkOpenPossible();
}
void QCMake::open()
{
#ifdef Q_OS_WIN
UINT lastErrorMode = SetErrorMode(0);
#endif
InterruptFlag = 0;
cmSystemTools::ResetErrorOccuredFlag();
auto successful = this->CMakeInstance->Open(
this->BinaryDirectory.toLocal8Bit().data(), false);
#ifdef Q_OS_WIN
SetErrorMode(lastErrorMode);
#endif
emit this->openDone(successful);
}
2013-03-16 19:13:01 +02:00
void QCMake::setProperties(const QCMakePropertyList& newProps)
{
QCMakePropertyList props = newProps;
QStringList toremove;
// set the value of properties
2015-08-17 11:37:30 +02:00
cmState* state = this->CMakeInstance->GetState();
std::vector<std::string> cacheKeys = state->GetCacheEntryKeys();
2019-11-11 23:01:05 +01:00
for (std::string const& key : cacheKeys) {
cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key);
2017-04-14 19:02:05 +02:00
if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC) {
continue;
2016-07-09 11:21:54 +02:00
}
QCMakeProperty prop;
2019-11-11 23:01:05 +01:00
prop.Key = QString::fromLocal8Bit(key.c_str());
int idx = props.indexOf(prop);
2016-07-09 11:21:54 +02:00
if (idx == -1) {
2019-11-11 23:01:05 +01:00
toremove.append(QString::fromLocal8Bit(key.c_str()));
2016-07-09 11:21:54 +02:00
} else {
prop = props[idx];
2021-09-14 00:13:48 +02:00
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
const bool isBool = prop.Value.type() == QVariant::Bool;
#else
const bool isBool = prop.Value.metaType() == QMetaType::fromType<bool>();
#endif
if (isBool) {
2019-11-11 23:01:05 +01:00
state->SetCacheEntryValue(key, prop.Value.toBool() ? "ON" : "OFF");
2016-07-09 11:21:54 +02:00
} else {
2019-11-11 23:01:05 +01:00
state->SetCacheEntryValue(key,
2016-07-09 11:21:54 +02:00
prop.Value.toString().toLocal8Bit().data());
}
2016-07-09 11:21:54 +02:00
props.removeAt(idx);
}
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
// remove some properties
2017-07-20 19:35:53 +02:00
foreach (QString const& s, toremove) {
2012-08-04 10:26:08 +03:00
this->CMakeInstance->UnwatchUnusedCli(s.toLocal8Bit().data());
2011-02-07 16:37:25 +01:00
2015-08-17 11:37:30 +02:00
state->RemoveCacheEntry(s.toLocal8Bit().data());
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2020-02-01 23:06:01 +01:00
// add some new properties
2017-07-20 19:35:53 +02:00
foreach (QCMakeProperty const& s, props) {
2012-08-04 10:26:08 +03:00
this->CMakeInstance->WatchUnusedCli(s.Key.toLocal8Bit().data());
2011-02-07 16:37:25 +01:00
2016-07-09 11:21:54 +02:00
if (s.Type == QCMakeProperty::BOOL) {
this->CMakeInstance->AddCacheEntry(
s.Key.toLocal8Bit().data(), s.Value.toBool() ? "ON" : "OFF",
2017-04-14 19:02:05 +02:00
s.Help.toLocal8Bit().data(), cmStateEnums::BOOL);
2016-07-09 11:21:54 +02:00
} else if (s.Type == QCMakeProperty::STRING) {
this->CMakeInstance->AddCacheEntry(
s.Key.toLocal8Bit().data(), s.Value.toString().toLocal8Bit().data(),
2017-04-14 19:02:05 +02:00
s.Help.toLocal8Bit().data(), cmStateEnums::STRING);
2016-07-09 11:21:54 +02:00
} else if (s.Type == QCMakeProperty::PATH) {
this->CMakeInstance->AddCacheEntry(
s.Key.toLocal8Bit().data(), s.Value.toString().toLocal8Bit().data(),
2017-04-14 19:02:05 +02:00
s.Help.toLocal8Bit().data(), cmStateEnums::PATH);
2016-07-09 11:21:54 +02:00
} else if (s.Type == QCMakeProperty::FILEPATH) {
this->CMakeInstance->AddCacheEntry(
s.Key.toLocal8Bit().data(), s.Value.toString().toLocal8Bit().data(),
2017-04-14 19:02:05 +02:00
s.Help.toLocal8Bit().data(), cmStateEnums::FILEPATH);
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2015-08-17 11:37:30 +02:00
this->CMakeInstance->SaveCache(this->BinaryDirectory.toLocal8Bit().data());
}
QCMakePropertyList QCMake::properties() const
{
QCMakePropertyList ret;
2015-08-17 11:37:30 +02:00
cmState* state = this->CMakeInstance->GetState();
std::vector<std::string> cacheKeys = state->GetCacheEntryKeys();
2019-11-11 23:01:05 +01:00
for (std::string const& key : cacheKeys) {
cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key);
2017-04-14 19:02:05 +02:00
if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC ||
t == cmStateEnums::UNINITIALIZED) {
continue;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
cmProp cachedValue = state->GetCacheEntryValue(key);
2015-08-17 11:37:30 +02:00
QCMakeProperty prop;
2019-11-11 23:01:05 +01:00
prop.Key = QString::fromLocal8Bit(key.c_str());
2020-08-30 11:54:41 +02:00
if (cmProp hs = state->GetCacheEntryProperty(key, "HELPSTRING")) {
prop.Help = QString::fromLocal8Bit(hs->c_str());
}
prop.Value = QString::fromLocal8Bit(cachedValue->c_str());
2019-11-11 23:01:05 +01:00
prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED");
2017-04-14 19:02:05 +02:00
if (t == cmStateEnums::BOOL) {
prop.Type = QCMakeProperty::BOOL;
2020-08-30 11:54:41 +02:00
prop.Value = cmIsOn(*cachedValue);
2017-04-14 19:02:05 +02:00
} else if (t == cmStateEnums::PATH) {
prop.Type = QCMakeProperty::PATH;
2017-04-14 19:02:05 +02:00
} else if (t == cmStateEnums::FILEPATH) {
prop.Type = QCMakeProperty::FILEPATH;
2017-04-14 19:02:05 +02:00
} else if (t == cmStateEnums::STRING) {
prop.Type = QCMakeProperty::STRING;
2020-08-30 11:54:41 +02:00
cmProp stringsProperty = state->GetCacheEntryProperty(key, "STRINGS");
2016-07-09 11:21:54 +02:00
if (stringsProperty) {
2020-08-30 11:54:41 +02:00
prop.Strings =
QString::fromLocal8Bit(stringsProperty->c_str()).split(";");
}
2016-07-09 11:21:54 +02:00
}
ret.append(prop);
2016-07-09 11:21:54 +02:00
}
2021-09-14 00:13:48 +02:00
if (!this->PresetName.isNull()) {
std::string presetName(this->PresetName.toLocal8Bit());
auto const& p =
this->CMakePresetsFile.ConfigurePresets.at(presetName).Expanded;
if (p) {
for (auto const& v : p->CacheVariables) {
if (!v.second) {
continue;
}
QCMakeProperty prop;
prop.Key = QString::fromLocal8Bit(v.first.data());
prop.Value = QString::fromLocal8Bit(v.second->Value.data());
prop.Type = QCMakeProperty::STRING;
if (!v.second->Type.empty()) {
auto type = cmState::StringToCacheEntryType(v.second->Type);
switch (type) {
case cmStateEnums::BOOL:
prop.Type = QCMakeProperty::BOOL;
prop.Value = cmIsOn(v.second->Value);
break;
case cmStateEnums::PATH:
prop.Type = QCMakeProperty::PATH;
break;
case cmStateEnums::FILEPATH:
prop.Type = QCMakeProperty::FILEPATH;
break;
default:
prop.Type = QCMakeProperty::STRING;
break;
}
}
// QCMakeCacheModel prefers variables earlier in the list rather than
// later, so overwrite them if they already exist rather than simply
// appending
bool found = false;
for (auto& orig : ret) {
if (orig.Key == prop.Key) {
orig = prop;
found = true;
break;
}
}
if (!found) {
ret.append(prop);
}
}
}
}
return ret;
}
2013-03-16 19:13:01 +02:00
void QCMake::interrupt()
{
2012-04-19 19:04:21 +03:00
this->InterruptFlag.ref();
}
2019-11-11 23:01:05 +01:00
bool QCMake::interruptCallback()
2012-04-19 19:04:21 +03:00
{
2021-09-14 00:13:48 +02:00
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
2019-11-11 23:01:05 +01:00
return this->InterruptFlag.load();
2021-09-14 00:13:48 +02:00
#else
return this->InterruptFlag.loadRelaxed();
2013-03-16 19:13:01 +02:00
#endif
}
2019-11-11 23:01:05 +01:00
void QCMake::progressCallback(const std::string& msg, float percent)
{
2016-07-09 11:21:54 +02:00
if (percent >= 0) {
2019-11-11 23:01:05 +01:00
emit this->progressChanged(QString::fromStdString(msg), percent);
2016-07-09 11:21:54 +02:00
} else {
2019-11-11 23:01:05 +01:00
emit this->outputMessage(QString::fromStdString(msg));
2016-07-09 11:21:54 +02:00
}
QCoreApplication::processEvents();
}
2019-11-11 23:01:05 +01:00
void QCMake::messageCallback(std::string const& msg, const char* /*title*/)
{
2019-11-11 23:01:05 +01:00
emit this->errorMessage(QString::fromStdString(msg));
QCoreApplication::processEvents();
}
2019-11-11 23:01:05 +01:00
void QCMake::stdoutCallback(std::string const& msg)
2015-04-27 22:25:09 +02:00
{
2019-11-11 23:01:05 +01:00
emit this->outputMessage(QString::fromStdString(msg));
2015-04-27 22:25:09 +02:00
QCoreApplication::processEvents();
}
2019-11-11 23:01:05 +01:00
void QCMake::stderrCallback(std::string const& msg)
2015-04-27 22:25:09 +02:00
{
2019-11-11 23:01:05 +01:00
emit this->outputMessage(QString::fromStdString(msg));
2015-04-27 22:25:09 +02:00
QCoreApplication::processEvents();
}
2021-09-14 00:13:48 +02:00
void QCMake::setUpEnvironment() const
{
auto env = QProcessEnvironment::systemEnvironment();
for (auto const& key : env.keys()) {
cmSystemTools::UnsetEnv(key.toLocal8Bit().data());
}
for (auto const& var : this->Environment.toStringList()) {
cmSystemTools::PutEnv(var.toLocal8Bit().data());
}
}
void QCMake::loadPresets()
{
auto result = this->CMakePresetsFile.ReadProjectPresets(
this->SourceDirectory.toLocal8Bit().data(), true);
if (result != this->LastLoadPresetsResult &&
result != cmCMakePresetsFile::ReadFileResult::READ_OK) {
emit this->presetLoadError(this->SourceDirectory, result);
}
this->LastLoadPresetsResult = result;
QVector<QCMakePreset> presets;
for (auto const& name : this->CMakePresetsFile.ConfigurePresetOrder) {
auto const& it = this->CMakePresetsFile.ConfigurePresets[name];
auto const& p = it.Unexpanded;
if (p.Hidden) {
continue;
}
QCMakePreset preset;
preset.name = std::move(QString::fromLocal8Bit(p.Name.data()));
preset.displayName =
std::move(QString::fromLocal8Bit(p.DisplayName.data()));
preset.description =
std::move(QString::fromLocal8Bit(p.Description.data()));
preset.generator = std::move(QString::fromLocal8Bit(p.Generator.data()));
preset.architecture =
std::move(QString::fromLocal8Bit(p.Architecture.data()));
preset.setArchitecture = !p.ArchitectureStrategy ||
p.ArchitectureStrategy == cmCMakePresetsFile::ArchToolsetStrategy::Set;
preset.toolset = std::move(QString::fromLocal8Bit(p.Toolset.data()));
preset.setToolset = !p.ToolsetStrategy ||
p.ToolsetStrategy == cmCMakePresetsFile::ArchToolsetStrategy::Set;
preset.enabled = it.Expanded && it.Expanded->ConditionResult &&
std::find_if(this->AvailableGenerators.begin(),
this->AvailableGenerators.end(),
[&p](const cmake::GeneratorInfo& g) {
return g.name == p.Generator;
}) != this->AvailableGenerators.end();
presets.push_back(preset);
}
emit this->presetsChanged(presets);
}
QString QCMake::binaryDirectory() const
{
return this->BinaryDirectory;
}
QString QCMake::sourceDirectory() const
{
return this->SourceDirectory;
}
QString QCMake::generator() const
{
return this->Generator;
}
2021-09-14 00:13:48 +02:00
QProcessEnvironment QCMake::environment() const
{
return this->Environment;
}
2016-03-13 13:35:51 +01:00
std::vector<cmake::GeneratorInfo> const& QCMake::availableGenerators() const
{
2016-03-13 13:35:51 +01:00
return AvailableGenerators;
}
void QCMake::deleteCache()
{
// delete cache
2015-08-17 11:37:30 +02:00
this->CMakeInstance->DeleteCache(this->BinaryDirectory.toLocal8Bit().data());
// reload to make our cache empty
2015-08-17 11:37:30 +02:00
this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit no generator and no properties
this->setGenerator(QString());
2016-03-13 13:35:51 +01:00
this->setToolset(QString());
QCMakePropertyList props = this->properties();
emit this->propertiesChanged(props);
}
void QCMake::reloadCache()
{
// emit that the cache was cleaned out
QCMakePropertyList props;
emit this->propertiesChanged(props);
// reload
2015-08-17 11:37:30 +02:00
this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit new cache properties
props = this->properties();
emit this->propertiesChanged(props);
}
2013-03-16 19:13:01 +02:00
void QCMake::setDebugOutput(bool flag)
{
2016-07-09 11:21:54 +02:00
if (flag != this->CMakeInstance->GetDebugOutput()) {
this->CMakeInstance->SetDebugOutputOn(flag);
emit this->debugOutputChanged(flag);
2016-07-09 11:21:54 +02:00
}
}
bool QCMake::getDebugOutput() const
{
return this->CMakeInstance->GetDebugOutput();
}
2016-03-13 13:35:51 +01:00
bool QCMake::getSuppressDevWarnings()
{
return this->CMakeInstance->GetSuppressDevWarnings();
}
void QCMake::setSuppressDevWarnings(bool value)
{
2016-03-13 13:35:51 +01:00
this->CMakeInstance->SetSuppressDevWarnings(value);
}
bool QCMake::getSuppressDeprecatedWarnings()
{
return this->CMakeInstance->GetSuppressDeprecatedWarnings();
}
void QCMake::setSuppressDeprecatedWarnings(bool value)
{
this->CMakeInstance->SetSuppressDeprecatedWarnings(value);
}
bool QCMake::getDevWarningsAsErrors()
{
return this->CMakeInstance->GetDevWarningsAsErrors();
}
void QCMake::setDevWarningsAsErrors(bool value)
{
this->CMakeInstance->SetDevWarningsAsErrors(value);
}
bool QCMake::getDeprecatedWarningsAsErrors()
{
return this->CMakeInstance->GetDeprecatedWarningsAsErrors();
}
void QCMake::setDeprecatedWarningsAsErrors(bool value)
{
this->CMakeInstance->SetDeprecatedWarningsAsErrors(value);
}
2011-02-07 16:37:25 +01:00
void QCMake::setWarnUninitializedMode(bool value)
{
this->WarnUninitializedMode = value;
}
2018-04-23 21:13:27 +02:00
void QCMake::checkOpenPossible()
{
2020-08-30 11:54:41 +02:00
std::string data = this->BinaryDirectory.toLocal8Bit().data();
2018-04-23 21:13:27 +02:00
auto possible = this->CMakeInstance->Open(data, true);
emit openPossible(possible);
}