MACRO (FINDHUGE_VALF)
  GET_PROPERTY(source_dir_set GLOBAL PROPERTY MYPACKAGE_SOURCE_DIR SET)
  IF (NOT ${source_dir_set})
    MESSAGE (WARNING "Cannot check HUGE_VALF, property MYPACKAGE_SOURCE_DIR is not set")
  ELSE ()
    IF (NOT C_HUGE_VALF_SINGLETON)
      GET_PROPERTY(source_dir GLOBAL PROPERTY MYPACKAGE_SOURCE_DIR)
      SET (_C_HUGE_VALF_FOUND FALSE)
      #
      # We depend on math.h
      #
      INCLUDE (CheckIncludeFile)
      CHECK_INCLUDE_FILE ("math.h" HAVE_MATH_H)
      IF (HAVE_MATH_H)
        SET (_HAVE_MATH_H 1)
      ELSE ()
        SET (_HAVE_MATH_H 0)
      ENDIF ()
      #
      # Test
      #
      MESSAGE(STATUS "Looking for working HUGE_VALF")
      TRY_COMPILE (C_HAS_HUGE_VALF ${CMAKE_CURRENT_BINARY_DIR}
        ${source_dir}/HUGE_VALF.c
        COMPILE_DEFINITIONS -DC_HUGE_VALF=HUGE_VALF -DHAVE_MATH_H=${_HAVE_MATH_H})
      IF (C_HAS_HUGE_VALF)
        MESSAGE(STATUS "Looking for working HUGE_VALF - found")
        SET (_C_HUGE_VALF HUGE_VALF)
        SET (_C_HUGE_VALF_FOUND TRUE)
      ELSE ()
        MESSAGE(STATUS "Looking for HUGE_VALF replacement")
        TRY_COMPILE (C_HAS_HUGE_VALF_REPLACEMENT ${CMAKE_CURRENT_BINARY_DIR}
          ${source_dir}/HUGE_VALF.c
          COMPILE_DEFINITIONS -DC_HUGE_VALF=HUGE_VALF -DHAVE_HUGE_VALF_REPLACEMENT=1 -DHAVE_MATH_H=${_HAVE_MATH_H})
        IF (C_HAS_HUGE_VALF_REPLACEMENT)
          MESSAGE(STATUS "Looking for HUGE_VALF replacement - found")
          SET (_C_HUGE_VALF_REPLACEMENT TRUE)
      ELSE ()
      ENDIF ()
      ENDIF ()
    ENDIF ()
    IF (_C_HUGE_VALF_FOUND)
      SET (C_HUGE_VALF "${_C_HUGE_VALF}" CACHE STRING "C HUGE_VALF implementation")
      MARK_AS_ADVANCED (C_HUGE_VALF)
    ENDIF ()
    IF (_C_HUGE_VALF_REPLACEMENT)
      SET (C_HUGE_VALF_REPLACEMENT "(__builtin_huge_valf())" CACHE STRING "C HUGE_VALF_REPLACEMENT implementation")
      MARK_AS_ADVANCED (C_HUGE_VALF_REPLACEMENT)
    ENDIF ()
    SET (C_HUGE_VALF_SINGLETON TRUE CACHE BOOL "C HUGE_VALF check singleton")
    MARK_AS_ADVANCED (C_HUGE_VALF_SINGLETON)
  ENDIF ()
ENDMACRO()
