
SET(SOUNDOUTPUT_TYPES ALSA AO)
# SOUNDOUTPUT_TYPES_AVAILABLE "declare" the variable :)
SET(SOUNDOUTPUT_TYPES_FOUND FALSE)
SET(SOUNDOUTPUT_TYPES_ENABLED FALSE)

FOREACH(TYPE ${SOUNDOUTPUT_TYPES})
  # Check for sound output libraries, not fatal
  FIND_PACKAGE(${TYPE})
  
  IF(${TYPE}_FOUND)
    SET(SOUNDOUTPUT_TYPES_FOUND TRUE)
    SET(SOUNDOUTPUT_TYPES_AVAILABLE ${SOUNDOUTPUT_TYPES_AVAILABLE} ${TYPE})
  ENDIF(${TYPE}_FOUND)

  OPTION(${TYPE}_ENABLED "Compile with ${TYPE} sound output support enabled." ON)
ENDFOREACH(TYPE)

#
# ALSA
#
IF(ALSA_ENABLED AND ALSA_FOUND)
  SET(SOUNDOUTPUT_TYPES_ENABLED TRUE)
  SET(ANNOYME_SRC_SOUNDOUTPUT ${ANNOYME_SRC_SOUNDOUTPUT} AlsaOutput.cpp)
  SET(ANNOYME_LIBS_SOUNDOUTPUT ${ANNOYME_LIBS_SOUNDOUTPUT} ${ALSA_LIBRARIES})
  INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
  SET(WITH_ALSA TRUE)
ENDIF(ALSA_ENABLED AND ALSA_FOUND)

#
# AO
#
IF(AO_ENABLED AND AO_FOUND)
  SET(SOUNDOUTPUT_TYPES_ENABLED TRUE)
  SET(ANNOYME_SRC_SOUNDOUTPUT ${ANNOYME_SRC_SOUNDOUTPUT} AOutput.cpp)
  SET(ANNOYME_LIBS_SOUNDOUTPUT ${ANNOYME_LIBS_SOUNDOUTPUT} ${AO_LIBRARIES})
  INCLUDE_DIRECTORIES(${AO_INCLUDE_DIRS})
  SET(WITH_AO TRUE)
ENDIF(AO_ENABLED AND AO_FOUND)

# There must be some of the above sound output libs available
IF(NOT SOUNDOUTPUT_TYPES_FOUND)
  MESSAGE(FATAL_ERROR "No suitable \(supported\) sound output found.")
ENDIF(NOT SOUNDOUTPUT_TYPES_FOUND)

# There must be some of the above sound output libs be enabled
IF(NOT SOUNDOUTPUT_TYPES_ENABLED)
  MESSAGE(FATAL_ERROR "No sound output type selected. Available are: ${SOUNDOUTPUT_TYPES_AVAILABLE}")
ENDIF(NOT SOUNDOUTPUT_TYPES_ENABLED)

