Feature Request: list() commands should write to CACHE variables

Today we stumbled upon an error in our CMake codebase that comes from
CMP0126 = NEW. It was very hard to find, we were sure that there is no normal variable.
We located the culprit in list() on CACHE variables. This little detail is important here:

Similar to the set() command, the LIST command creates new variable values in the current scope, even if the list itself is actually defined in a parent scope.

I think list should write to the variable it reads from. If it reads from a cache variable (explicitly CACHE{cvar} or implicitly cvar because no normal variable is defined), it should also write to this.

This feature probably also needs a policy flag, because it might break old codebases.

Since changing (non INTERNAL) cache variables needs FORCE, you might also add this the list functions.

I don’t think modifying the cache should be so easy. It is far too easy to end up with states where you need to double-configure to get something to happen (or not happen) from such things. Most cases for INTERNAL cache variables are better served by global properties instead. If you really need to operate on cache variables directly, for the usual APPEND case, you have:

set_property(CACHE cache_var APPEND PROPERTY VALUE appended)

They maybe you should simply forbid (or issue a warning) when using “writing” list function on cache variables. Creating a new non-cache variable is probably never what you want here.

The thing is that users can pass in whatever cache variables they want and “clobber” local variables. I don’t think such hard errors is a nice behavior either.