Cache entry with "=" in name
Consider the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.19)
project(test)
set(var "foo=bar")
set("${var}" "baz" CACHE STRING "")
message(STATUS "var: ${${var}}")
message(STATUS "foo: ${foo}")
The first time this runs via cmake -S . -B build
(Makefile generator, Ubuntu 20.04, CMake 3.19.1), we get the following:
-- var: baz
-- foo:
In my CMakeCache.txt, I see:
$ grep foo build/CMakeCache.txt
foo=bar:STRING=baz
This makes sense. But if I now change "baz" to "INVALID" in the file and try again, I see:
$ cmake -S . -B build
-- var: INVALID
-- foo: bar:STRING=bar
...
$ grep foo build/CMakeCache.txt
foo:UNINITIALIZED=bar:STRING=bar
foo=bar:STRING=INVALID
Which is surprising for a number of reasons. First that the value changed without me touching the cache. Second, that it created a cache entry for foo
when there was no command telling it to do so! I can understand why foo=bar
changed to INVALID
(because the name wasn't properly quoted when saving in the first place).
Now, this is definitely an edge case, but I think it should either work or be formally an error to include a "special" character in a cache entry. There is likely also a similar problem with including a "
at the start of a name in the current format.