CheckVariableExists.cmake 921 B

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