Cache variable with type UNINITIALIZED removed by cmake-gui

I had a variable entered in the cache from the command line, without giving it a type. And the variable was not declared as cache variable in my CMakeLists.txt. In the CMakeCache.txt it looked like:

FOO_UNTYPED:UNINITIALIZED=999

I have noticed that this entry in the cache:

  • it remains if I run cmake build_dir, or cmake -DNEW_VARIABLE=123 build_dir
  • it remains if I run ccmake build_dir add press Configure + Generate
  • it disappears if I run cmake-gui build_dir and press Configure + Generate

I’m aware that I can avoid this problem by either:

  • set the variable as a cache variable with a type in CMakeLists.txt
  • supply a type on the command line in the -D option

But I was surprised by the way cmake-gui differed from the other situations. Is this intentional?

Johan, I was also able to confirm this with CMake 4.4.4. Definitely seems like oddly divergent behavior to me.

Looks like this has been reported already in an issue here: https://gitlab.kitware.com/cmake/cmake/-/work_items/23721