CheckVariableExists.cmake 1.0 KB

12345678910111213141516171819202122232425
  1. #
  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
  6. #
  7. MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE)
  8. IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  9. SET(MACRO_CHECK_VARIABLE_DEFINITIONS -DCHECK_VARIABLE_EXISTS=${VAR})
  10. TRY_COMPILE(${VARIABLE}
  11. ${CMAKE_BINARY_DIR}
  12. ${CMAKE_ROOT}/Modules/CheckVariableExists.c
  13. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS}
  14. OUTPUT_VARIABLE OUTPUT)
  15. IF(${VARIABLE})
  16. SET(${VARIABLE} 1 CACHE INTERNAL "Have variable ${VAR}")
  17. ELSE(${VARIABLE})
  18. SET(${VARIABLE} "" CACHE INTERNAL "Have variable ${VAR}")
  19. WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
  20. "Determining if the variable ${VAR} exists failed with the following output:\n"
  21. "${OUTPUT}\n" APPEND)
  22. ENDIF(${VARIABLE})
  23. ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  24. ENDMACRO(CHECK_VARIABLE_EXISTS)