summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-04 15:54:41 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-05-04 15:54:49 (GMT)
commit09f2f5df89a72d8394bdc21de0c1f599fdbbb27a (patch)
tree9cdfe8518fe4733973158cd3a4267757d357dc33 /Source
parentabc78a35578de4260f497ecd924ca3323fb17604 (diff)
parenta9b968bb9894902e2183a4aea4c23701d5666733 (diff)
downloadCMake-09f2f5df89a72d8394bdc21de0c1f599fdbbb27a.zip
CMake-09f2f5df89a72d8394bdc21de0c1f599fdbbb27a.tar.gz
CMake-09f2f5df89a72d8394bdc21de0c1f599fdbbb27a.tar.bz2
Merge topic 'extend_toolchain_flag_to_cmake_preset'
a9b968bb98 cmake-presets: Introduce `toolchainFile` preset option Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6045
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCMakePresetsFile.cxx10
-rw-r--r--Source/cmCMakePresetsFile.h2
-rw-r--r--Source/cmCMakePresetsFileReadJSON.cxx7
-rw-r--r--Source/cmake.cxx7
4 files changed, 26 insertions, 0 deletions
diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx
index 39cce98..2f9972c 100644
--- a/Source/cmCMakePresetsFile.cxx
+++ b/Source/cmCMakePresetsFile.cxx
@@ -214,6 +214,12 @@ bool ExpandMacros(const cmCMakePresetsFile& file,
cmSystemTools::ConvertToUnixSlashes(out->InstallDir);
}
+ if (!preset.ToolchainFile.empty()) {
+ std::string toolchain = preset.ToolchainFile;
+ CHECK_EXPAND(out, toolchain, macroExpanders, file.GetVersion(preset))
+ out->ToolchainFile = toolchain;
+ }
+
for (auto& variable : out->CacheVariables) {
if (variable.second) {
CHECK_EXPAND(out, variable.second->Value, macroExpanders,
@@ -643,6 +649,7 @@ cmCMakePresetsFile::ConfigurePreset::VisitPresetInherit(
}
InheritString(preset.BinaryDir, parent.BinaryDir);
InheritString(preset.InstallDir, parent.InstallDir);
+ InheritString(preset.ToolchainFile, parent.ToolchainFile);
InheritOptionalValue(preset.WarnDev, parent.WarnDev);
InheritOptionalValue(preset.ErrorDev, parent.ErrorDev);
InheritOptionalValue(preset.WarnDeprecated, parent.WarnDeprecated);
@@ -989,6 +996,9 @@ const char* cmCMakePresetsFile::ResultToString(ReadFileResult result)
return "Invalid preset condition";
case ReadFileResult::CONDITION_UNSUPPORTED:
return "File version must be 3 or higher for condition support";
+ case ReadFileResult::TOOLCHAIN_FILE_UNSUPPORTED:
+ return "File version must be 3 or higher for toolchainFile preset "
+ "support.";
}
return "Unknown error";
diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h
index fc14830..7aa9b6a 100644
--- a/Source/cmCMakePresetsFile.h
+++ b/Source/cmCMakePresetsFile.h
@@ -39,6 +39,7 @@ public:
INSTALL_PREFIX_UNSUPPORTED,
INVALID_CONDITION,
CONDITION_UNSUPPORTED,
+ TOOLCHAIN_FILE_UNSUPPORTED,
};
enum class ArchToolsetStrategy
@@ -113,6 +114,7 @@ public:
cm::optional<ArchToolsetStrategy> ArchitectureStrategy;
std::string Toolset;
cm::optional<ArchToolsetStrategy> ToolsetStrategy;
+ std::string ToolchainFile;
std::string BinaryDir;
std::string InstallDir;
diff --git a/Source/cmCMakePresetsFileReadJSON.cxx b/Source/cmCMakePresetsFileReadJSON.cxx
index 403fac6..909a78b 100644
--- a/Source/cmCMakePresetsFileReadJSON.cxx
+++ b/Source/cmCMakePresetsFileReadJSON.cxx
@@ -491,6 +491,8 @@ auto const ConfigurePresetHelper =
false)
.Bind("architecture"_s, ArchitectureHelper, false)
.Bind("toolset"_s, ToolsetHelper, false)
+ .Bind("toolchainFile"_s, &ConfigurePreset::ToolchainFile,
+ PresetStringHelper, false)
.Bind("binaryDir"_s, &ConfigurePreset::BinaryDir, PresetStringHelper,
false)
.Bind("installDir"_s, &ConfigurePreset::InstallDir, PresetStringHelper,
@@ -973,6 +975,11 @@ cmCMakePresetsFile::ReadFileResult cmCMakePresetsFile::ReadJSONFile(
return ReadFileResult::CONDITION_UNSUPPORTED;
}
+ // Support for toolchainFile presets added in version 3.
+ if (v < 3 && !preset.ToolchainFile.empty()) {
+ return ReadFileResult::TOOLCHAIN_FILE_UNSUPPORTED;
+ }
+
this->ConfigurePresetOrder.push_back(preset.Name);
}
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index d24e268..4130f5f 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1257,6 +1257,13 @@ void cmake::SetArgs(const std::vector<std::string>& args)
"PATH", expandedPreset->InstallDir
};
}
+ if (!expandedPreset->ToolchainFile.empty() &&
+ this->State->GetInitializedCacheValue("CMAKE_TOOLCHAIN_FILE") ==
+ nullptr) {
+ this->UnprocessedPresetVariables["CMAKE_TOOLCHAIN_FILE"] = {
+ "FILEPATH", expandedPreset->ToolchainFile
+ };
+ }
if (!expandedPreset->ArchitectureStrategy ||
expandedPreset->ArchitectureStrategy ==