2 # Check if the variable exists.
3 # # CHECK_VARIABLE_EXISTS - macro which checks if the variable exists
4 # VAR - the name of the variable
5 # VARIABLE - variable to store the result
8 MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE)
9 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
10 SET(MACRO_CHECK_VARIABLE_DEFINITIONS
11 "-DCHECK_VARIABLE_EXISTS=${VAR} ${CMAKE_REQUIRED_FLAGS}")
12 MESSAGE(STATUS "Looking for ${VAR}")
13 IF(CMAKE_REQUIRED_LIBRARIES)
14 SET(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES
15 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
16 ENDIF(CMAKE_REQUIRED_LIBRARIES)
17 TRY_COMPILE(${VARIABLE}
19 ${CMAKE_ROOT}/Modules/CheckVariableExists.c
20 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS}
21 "${CHECK_VARIABLE_EXISTS_ADD_LIBRARIES}"
22 OUTPUT_VARIABLE OUTPUT)
24 SET(${VARIABLE} 1 CACHE INTERNAL "Have variable ${VAR}")
25 MESSAGE(STATUS "Looking for ${VAR} - found")
26 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
27 "Determining if the variable ${VAR} exists passed with the following output:\n"
30 SET(${VARIABLE} "" CACHE INTERNAL "Have variable ${VAR}")
31 MESSAGE(STATUS "Looking for ${VAR} - not found")
32 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
33 "Determining if the variable ${VAR} exists failed with the following output:\n"
36 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
37 ENDMACRO(CHECK_VARIABLE_EXISTS)