summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorfriendlyanon <friendlyanon_@hotmail.com>2021-03-26 12:31:43 (GMT)
committerfriendlyanon <friendlyanon_@hotmail.com>2021-04-06 23:24:44 (GMT)
commit06e69813360560347434a5320f1a366ba004e033 (patch)
tree7d73bde2c3a04079d173cbfce540d40f75413a72 /Source
parent46393e8977ed0aba5536e6108c78db07615616ba (diff)
downloadCMake-06e69813360560347434a5320f1a366ba004e033.zip
CMake-06e69813360560347434a5320f1a366ba004e033.tar.gz
CMake-06e69813360560347434a5320f1a366ba004e033.tar.bz2
cmake-presets: Make generator and binaryDir fields optional
In v3 of the presets, generator and buildDir can be omitted to fall back to regular cmake behavior when these values are not explicitly provided by the user. Fixes: #21987
Diffstat (limited to 'Source')
-rw-r--r--Source/QtDialog/QCMake.cxx2
-rw-r--r--Source/cmCMakePresetsFile.cxx38
-rw-r--r--Source/cmCMakePresetsFile.h8
-rw-r--r--Source/cmake.cxx9
4 files changed, 33 insertions, 24 deletions
diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx
index 7d037e3..6796e25 100644
--- a/Source/QtDialog/QCMake.cxx
+++ b/Source/QtDialog/QCMake.cxx
@@ -160,7 +160,7 @@ void QCMake::setPreset(const QString& name, bool setBinary)
auto const& expandedPreset =
this->CMakePresetsFile.ConfigurePresets[presetName].Expanded;
if (expandedPreset) {
- if (setBinary) {
+ if (setBinary && !expandedPreset->BinaryDir.empty()) {
QString binaryDir =
QString::fromLocal8Bit(expandedPreset->BinaryDir.data());
this->setBinaryDirectory(binaryDir);
diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx
index d44dfb3..39cce98 100644
--- a/Source/cmCMakePresetsFile.cxx
+++ b/Source/cmCMakePresetsFile.cxx
@@ -78,7 +78,7 @@ void InheritVector(std::vector<T>& child, const std::vector<T>& parent)
template <class T>
ReadFileResult VisitPreset(
T& preset, std::map<std::string, cmCMakePresetsFile::PresetPair<T>>& presets,
- std::map<std::string, CycleStatus> cycleStatus)
+ std::map<std::string, CycleStatus> cycleStatus, int version)
{
switch (cycleStatus[preset.Name]) {
case CycleStatus::InProgress:
@@ -108,7 +108,7 @@ ReadFileResult VisitPreset(
return ReadFileResult::USER_PRESET_INHERITANCE;
}
- auto result = VisitPreset(parentPreset, presets, cycleStatus);
+ auto result = VisitPreset(parentPreset, presets, cycleStatus, version);
if (result != ReadFileResult::READ_OK) {
return result;
}
@@ -128,7 +128,7 @@ ReadFileResult VisitPreset(
preset.ConditionEvaluator.reset();
}
- CHECK_OK(preset.VisitPresetAfterInherit())
+ CHECK_OK(preset.VisitPresetAfterInherit(version))
cycleStatus[preset.Name] = CycleStatus::Verified;
return ReadFileResult::READ_OK;
@@ -136,7 +136,8 @@ ReadFileResult VisitPreset(
template <class T>
ReadFileResult ComputePresetInheritance(
- std::map<std::string, cmCMakePresetsFile::PresetPair<T>>& presets)
+ std::map<std::string, cmCMakePresetsFile::PresetPair<T>>& presets,
+ const cmCMakePresetsFile& file)
{
std::map<std::string, CycleStatus> cycleStatus;
for (auto const& it : presets) {
@@ -144,7 +145,9 @@ ReadFileResult ComputePresetInheritance(
}
for (auto& it : presets) {
- auto result = VisitPreset<T>(it.second.Unexpanded, presets, cycleStatus);
+ auto& preset = it.second.Unexpanded;
+ auto result =
+ VisitPreset<T>(preset, presets, cycleStatus, file.GetVersion(preset));
if (result != ReadFileResult::READ_OK) {
return result;
}
@@ -667,16 +670,19 @@ cmCMakePresetsFile::ConfigurePreset::VisitPresetBeforeInherit()
}
cmCMakePresetsFile::ReadFileResult
-cmCMakePresetsFile::ConfigurePreset::VisitPresetAfterInherit()
+cmCMakePresetsFile::ConfigurePreset::VisitPresetAfterInherit(int version)
{
auto& preset = *this;
if (!preset.Hidden) {
- if (preset.Generator.empty()) {
- return ReadFileResult::INVALID_PRESET;
- }
- if (preset.BinaryDir.empty()) {
- return ReadFileResult::INVALID_PRESET;
+ if (version < 3) {
+ if (preset.Generator.empty()) {
+ return ReadFileResult::INVALID_PRESET;
+ }
+ if (preset.BinaryDir.empty()) {
+ return ReadFileResult::INVALID_PRESET;
+ }
}
+
if (preset.WarnDev == false && preset.ErrorDev == true) {
return ReadFileResult::INVALID_PRESET;
}
@@ -712,7 +718,7 @@ cmCMakePresetsFile::BuildPreset::VisitPresetInherit(
}
cmCMakePresetsFile::ReadFileResult
-cmCMakePresetsFile::BuildPreset::VisitPresetAfterInherit()
+cmCMakePresetsFile::BuildPreset::VisitPresetAfterInherit(int /* version */)
{
auto& preset = *this;
if (!preset.Hidden && preset.ConfigurePreset.empty()) {
@@ -822,7 +828,7 @@ cmCMakePresetsFile::TestPreset::VisitPresetInherit(
}
cmCMakePresetsFile::ReadFileResult
-cmCMakePresetsFile::TestPreset::VisitPresetAfterInherit()
+cmCMakePresetsFile::TestPreset::VisitPresetAfterInherit(int /* version */)
{
auto& preset = *this;
if (!preset.Hidden && preset.ConfigurePreset.empty()) {
@@ -883,9 +889,9 @@ cmCMakePresetsFile::ReadProjectPresetsInternal(bool allowNoFiles)
: ReadFileResult::FILE_NOT_FOUND;
}
- CHECK_OK(ComputePresetInheritance(this->ConfigurePresets))
- CHECK_OK(ComputePresetInheritance(this->BuildPresets))
- CHECK_OK(ComputePresetInheritance(this->TestPresets))
+ CHECK_OK(ComputePresetInheritance(this->ConfigurePresets, *this))
+ CHECK_OK(ComputePresetInheritance(this->BuildPresets, *this))
+ CHECK_OK(ComputePresetInheritance(this->TestPresets, *this))
for (auto& it : this->ConfigurePresets) {
if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h
index 0999d5a..fc14830 100644
--- a/Source/cmCMakePresetsFile.h
+++ b/Source/cmCMakePresetsFile.h
@@ -89,7 +89,7 @@ public:
return ReadFileResult::READ_OK;
}
- virtual ReadFileResult VisitPresetAfterInherit()
+ virtual ReadFileResult VisitPresetAfterInherit(int /* version */)
{
return ReadFileResult::READ_OK;
}
@@ -132,7 +132,7 @@ public:
ReadFileResult VisitPresetInherit(const Preset& parent) override;
ReadFileResult VisitPresetBeforeInherit() override;
- ReadFileResult VisitPresetAfterInherit() override;
+ ReadFileResult VisitPresetAfterInherit(int version) override;
};
class BuildPreset : public Preset
@@ -158,7 +158,7 @@ public:
std::vector<std::string> NativeToolOptions;
ReadFileResult VisitPresetInherit(const Preset& parent) override;
- ReadFileResult VisitPresetAfterInherit() override;
+ ReadFileResult VisitPresetAfterInherit(int /* version */) override;
};
class TestPreset : public Preset
@@ -285,7 +285,7 @@ public:
cm::optional<ExecutionOptions> Execution;
ReadFileResult VisitPresetInherit(const Preset& parent) override;
- ReadFileResult VisitPresetAfterInherit() override;
+ ReadFileResult VisitPresetAfterInherit(int /* version */) override;
};
template <class T>
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index a04338f..1d4bbf4 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1223,10 +1223,11 @@ void cmake::SetArgs(const std::vector<std::string>& args)
return;
}
- if (!this->State->IsCacheLoaded() && !haveBArg) {
+ if (!this->State->IsCacheLoaded() && !haveBArg &&
+ !expandedPreset->BinaryDir.empty()) {
this->SetHomeOutputDirectory(expandedPreset->BinaryDir);
}
- if (!this->GlobalGenerator) {
+ if (!this->GlobalGenerator && !expandedPreset->Generator.empty()) {
if (!this->CreateAndSetGlobalGenerator(expandedPreset->Generator,
false)) {
return;
@@ -3203,7 +3204,9 @@ int cmake::Build(int jobs, std::string dir, std::vector<std::string> targets,
return 1;
}
- dir = expandedConfigurePreset->BinaryDir;
+ if (!expandedConfigurePreset->BinaryDir.empty()) {
+ dir = expandedConfigurePreset->BinaryDir;
+ }
this->UnprocessedPresetEnvironment = expandedPreset->Environment;
this->ProcessPresetEnvironment();