# Locate async I/O libraries on a host OS.

IF (UNIX)
    FIND_PATH(ASYNC_IO_INCLUDE_DIR libaio.h
              PATH_SUFFIXES include
              PATHS
                  ~/Library/Frameworks
                  /Library/Frameworks
                  /usr/local
                  /opt/local
                  /opt/csw
                  /opt)

    FIND_LIBRARY(ASYNC_IO_LIBRARIES
                 NAMES aio
                 PATHS
                     ~/Library/Frameworks
                     /Library/Frameworks
                     /usr/local
                     /opt/local
                     /opt/csw
                     /opt)
ELSEIF (WIN32)
ENDIF()

IF (ASYNC_IO_LIBRARIES)
    MESSAGE(STATUS "Found async I/O libraries in ${ASYNC_IO_INCLUDE_DIR} :
            ${ASYNC_IO_LIBRARIES}")
    ADD_DEFINITIONS(-D_ASYNC_IO=1)
    set(ASYNC_IO_LIB ${ASYNC_IO_LIBRARIES})
    include_directories(AFTER ${ASYNC_IO_INCLUDE_DIR})
    MARK_AS_ADVANCED(ASYNC_IO_INCLUDE_DIR ASYNC_IO_LIBRARIES)
ELSE (ASYNC_IO_LIBRARIES)
    MESSAGE(STATUS "Can't find async I/O libraries")
ENDIF (ASYNC_IO_LIBRARIES)

# Locate async I/O libraries on a host OS.

IF (UNIX)
    FIND_PATH(ASYNC_IO_INCLUDE_DIR libaio.h
              PATH_SUFFIXES include
              PATHS
                  ~/Library/Frameworks
                  /Library/Frameworks
                  /usr/local
                  /opt/local
                  /opt/csw
                  /opt)

    FIND_LIBRARY(ASYNC_IO_LIBRARIES
                 NAMES aio
                 PATHS
                     ~/Library/Frameworks
                     /Library/Frameworks
                     /usr/local
                     /opt/local
                     /opt/csw
                     /opt)
ELSEIF (WIN32)
ENDIF()

IF (ASYNC_IO_LIBRARIES AND ASYNC_IO_INCLUDE_DIR)
    MESSAGE(STATUS "Found async I/O libraries in ${ASYNC_IO_INCLUDE_DIR} :
            ${ASYNC_IO_LIBRARIES}")
    ADD_DEFINITIONS(-D_ASYNC_IO=1)
    set(ASYNC_IO_LIB ${ASYNC_IO_LIBRARIES})
    include_directories(AFTER ${ASYNC_IO_INCLUDE_DIR})
    MARK_AS_ADVANCED(ASYNC_IO_INCLUDE_DIR ASYNC_IO_LIBRARIES)
ELSE (ASYNC_IO_LIBRARIES AND ASYNC_IO_INCLUDE_DIR)
    MESSAGE(STATUS "Can't find async I/O libraries")
ENDIF (ASYNC_IO_LIBRARIES AND ASYNC_IO_INCLUDE_DIR)

Fix build failures on platforms with a lib named aio
Fix build failures on platforms with a lib named aio

Solaris have a library named libaio.so, which historically
provided the asynchronous IO functions aiocancel/read etc,
but all of this is now part of libc (and the library exists
for backwards compatibility). We need to check that we've
got the header and the library before using the macro,
otherwise we'll get errors due to using a cmake variable
that isn't set

Change-Id: Ie87790fc527c7877d01cd8aef7bd7c8a17f5a117
