add_library(RtAudio STATIC EXCLUDE_FROM_ALL "thirdparty/rtaudio/RtAudio.cpp")
target_include_directories(RtAudio PUBLIC "thirdparty/rtaudio")
target_include_directories(RtAudio PRIVATE "thirdparty/rtaudio/include")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  target_compile_definitions(RtAudio PUBLIC "__LINUX_ALSA__")
  target_link_libraries(RtAudio PUBLIC "asound")
  if(PULSEAUDIO_FOUND)
    target_compile_definitions(RtAudio PUBLIC "__LINUX_PULSE__")
    target_include_directories(RtAudio PUBLIC ${PULSEAUDIO_INCLUDE_DIRS})
    link_directories(${PULSEAUDIO_LIBRARY_DIRS})
    target_link_libraries(RtAudio PUBLIC ${PULSEAUDIO_LIBRARIES})
  endif()
  # target_compile_definitions(RtAudio PUBLIC "__LINUX_OSS__")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  target_compile_definitions(RtAudio PUBLIC "__WINDOWS_DS__")
  target_link_libraries(RtAudio PUBLIC "dsound")
  target_compile_definitions(RtAudio PUBLIC "__WINDOWS_WASAPI__")
  target_link_libraries(RtAudio PUBLIC "ksguid")
  target_compile_definitions(RtAudio PUBLIC "__WINDOWS_ASIO__")
  target_sources(RtAudio PRIVATE
    "thirdparty/rtaudio/include/asio.cpp"
    "thirdparty/rtaudio/include/asiodrivers.cpp"
    "thirdparty/rtaudio/include/asiolist.cpp"
    "thirdparty/rtaudio/include/iasiothiscallresolver.cpp")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  target_compile_definitions(RtAudio PUBLIC "__MACOSX_CORE__")
  find_library(COREAUDIO_LIBRARY "CoreAudio")
  find_library(FOUNDATION_LIBRARY "Foundation")
  target_link_libraries(RtAudio PUBLIC "${COREAUDIO_LIBRARY}" "${FOUNDATION_LIBRARY}")
endif()
if(JACK_FOUND)
  target_compile_definitions(RtAudio PUBLIC "__UNIX_JACK__")
  target_include_directories(RtAudio PUBLIC ${JACK_INCLUDE_DIRS})
  link_directories(${JACK_LIBRARY_DIRS})
  target_link_libraries(RtAudio PUBLIC ${JACK_LIBRARIES})
endif()
