forked from qt-creator/qt-creator
CMakePM: Set CMakePM project settings via CMakePresets's vendor field
The field name is "qt.io/QtCreator/1.0": ``` "vendor": { "qt.io/QtCreator/1.0": { "AskBeforePresetsReload": false, "AskReConfigureInitialParams": false, "AutorunCMake": false, "PackageManagerAutoSetup": false, "ShowAdvancedOptionsByDefault": true, "ShowSourceSubFolders": false, "UseJunctionsForSourceAndBuildDirectories": true } } ``` Fixes: QTCREATORBUG-25972 Fixes: QTCREATORBUG-29559 Fixes: QTCREATORBUG-30385 Change-Id: Ifac0d10eebda85f8d97e7a1387325a555101ea6d Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -121,6 +121,14 @@ Internal::PresetsData CMakeProject::combinePresets(Internal::PresetsData &cmakeP
|
||||
result.include = cmakeUserPresetsData.include;
|
||||
}
|
||||
|
||||
result.vendor = cmakePresetsData.vendor;
|
||||
if (result.vendor) {
|
||||
if (cmakeUserPresetsData.vendor)
|
||||
result.vendor->insert(cmakeUserPresetsData.vendor.value());
|
||||
} else {
|
||||
result.vendor = cmakeUserPresetsData.vendor;
|
||||
}
|
||||
|
||||
auto combinePresetsInternal = [](auto &presetsHash,
|
||||
auto &presets,
|
||||
auto &userPresets,
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectimporter.h>
|
||||
#include <projectexplorer/projectpanelfactory.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -122,7 +123,13 @@ CMakeSpecificSettings::CMakeSpecificSettings(Project *p, bool autoApply)
|
||||
|
||||
if (project) {
|
||||
// Re-read the settings. Reading in constructor is too early
|
||||
connect(project, &Project::settingsLoaded, this, [this] {
|
||||
connect(project, &Project::settingsLoaded, this, [this] { readSettings(); });
|
||||
|
||||
connect(project->projectImporter(), &ProjectImporter::cmakePresetsUpdated, this, [this] {
|
||||
// clear settings first
|
||||
Store data;
|
||||
project->setNamedSettings(Constants::Settings::GENERAL_ID, variantFromStore(data));
|
||||
|
||||
readSettings();
|
||||
});
|
||||
}
|
||||
@@ -133,9 +140,24 @@ void CMakeSpecificSettings::readSettings()
|
||||
if (!project) {
|
||||
AspectContainer::readSettings();
|
||||
} else {
|
||||
const Store data = storeFromVariant(project->namedSettings(Constants::Settings::GENERAL_ID));
|
||||
useGlobalSettings = data.value(Constants::Settings::USE_GLOBAL_SETTINGS, true).toBool();
|
||||
fromMap(data);
|
||||
Store data = storeFromVariant(project->namedSettings(Constants::Settings::GENERAL_ID));
|
||||
if (data.isEmpty()) {
|
||||
CMakeProject *cmakeProject = static_cast<CMakeProject *>(project);
|
||||
if (cmakeProject->presetsData().havePresets && cmakeProject->presetsData().vendor) {
|
||||
useGlobalSettings = false;
|
||||
data = storeFromMap(cmakeProject->presetsData().vendor.value());
|
||||
fromMap(data);
|
||||
|
||||
// Write the new loaded CMakePresets settings into .user file
|
||||
writeSettings();
|
||||
} else {
|
||||
useGlobalSettings = true;
|
||||
AspectContainer::readSettings();
|
||||
}
|
||||
} else {
|
||||
useGlobalSettings = data.value(Constants::Settings::USE_GLOBAL_SETTINGS, true).toBool();
|
||||
fromMap(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -435,6 +435,30 @@ bool parseBuildPresets(const QJsonValue &jsonValue,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseVendor(const QJsonValue &jsonValue, std::optional<QVariantMap> &vendorSettings)
|
||||
{
|
||||
// The whole section is optional
|
||||
if (jsonValue.isUndefined())
|
||||
return true;
|
||||
if (!jsonValue.isObject())
|
||||
return false;
|
||||
|
||||
const QJsonObject object = jsonValue.toObject();
|
||||
const QJsonValue qtIo = object.value("qt.io/QtCreator/1.0");
|
||||
if (qtIo.isUndefined())
|
||||
return true;
|
||||
if (!qtIo.isObject())
|
||||
return false;
|
||||
|
||||
const QJsonObject qtIoObject = qtIo.toObject();
|
||||
vendorSettings = QVariantMap();
|
||||
for (const QString &settingKey : qtIoObject.keys()) {
|
||||
const QJsonValue settingValue = qtIoObject.value(settingKey);
|
||||
vendorSettings->insert(settingKey, settingValue.toVariant());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const PresetsData &PresetsParser::presetsData() const
|
||||
{
|
||||
return m_presetsData;
|
||||
@@ -502,6 +526,12 @@ bool PresetsParser::parse(const Utils::FilePath &jsonFile, QString &errorMessage
|
||||
return false;
|
||||
}
|
||||
|
||||
// optional
|
||||
if (!parseVendor(root.value("vendor"), m_presetsData.vendor)) {
|
||||
errorMessage = ::CMakeProjectManager::Tr::tr("Invalid \"vendor\" section in %1 file")
|
||||
.arg(jsonFile.fileName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -142,7 +142,7 @@ public:
|
||||
int version = 0;
|
||||
bool havePresets = false;
|
||||
QVersionNumber cmakeMinimimRequired;
|
||||
QHash<QString, QString> vendor;
|
||||
std::optional<QVariantMap> vendor;
|
||||
std::optional<QStringList> include;
|
||||
Utils::FilePath fileDir;
|
||||
QList<PresetsDetails::ConfigurePreset> configurePresets;
|
||||
|
Reference in New Issue
Block a user