diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-10-19 18:01:40 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2020-10-21 14:37:08 (GMT) |
commit | 920d18004731c97a828a937e2074b6882ffeb20d (patch) | |
tree | 300fb2ca724c39e0f9498736f8b48d0a5bf62fa0 /Source/cmCMakePresetsFile.cxx | |
parent | ec3b3d2c2f16397b9a40f79a9783f3d207088b93 (diff) | |
download | CMake-920d18004731c97a828a937e2074b6882ffeb20d.zip CMake-920d18004731c97a828a937e2074b6882ffeb20d.tar.gz CMake-920d18004731c97a828a937e2074b6882ffeb20d.tar.bz2 |
CMakePresets.json: Allow boolean for cache variable value
Fixes: #21327
Diffstat (limited to 'Source/cmCMakePresetsFile.cxx')
-rw-r--r-- | Source/cmCMakePresetsFile.cxx | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx index 90a0faa..456094f 100644 --- a/Source/cmCMakePresetsFile.cxx +++ b/Source/cmCMakePresetsFile.cxx @@ -77,15 +77,37 @@ auto const RootVersionHelper = auto const VariableStringHelper = cmJSONStringHelper<ReadFileResult>( ReadFileResult::READ_OK, ReadFileResult::INVALID_VARIABLE); +ReadFileResult VariableValueHelper(std::string& out, const Json::Value* value) +{ + if (!value) { + out.clear(); + return ReadFileResult::READ_OK; + } + + if (value->isBool()) { + out = value->asBool() ? "TRUE" : "FALSE"; + return ReadFileResult::READ_OK; + } + + return VariableStringHelper(out, value); +} + auto const VariableObjectHelper = cmJSONObjectHelper<CacheVariable, ReadFileResult>( ReadFileResult::READ_OK, ReadFileResult::INVALID_VARIABLE, false) .Bind("type"_s, &CacheVariable::Type, VariableStringHelper, false) - .Bind("value"_s, &CacheVariable::Value, VariableStringHelper); + .Bind("value"_s, &CacheVariable::Value, VariableValueHelper); ReadFileResult VariableHelper(cm::optional<CacheVariable>& out, const Json::Value* value) { + if (value->isBool()) { + out = CacheVariable{ + /*Type=*/"BOOL", + /*Value=*/value->asBool() ? "TRUE" : "FALSE", + }; + return ReadFileResult::READ_OK; + } if (value->isString()) { out = CacheVariable{ /*Type=*/"", |