STRING(JSON ... SET ...) output unexpected
I'm using cmake version 3.20.2 given script:
set(VAR_STR "15.2.3a")
string(JSON VAR_JSON SET "{}" "Variable" "${VAR_STR}")
message("${VAR_JSON}")
output JSON is:
{
"Variable" : 15.199999999999999
}
what I was expecting to get was:
{
"Variable" : "15.2.3a"
}
so I tried with adding extra escaped quotes:
string(JSON VAR_JSON SET "{}" "Variable" "\"${VAR_STR}\"")
message("${VAR_JSON}")
which produces wanted output, but then if string had quote inside (set(VAR_STR "t\"est")
) the output is truncated still.
I find it odd that since cmake variable are strings by default they would need additional escaped quotes to output string to JSON. And then comes another problem of having exiting quotes inside cmake variable, and they would need additional escaping to be properly written.
I would expect that first example produces output like wanted example, and possibly having VERBATIM which would produce output like it is current behavior.