You can simply write (i.e. do not expand the variable):
if (MY_VAR STREQUAL "true")
In this case, a non-existing variable will evaluate to FALSE
(boolean value as defined by CMake
).
And, in the case of expected value is a true
value as defined by CMake
:
if (MY_VAR)