include(ExternalProject)

# Tag: 2020/06/07
set(RtAudio_GIT_TAG d7f12763c55795ef8a71a9b589b39e7be01db7b2)

set(RtAudio_ARGS
    -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
    -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
    -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
    -DCMAKE_INSTALL_LIBDIR=lib
    -DCMAKE_DEBUG_POSTFIX=
    -DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW
    -DCMAKE_FIND_FRAMEWORK=${CMAKE_FIND_FRAMEWORK}
    -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
    -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
    -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
    -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
    -DRTAUDIO_BUILD_TESTING=FALSE
    -DRTAUDIO_STATIC_MSVCRT=FALSE)
if(BUILD_SHARED_LIBS)
    set(RtAudio_ARGS ${RtAudio_ARGS} -DRTAUDIO_BUILD_SHARED_LIBS=TRUE)
else()
    set(RtAudio_ARGS ${RtAudio_ARGS} -DRTAUDIO_BUILD_STATIC_LIBS=TRUE)
endif()
if(CMAKE_CXX_STANDARD)
    set(RtAudio_ARGS ${RtAudio_ARGS} -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD})
endif()

ExternalProject_Add(
    RtAudio
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/RtAudio
    GIT_REPOSITORY https://github.com/thestk/rtaudio.git
    GIT_TAG ${RtAudio_GIT_TAG}
    CMAKE_ARGS ${RtAudio_ARGS})
