# build rules for RtMidi

add_library(RtMidi STATIC "${PROJECT_SOURCE_DIR}/thirdparty/rtmidi/RtMidi.cpp")
target_include_directories(RtMidi PUBLIC "${PROJECT_SOURCE_DIR}/thirdparty/rtmidi")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  include(FindPkgConfig)
  pkg_check_modules(ALSA "alsa")
  pkg_check_modules(JACK "jack")
  if(ALSA_FOUND)
    target_compile_definitions(RtMidi PUBLIC "__LINUX_ALSA__")
    target_include_directories(RtMidi PUBLIC ${ALSA_INCLUDE_DIRS})
    target_link_libraries(RtMidi PUBLIC ${ALSA_LIBRARIES})
  endif()
  if(JACK_FOUND)
    target_compile_definitions(RtMidi PUBLIC "__UNIX_JACK__")
    target_include_directories(RtMidi PUBLIC ${JACK_INCLUDE_DIRS})
    target_link_libraries(RtMidi PUBLIC ${JACK_LIBRARIES})
  endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  target_compile_definitions(RtMidi PUBLIC "__WINDOWS_MM__")
  target_link_libraries(RtMidi PUBLIC "winmm")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  target_compile_definitions(RtMidi PUBLIC "__MACOSX_CORE__")
  find_library(COREMIDI_LIBRARY "CoreMIDI")
  target_link_libraries(RtMidi PUBLIC "${COREMIDI_LIBRARY}")
  find_library(COREAUDIO_LIBRARY "CoreAudio")
  target_link_libraries(RtMidi PUBLIC "${COREAUDIO_LIBRARY}")
endif()
