cmake
In cmake, environment variables are read and written through the ENV prefix to access environment variables. To
read environment variables, use the format $ENV{JAVA_HOME} to
write environment variables as follows:
set( ENV{
PATH} /home/martink )
The if statement determines whether the environment variable is defined in the following format
if(NOT DEFINED ENV{
JAVA_HOME})
# 没有找到JAVA_HOME环境变量
message(FATAL_ERROR "not defined environment variable:JAVA_HOME")
endif()
#不能用if(ENV{JAVA_HOME})形式来判断是否定义
#但可以用if($ENV{JAVA_HOME})
To sum up, you can see that when reading environment variables, you must add a $
symbol before ENV , and writing and if ,ENV{JAVA_HOME}
refer to the variable name when judging whether it is defined or not, so no $
symbol is added .