Incorrect `NOT` behaviour with empty string in variable
CMake version 3.10, Ubuntu 18, but I think it is version independent.
if we set a variable TEMP_VAR
to empty string ("") both conditions (${TEMP_VAR})
and (NOT ${TEMP_VAR})
are False.
Simple case for test:
message("**** Test empty string ****")
if("")
message("[Empty string] is TRUE")
else()
message("[Empty string] is FALSE")
endif()
if(NOT "")
message("[NOT Empty string] is TRUE")
else()
message("[NOT Empty string] is FALSE")
endif()
set(TEMP_VAR "")
message("**** Test empty string as variable ****")
if(TEMP_VAR)
message("[Empty string] is TRUE")
else()
message("[Empty string] is FALSE")
endif()
if(NOT TEMP_VAR)
message("[NOT Empty string] is TRUE")
else()
message("[NOT Empty string] is FALSE")
endif()
message("**** Test empty string as dereferenced variable ****")
if(${TEMP_VAR})
message("[Empty string] is TRUE")
else()
message("[Empty string] is FALSE")
endif()
if(NOT ${TEMP_VAR})
message("[NOT Empty string] is TRUE")
else()
message("[NOT Empty string] is FALSE")
endif()
My output is:
**** Test empty string ****
[Empty string] is FALSE
[NOT Empty string] is TRUE
**** Test empty string as variable ****
[Empty string] is FALSE
[NOT Empty string] is TRUE
**** Test empty string as dereferenced variable ****
[Empty string] is FALSE
[NOT Empty string] is FALSE