set(
  sources
  ffmpeg.cpp
  filter_graph.cpp
  hw_context.cpp
  stream_reader/buffer/chunked_buffer.cpp
  stream_reader/buffer/unchunked_buffer.cpp
  stream_reader/conversion.cpp
  stream_reader/packet_buffer.cpp
  stream_reader/post_process.cpp
  stream_reader/stream_processor.cpp
  stream_reader/stream_reader.cpp
  stream_writer/encode_process.cpp
  stream_writer/encoder.cpp
  stream_writer/packet_writer.cpp
  stream_writer/stream_writer.cpp
  stream_writer/tensor_converter.cpp
  compat.cpp
  )

set(
  ext_sources
  pybind/pybind.cpp
  )

if (USE_CUDA)
  set(
    additional_lib
    cuda_deps)
endif()

if (TARGET ffmpeg)
  torchaudio_library(
    libtorchaudio_ffmpeg
    "${sources}"
    ""
    "torch;ffmpeg;${additional_lib}"
    ""
    )
  if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
    torchaudio_extension(
      _torchaudio_ffmpeg
      "${ext_sources}"
      ""
      "libtorchaudio_ffmpeg"
      "TORCHAUDIO_FFMPEG_EXT_NAME=_torchaudio_ffmpeg"
      )
  endif()
else()
  torchaudio_library(
    libtorchaudio_ffmpeg4
    "${sources}"
    ""
    "torch;ffmpeg4;${additional_lib}"
    ""
    )
  torchaudio_library(
    libtorchaudio_ffmpeg5
    "${sources}"
    ""
    "torch;ffmpeg5;${additional_lib}"
    ""
    )
  torchaudio_library(
    libtorchaudio_ffmpeg6
    "${sources}"
    ""
    "torch;ffmpeg6;${additional_lib}"
    ""
    )
  if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
    torchaudio_extension(
      _torchaudio_ffmpeg4
      "${ext_sources}"
      ""
      "libtorchaudio_ffmpeg4"
      "TORCHAUDIO_FFMPEG_EXT_NAME=_torchaudio_ffmpeg4"
      )
    torchaudio_extension(
      _torchaudio_ffmpeg5
      "${ext_sources}"
      ""
      "libtorchaudio_ffmpeg5"
      "TORCHAUDIO_FFMPEG_EXT_NAME=_torchaudio_ffmpeg5"
      )
    torchaudio_extension(
      _torchaudio_ffmpeg6
      "${ext_sources}"
      ""
      "libtorchaudio_ffmpeg6"
      "TORCHAUDIO_FFMPEG_EXT_NAME=_torchaudio_ffmpeg6"
      )
  endif ()
endif()
