include(CheckSymbolExists)
include(CheckIncludeFile)

macro(die_unless_include_found)
    set(FILE ${ARGV0})
    string(MAKE_C_IDENTIFIER "${ARGV0}_FOUND" DEFINITION)
    string(TOUPPER "${DEFINITION}" DEFINITION)
    check_include_file("${FILE}" "${DEFINITION}")
    if (NOT "${${DEFINITION}}")
        message(FATAL_ERROR "Header ${ARGV0} not found!")
    endif()
    unset(DEFINITION)
endmacro()

macro(die_unless_symbol_found)
    set(SYMBOL "${ARGV0}")
    string(MAKE_C_IDENTIFIER "${ARGV0}_FOUND" DEFINITION)
    string(TOUPPER "${DEFINITION}" DEFINITION)
    check_symbol_exists("${ARGV0}" "${ARGV1}" "${DEFINITION}")
    if (NOT "${${DEFINITION}}")
        message(FATAL_ERROR "Symbol ${ARGV0} not found in header(s) ${ARGV1}!")
    endif()
    unset(DEFINITION)
endmacro()

macro(define_if_type_exist)
    set(TYPE "${ARGV0}")
    set(VAR "HAVE_${TYPE}")
    check_type_size("${TYPE}" "${VAR}")
    if ("${${VAR}}")
        add_definitions(-D${VAR})
    endif ()
endmacro()
