From 370370364b178e90cff291cfdcffe89716cd09dc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 3 Jan 2024 14:48:19 -0500 Subject: cmake-gui: Add support for preset toolchain entry Previously the toolchain field was ignored when passing a preset to cmake-gui. Fixes: #24034 --- Source/QtDialog/QCMake.cxx | 96 ++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index f43f05f..8d63f6d 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -378,6 +378,54 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) this->CMakeInstance->SaveCache(this->BinaryDirectory.toStdString()); } +namespace { +template +QCMakeProperty cache_to_property(const T& v) +{ + QCMakeProperty prop; + prop.Key = QString::fromStdString(v.first); + prop.Value = QString::fromStdString(v.second->Value); + 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; + } + } + return prop; +} + +void add_to_property_list(QCMakePropertyList& list, QCMakeProperty&& prop) +{ + // 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 : list) { + if (orig.Key == prop.Key) { + orig = prop; + found = true; + break; + } + } + if (!found) { + list.append(prop); + } +} +} + QCMakePropertyList QCMake::properties() const { QCMakePropertyList ret; @@ -423,47 +471,21 @@ QCMakePropertyList QCMake::properties() const auto const& p = this->CMakePresetsGraph.ConfigurePresets.at(presetName).Expanded; if (p) { + if (!p->ToolchainFile.empty()) { + using CacheVariable = cmCMakePresetsGraph::CacheVariable; + CacheVariable var{ "FILEPATH", p->ToolchainFile }; + std::pair> value = { + "CMAKE_TOOLCHAIN_FILE", var + }; + auto prop = cache_to_property(value); + add_to_property_list(ret, std::move(prop)); + } for (auto const& v : p->CacheVariables) { if (!v.second) { continue; } - QCMakeProperty prop; - prop.Key = QString::fromStdString(v.first); - prop.Value = QString::fromStdString(v.second->Value); - 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); - } + auto prop = cache_to_property(v); + add_to_property_list(ret, std::move(prop)); } } } -- cgit v0.12