`if(${VAR})` and `if("${VAR}")` Show same in --trace output but actually different when CMP0054 being set.

set(DO_NOTHING "-----------Set Policy CMP0054-------------")
if(POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif()
set(MY_VAR "Hello")
set(Hello "Hello")
set(DO_NOTHING "-----------After Policy CMP0054-----------")


if(${MY_VAR})
    message(STATUS "If branch")
else()
    message(STATUS "Else branch") # <--- this
endif()

if("${MY_VAR}")
    message(STATUS "If branch") # <--- this
else()
    message(STATUS "Else branch") 
endif()

However, when examining the --trace output, I couldn’t see any difference between these two conditions. The output looks like this:

/main.cmake(40):  set(DO_NOTHING -----------Set Policy CMP0054------------- )
/main.cmake(41):  if(POLICY CMP0054 )
/main.cmake(42):  cmake_policy(SET CMP0054 NEW )
/main.cmake(45):  set(Hello Hello )
/main.cmake(46):  set(DO_NOTHING -----------After Policy CMP0054----------- )
/main.cmake(49):  if(${MY_VAR} )
/main.cmake(50):  message(STATUS If branch )
-- If branch
/main.cmake(55):  if(${MY_VAR} ) ####### Same as above
/main.cmake(57):  else()
/main.cmake(58):  message(STATUS Else branch )
-- Else branch

It’s work as expect?

--trace only shows what CMake reads. You probably want --trace-expand which shows what the command receives (though predicate commands like if receive quoting information that isn’t shown). Neither behaviors differently for any CMP0054 setting; that is inside of if and friends directly.