# Audio / MIDI driver support
set(FLUIDSYNTH_SUPPORT_ALSA @ALSA_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_COREAUDIO @COREAUDIO_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_COREMIDI @COREMIDI_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_DART @DART_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_DSOUND @DSOUND_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_JACK @JACK_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_MIDISHARE @MIDISHARE_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_OBOE @OBOE_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_OPENSLES @OPENSLES_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_OSS @OSS_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_PIPEWIRE @PIPEWIRE_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_PORTAUDIO @PORTAUDIO_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_PULSE @PULSE_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_SDL2 @SDL2_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_WASAPI @WASAPI_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_WAVEOUT @WAVEOUT_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_WINMIDI @WINMIDI_SUPPORT@)

# Files support
set(FLUIDSYNTH_SUPPORT_DLS @LIBINSTPATCH_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_LIBINSTPATCH @LIBINSTPATCH_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_LIBSNDFILE @LIBSNDFILE_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_SF3 @LIBSNDFILE_HASVORBIS@)

# Miscrellaneous support
set(FLUIDSYNTH_SUPPORT_DBUS @DBUS_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_GETOPT @HAVE_GETOPT_H@)
set(FLUIDSYNTH_SUPPORT_IPV6 @IPV6_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_LADSPA @LADSPA_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_LASH @LASH_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_NETWORK @NETWORK_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_READLINE @READLINE_SUPPORT@)
set(FLUIDSYNTH_SUPPORT_SYSTEMD @SYSTEMD_SUPPORT@)

# Extra info
set(FLUIDSYNTH_IS_SHARED @BUILD_SHARED_LIBS@)
set(FLUIDSYNTH_SUPPORT_COVERAGE @ENABLE_COVERAGE@)
set(FLUIDSYNTH_SUPPORT_FLOAT @WITH_FLOAT@)
set(FLUIDSYNTH_SUPPORT_FPECHECK @ENABLE_FPECHECK@)
set(FLUIDSYNTH_SUPPORT_FPETRAP @ENABLE_TRAPONFPE@)
set(FLUIDSYNTH_SUPPORT_OPENMP @HAVE_OPENMP@)
set(FLUIDSYNTH_SUPPORT_PROFILING @WITH_PROFILING@)
set(FLUIDSYNTH_SUPPORT_THREADS @ENABLE_MIXER_THREADS@)
set(FLUIDSYNTH_SUPPORT_UBSAN @ENABLE_UBSAN@)

# Only load dependencies on static builds
if(NOT FLUIDSYNTH_IS_SHARED)
  # Allows CMake to use the additional modules
  list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

  # Make searching for packages easier on VCPKG
  if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15 AND VCPKG_TOOLCHAIN)
    set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
  endif()

  # Load the pkg-config helpers
  include(PkgConfigHelpers)

  # Check the system has a separated math library
  find_library(HAS_LIBM NAMES "m" NO_CACHE)
  if(HAS_LIBM)
    set(MATH_LIBRARY "m")
  endif(HAS_LIBM)

  # Load find_dependency macro
  include(CMakeFindDependencyMacro)

  # Mandatory dependencies
  if(NOT TARGET Threads::Threads)
    find_dependency(Threads)
  endif()

  if(NOT TARGET GLib2::glib-2 OR NOT TARGET GLib2::gthread-2)
    find_dependency(GLib2 @GLIB2_MINUMUM_VERSION@)
  endif()

  # Optional dependencies
  if(FLUIDSYNTH_SUPPORT_ALSA AND NOT TARGET ALSA::ALSA)
    find_dependency(ALSA @ALSA_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_DBUS AND NOT TARGET dbus-1)
    find_dependency(DBus1 @DBUS_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_JACK AND NOT TARGET Jack::Jack)
    find_dependency(Jack)
  endif()

  if(FLUIDSYNTH_SUPPORT_LADSPA AND NOT TARGET GLib2::gmodule-2)
    message(WARN "LADSPA support was built in but gmodule could not be found.")
  endif()

  if(FLUIDSYNTH_SUPPORT_LASH AND NOT TARGET LASH::LASH)
    find_dependency(LASH @LASH_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_LIBINSTPATCH AND NOT TARGET InstPatch::libinstpatch)
    find_dependency(InstPatch @LIBINSTPATCH_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_LIBSNDFILE AND NOT TARGET SndFile::sndfile)
    find_dependency(SndFile @LIBSNDFILE_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_MIDISHARE AND NOT TARGET MidiShare::MidiShare)
    find_dependency(MidiShare)
  endif()

  if(FLUIDSYNTH_SUPPORT_OBOE AND NOT TARGET oboe::oboe)
    find_dependency(oboe)
  endif()

  if(FLUIDSYNTH_SUPPORT_OPENMP AND NOT TARGET OpenMP::OpenMP_C)
    find_dependency(OpenMP COMPONENTS C)
  endif()

  if(FLUIDSYNTH_SUPPORT_OPENSLES AND NOT TARGET OpenSLES::OpenSLES)
    find_dependency(OpenSLES)
  endif()

  if(FLUIDSYNTH_SUPPORT_PIPEWIRE AND NOT TARGET PipeWire::PipeWire)
    find_dependency(PipeWire @PIPEWIRE_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_PORTAUDIO AND NOT TARGET PortAudio::PortAudio)
    find_dependency(PortAudio @PORTAUDIO_MINIMUM_VERSION@)
  endif()

  if(FLUIDSYNTH_SUPPORT_READLINE AND NOT TARGET Readline::Readline)
    find_dependency(Readline)
  endif()

  if(FLUIDSYNTH_SUPPORT_SDL2 AND NOT TARGET SDL2::SDL2)
    find_dependency(SDL2)
  endif()

  if(FLUIDSYNTH_SUPPORT_SYSTEMD AND NOT Systemd::libsystemd)
    find_dependency(Systemd)
  endif()

  # Restore the module path
  list(REMOVE_ITEM CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
endif()

# finally, include the targets file
include("${CMAKE_CURRENT_LIST_DIR}/FluidSynthTargets.cmake")
