CMP0126: Overwriting a cache variable also removes normal variable
The second case is wrong:
The OLD behavior removes any normal variable of the same name from the current scope in the following situations:
No cache variable of that name existed previously.
A cache variable of that name existed previously, but it had no type. This can occur when the variable was set on the command line using a form like cmake -DMYVAR=blah instead of cmake -DMYVAR:STRING=blah.
When I overwrite a typed variable, it also removed the normal variable:
Reproduction (code : CMakeLists.txt):
$ rm CMakeCache.txt && cmake . -DCMP0126_ENABLE=OLD
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- CMP0126_ENABLE = OLD
-- 1 VAR =
-- 1 CACHE VAR =
-- 2 VAR = NORMAL
-- 2 CACHE VAR =
-- 3 VAR = CACHE
-- 3 CACHE VAR = CACHE
-- 4 VAR = NORMAL
-- 4 CACHE VAR = CACHE
-- 5 VAR = CACHE
-- 5 CACHE VAR = CACHE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/tmp/cmake_test
$ rm CMakeCache.txt && cmake . -DCMP0126_ENABLE=NEW
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- CMP0126_ENABLE = NEW
-- 1 VAR =
-- 1 CACHE VAR =
-- 2 VAR = NORMAL
-- 2 CACHE VAR =
-- 3 VAR = NORMAL
-- 3 CACHE VAR = CACHE
-- 4 VAR = NORMAL
-- 4 CACHE VAR = CACHE
-- 5 VAR = NORMAL
-- 5 CACHE VAR = CACHE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/tmp/cmake_test
See difference in 5 VAR =
Edited by KUGA2