diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-10-16 20:19:11 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2020-10-22 15:24:39 (GMT) |
commit | 64afabdbcb265acb53a9b8f8cb86465d31f2ca61 (patch) | |
tree | ca2616a38a2bf7c80d8635d7fd0f2957645a0a45 /Source | |
parent | 609122007dc074739b394d2f70f674bbccca6073 (diff) | |
download | CMake-64afabdbcb265acb53a9b8f8cb86465d31f2ca61.zip CMake-64afabdbcb265acb53a9b8f8cb86465d31f2ca61.tar.gz CMake-64afabdbcb265acb53a9b8f8cb86465d31f2ca61.tar.bz2 |
CMakePresets.json: Split cmakeGeneratorConfig field
Make this field separate for both architecture and toolset. Allow
architecture and toolset to be either strings or objects with value
and strategy fields.
Fixes: #21317
Diffstat (limited to 'Source')
-rw-r--r-- | Source/QtDialog/CMakeSetupDialog.cxx | 4 | ||||
-rw-r--r-- | Source/QtDialog/QCMake.cxx | 6 | ||||
-rw-r--r-- | Source/QtDialog/QCMakePreset.cxx | 17 | ||||
-rw-r--r-- | Source/QtDialog/QCMakePreset.h | 3 | ||||
-rw-r--r-- | Source/cmCMakePresetsFile.cxx | 66 | ||||
-rw-r--r-- | Source/cmCMakePresetsFile.h | 9 | ||||
-rw-r--r-- | Source/cmake.cxx | 10 |
7 files changed, 83 insertions, 32 deletions
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 7a04daa..a15614d 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -859,8 +859,10 @@ bool CMakeSetupDialog::setupFirstConfigure() if (presetData.isValid()) { auto preset = presetData.value<QCMakePreset>(); dialog.setCurrentGenerator(preset.generator); - if (preset.setGenConfig) { + if (preset.setArchitecture) { dialog.setPlatform(preset.architecture); + } + if (preset.setToolset) { dialog.setToolset(preset.toolset); } dialog.setCompilerOption(CompilerOption::DefaultNative); diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 3789e93..2f41f70 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -551,9 +551,11 @@ void QCMake::loadPresets() 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.setGenConfig = !p.GeneratorConfig || - p.GeneratorConfig == cmCMakePresetsFile::CMakeGeneratorConfig::Default; + preset.setToolset = !p.ToolsetStrategy || + p.ToolsetStrategy == cmCMakePresetsFile::ArchToolsetStrategy::Set; preset.enabled = it.Expanded && std::find_if(this->AvailableGenerators.begin(), this->AvailableGenerators.end(), diff --git a/Source/QtDialog/QCMakePreset.cxx b/Source/QtDialog/QCMakePreset.cxx index b10cf07..176f532 100644 --- a/Source/QtDialog/QCMakePreset.cxx +++ b/Source/QtDialog/QCMakePreset.cxx @@ -6,8 +6,9 @@ bool operator==(const QCMakePreset& lhs, const QCMakePreset& rhs) { return lhs.name == rhs.name && lhs.displayName == rhs.displayName && lhs.description == rhs.description && lhs.generator == rhs.generator && - lhs.architecture == rhs.architecture && lhs.toolset == rhs.toolset && - lhs.setGenConfig == rhs.setGenConfig && lhs.enabled == rhs.enabled; + lhs.architecture == rhs.architecture && + lhs.setArchitecture == rhs.setArchitecture && lhs.toolset == rhs.toolset && + lhs.setToolset == rhs.setToolset && lhs.enabled == rhs.enabled; } bool operator!=(const QCMakePreset& lhs, const QCMakePreset& rhs) @@ -27,11 +28,13 @@ bool operator<(const QCMakePreset& lhs, const QCMakePreset& rhs) (lhs.generator == rhs.generator && (lhs.architecture < rhs.architecture || (lhs.architecture == rhs.architecture && - (lhs.toolset < rhs.toolset || - (lhs.toolset == rhs.toolset && - (lhs.setGenConfig < rhs.setGenConfig || - (lhs.setGenConfig == rhs.setGenConfig && - (lhs.enabled < rhs.enabled)))))))))))))); + (lhs.setArchitecture < rhs.setArchitecture || + (lhs.setArchitecture == rhs.setArchitecture && + (lhs.toolset < rhs.toolset || + (lhs.toolset == rhs.toolset && + (lhs.setToolset < rhs.setToolset || + (lhs.setToolset == rhs.setToolset && + (lhs.enabled < rhs.enabled)))))))))))))))); } bool operator<=(const QCMakePreset& lhs, const QCMakePreset& rhs) diff --git a/Source/QtDialog/QCMakePreset.h b/Source/QtDialog/QCMakePreset.h index 93d70d8..1609fcb 100644 --- a/Source/QtDialog/QCMakePreset.h +++ b/Source/QtDialog/QCMakePreset.h @@ -15,8 +15,9 @@ public: QString description; QString generator; QString architecture; + bool setArchitecture; QString toolset; - bool setGenConfig; + bool setToolset; bool enabled; }; diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx index b3bb6df..34a313b 100644 --- a/Source/cmCMakePresetsFile.cxx +++ b/Source/cmCMakePresetsFile.cxx @@ -30,7 +30,7 @@ using ReadFileResult = cmCMakePresetsFile::ReadFileResult; using CacheVariable = cmCMakePresetsFile::CacheVariable; using UnexpandedPreset = cmCMakePresetsFile::UnexpandedPreset; using ExpandedPreset = cmCMakePresetsFile::ExpandedPreset; -using CMakeGeneratorConfig = cmCMakePresetsFile::CMakeGeneratorConfig; +using ArchToolsetStrategy = cmCMakePresetsFile::ArchToolsetStrategy; constexpr int MIN_VERSION = 1; constexpr int MAX_VERSION = 1; @@ -212,8 +212,8 @@ auto const PresetDebugHelper = .Bind("find"_s, &UnexpandedPreset::DebugFind, PresetOptionalBoolHelper, false); -ReadFileResult CMakeGeneratorConfigHelper( - cm::optional<CMakeGeneratorConfig>& out, const Json::Value* value) +ReadFileResult ArchToolsetStrategyHelper( + cm::optional<ArchToolsetStrategy>& out, const Json::Value* value) { if (!value) { out = cm::nullopt; @@ -224,19 +224,56 @@ ReadFileResult CMakeGeneratorConfigHelper( return ReadFileResult::INVALID_PRESET; } - if (value->asString() == "default") { - out = CMakeGeneratorConfig::Default; + if (value->asString() == "set") { + out = ArchToolsetStrategy::Set; return ReadFileResult::READ_OK; } - if (value->asString() == "ignore") { - out = CMakeGeneratorConfig::Ignore; + if (value->asString() == "external") { + out = ArchToolsetStrategy::External; return ReadFileResult::READ_OK; } return ReadFileResult::INVALID_PRESET; } +std::function<ReadFileResult(UnexpandedPreset&, const Json::Value*)> +ArchToolsetHelper( + std::string UnexpandedPreset::*valueField, + cm::optional<ArchToolsetStrategy> UnexpandedPreset::*strategyField) +{ + auto const objectHelper = + cmJSONObjectHelper<UnexpandedPreset, ReadFileResult>( + ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET, false) + .Bind("value", valueField, PresetStringHelper, false) + .Bind("strategy", strategyField, ArchToolsetStrategyHelper, false); + return [valueField, strategyField, objectHelper]( + UnexpandedPreset& out, const Json::Value* value) -> ReadFileResult { + if (!value) { + (out.*valueField).clear(); + out.*strategyField = cm::nullopt; + return ReadFileResult::READ_OK; + } + + if (value->isString()) { + out.*valueField = value->asString(); + out.*strategyField = cm::nullopt; + return ReadFileResult::READ_OK; + } + + if (value->isObject()) { + return objectHelper(out, value); + } + + return ReadFileResult::INVALID_PRESET; + }; +} + +auto const ArchitectureHelper = ArchToolsetHelper( + &UnexpandedPreset::Architecture, &UnexpandedPreset::ArchitectureStrategy); +auto const ToolsetHelper = ArchToolsetHelper( + &UnexpandedPreset::Toolset, &UnexpandedPreset::ToolsetStrategy); + auto const PresetHelper = cmJSONObjectHelper<UnexpandedPreset, ReadFileResult>( ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET, false) @@ -252,11 +289,8 @@ auto const PresetHelper = false) .Bind("generator"_s, &UnexpandedPreset::Generator, PresetStringHelper, false) - .Bind("architecture"_s, &UnexpandedPreset::Architecture, - PresetStringHelper, false) - .Bind("toolset"_s, &UnexpandedPreset::Toolset, PresetStringHelper, false) - .Bind("cmakeGeneratorConfig"_s, &UnexpandedPreset::GeneratorConfig, - CMakeGeneratorConfigHelper, false) + .Bind("architecture"_s, ArchitectureHelper, false) + .Bind("toolset"_s, ToolsetHelper, false) .Bind("binaryDir"_s, &UnexpandedPreset::BinaryDir, PresetStringHelper, false) .Bind<std::string>("cmakeExecutable"_s, nullptr, PresetStringHelper, false) @@ -353,8 +387,12 @@ ReadFileResult VisitPreset( InheritString(preset.Generator, parent->second.Unexpanded.Generator); InheritString(preset.Architecture, parent->second.Unexpanded.Architecture); InheritString(preset.Toolset, parent->second.Unexpanded.Toolset); - if (!preset.GeneratorConfig) { - preset.GeneratorConfig = parent->second.Unexpanded.GeneratorConfig; + if (!preset.ArchitectureStrategy) { + preset.ArchitectureStrategy = + parent->second.Unexpanded.ArchitectureStrategy; + } + if (!preset.ToolsetStrategy) { + preset.ToolsetStrategy = parent->second.Unexpanded.ToolsetStrategy; } InheritString(preset.BinaryDir, parent->second.Unexpanded.BinaryDir); InheritOptionalBool(preset.WarnDev, parent->second.Unexpanded.WarnDev); diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h index 87797d7..f6b159a 100644 --- a/Source/cmCMakePresetsFile.h +++ b/Source/cmCMakePresetsFile.h @@ -12,10 +12,10 @@ class cmCMakePresetsFile { public: - enum class CMakeGeneratorConfig + enum class ArchToolsetStrategy { - Default, - Ignore, + Set, + External, }; class CacheVariable @@ -50,8 +50,9 @@ public: std::string Description; std::string Generator; std::string Architecture; + cm::optional<ArchToolsetStrategy> ArchitectureStrategy; std::string Toolset; - cm::optional<CMakeGeneratorConfig> GeneratorConfig; + cm::optional<ArchToolsetStrategy> ToolsetStrategy; std::string BinaryDir; std::map<std::string, cm::optional<CacheVariable>> CacheVariables; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5b6bd1e..291ce22 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1069,12 +1069,16 @@ void cmake::SetArgs(const std::vector<std::string>& args) this->UnprocessedPresetVariables = expandedPreset->CacheVariables; this->UnprocessedPresetEnvironment = expandedPreset->Environment; - if (!expandedPreset->GeneratorConfig || - expandedPreset->GeneratorConfig == - cmCMakePresetsFile::CMakeGeneratorConfig::Default) { + if (!expandedPreset->ArchitectureStrategy || + expandedPreset->ArchitectureStrategy == + cmCMakePresetsFile::ArchToolsetStrategy::Set) { if (!this->GeneratorPlatformSet) { this->SetGeneratorPlatform(expandedPreset->Architecture); } + } + if (!expandedPreset->ToolsetStrategy || + expandedPreset->ToolsetStrategy == + cmCMakePresetsFile::ArchToolsetStrategy::Set) { if (!this->GeneratorToolsetSet) { this->SetGeneratorToolset(expandedPreset->Toolset); } |