Commit 920d1800 authored by Kyle Edwards's avatar Kyle Edwards
Browse files

CMakePresets.json: Allow boolean for cache variable value

Fixes: #21327
parent ec3b3d2c
Pipeline #195637 passed with stages
in 83 minutes and 14 seconds
......@@ -176,9 +176,10 @@ Format
``cacheVariables``
An optional map of cache variables. The key is the variable name (which
may not be an empty string), and the value is either ``null``, a string
representing the value of the variable (which supports macro expansion),
or an object with the following fields:
may not be an empty string), and the value is either ``null``, a boolean
(which is equivalent to a value of ``"TRUE"`` or ``"FALSE"`` and a type
of ``BOOL``), a string representing the value of the variable (which
supports macro expansion), or an object with the following fields:
``type``
......@@ -186,7 +187,8 @@ Format
``value``
A required string representing the value of the variable. This field
A required string or boolean representing the value of the variable.
A boolean is equivalent to ``"TRUE"`` or ``"FALSE"``. This field
supports macro expansion.
Cache variables are inherited through the ``inherits`` field, and the
......
......@@ -118,6 +118,10 @@
"type": "null",
"description": "Setting a variable to null causes it to not be set, even if a value was inherited from another preset."
},
{
"type": "boolean",
"description": "A boolean representing the value of the variable. Equivalent to \"TRUE\" or \"FALSE\"."
},
{
"type": "string",
"description": "A string representing the value of the variable (which supports macro expansion)."
......@@ -131,8 +135,16 @@
"description": "An optional string representing the type of the variable. It should be BOOL, FILEPATH, PATH, STRING, or INTERNAL."
},
"value": {
"type": "string",
"description": "A required string representing the value of the variable. This field supports macro expansion."
"anyOf": [
{
"type": "boolean",
"description": "A required boolean representing the value of the variable. Equivalent to \"TRUE\" or \"FALSE\"."
},
{
"type": "string",
"description": "A required string representing the value of the variable. This field supports macro expansion."
}
]
}
},
"required": [
......
......@@ -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=*/"",
......
......@@ -46,6 +46,22 @@
"type": "BOOL",
"value": "OFF"
},
"TEST_BOOL_TRUE": true,
"TEST_BOOL_FALSE": false,
"TEST_TYPED_BOOL_TRUE": {
"type": "STRING",
"value": true
},
"TEST_TYPED_BOOL_FALSE": {
"type": "STRING",
"value": false
},
"TEST_UNTYPED_BOOL_TRUE": {
"value": true
},
"TEST_UNTYPED_BOOL_FALSE": {
"value": false
},
"TEST_PRESET_NAME": {
"type": "STRING",
"value": "x${presetName}x"
......
Preset CMake variables:
TEST_BOOL_FALSE:BOOL="FALSE"
TEST_BOOL_TRUE:BOOL="TRUE"
TEST_DOLLAR="\$"
TEST_D_ENV_REF="xEnvironment variablex"
TEST_D_ENV_REF_P=""
......@@ -32,6 +34,10 @@ Preset CMake variables:
TEST_TRAILING_DOLLAR="a \$"
TEST_TRAILING_UNKNOWN_NAMESPACE="\$unknown{namespace"
TEST_TRUE:BOOL="TRUE"
TEST_TYPED_BOOL_FALSE:STRING="FALSE"
TEST_TYPED_BOOL_TRUE:STRING="TRUE"
TEST_UNTYPED_BOOL_FALSE="FALSE"
TEST_UNTYPED_BOOL_TRUE="TRUE"
Preset environment variables:
......
......@@ -8,6 +8,12 @@ test_variable(TEST_SOURCE_PARENT_DIR "PATH" "${_parent_dir}")
test_variable(TEST_SOURCE_LIST "FILEPATH" "${CMAKE_SOURCE_DIR}/CMakeLists.txt")
test_variable(TEST_TRUE "BOOL" "TRUE")
test_variable(TEST_OFF "BOOL" "OFF")
test_variable(TEST_BOOL_TRUE "BOOL" "TRUE")
test_variable(TEST_BOOL_FALSE "BOOL" "FALSE")
test_variable(TEST_TYPED_BOOL_TRUE "STRING" "TRUE")
test_variable(TEST_TYPED_BOOL_FALSE "STRING" "FALSE")
test_variable(TEST_UNTYPED_BOOL_TRUE "UNINITIALIZED" "TRUE")
test_variable(TEST_UNTYPED_BOOL_FALSE "UNINITIALIZED" "FALSE")
test_variable(TEST_PRESET_NAME "STRING" "xGoodx")
test_variable(TEST_GENERATOR "UNINITIALIZED" "x${CMAKE_GENERATOR}x")
test_variable(TEST_DOLLAR "UNINITIALIZED" "$")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment