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?