CMake if environment/cache variable conditions

CMake normal variables can be used without ${} evaluation in several contexts including if() statements. Cache and Environment variables do need ${} enclosure even in if() statements to be evaluated.

Example: environment variable “CI” to detect if CMake is running on a CI or not.

# ENV{...} is always false.
# $ENV{...} is correct syntax

if($ENV{CI})
  message(STATUS "CI value: $ENV{CI}")
endif()

When using if() to check for variable existence, then ${} is not used.

if(DEFINED ENV{CI})
  message(STATUS "CI value: $ENV{CI}")
endif()