cmake_minimum_required(VERSION 3.14)

project(ffmpeg_audio LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(ffmpeg_audio SHARED
    ffmpeg_audio.cpp
    ffmpeg_audio.h
    ../ffi_version.h
    ffmpeg_audio_refactored.cpp
)

add_executable(demo_ffmpeg_audio
    demo_ffmpeg_audio.c
)

if(WIN32)
    set(FFMPEG_LIB ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg-win/lib)
    set(FFMPEG_INC ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg-win/include)
    include_directories(${FFMPEG_INC})
    target_link_directories(ffmpeg_audio PRIVATE ${FFMPEG_LIB})
    set(FFMPEG_LIBRARIES avcodec.lib avformat.lib swresample.lib avutil.lib avdevice.lib avfilter.lib swscale.lib)
    target_link_directories(demo_ffmpeg_audio PRIVATE ${FFMPEG_LIB})
elseif(APPLE)
    target_link_directories(ffmpeg_audio PRIVATE /opt/homebrew/opt/ffmpeg-full/lib)
    include_directories(/opt/homebrew/opt/ffmpeg-full/include)
    set(FFMPEG_LIBRARIES avcodec avformat swresample avutil avdevice avfilter swscale)
    target_link_directories(demo_ffmpeg_audio PRIVATE /opt/homebrew/opt/ffmpeg-full/lib)
else()
    set(FFMPEG_LIBRARIES avcodec avformat swresample avutil avdevice avfilter swscale)
endif()

target_link_libraries(ffmpeg_audio PRIVATE ${FFMPEG_LIBRARIES})
target_compile_definitions(ffmpeg_audio PRIVATE LIB_COMPILE)

target_link_Libraries(demo_ffmpeg_audio PRIVATE ffmpeg_audio ${FFMPEG_LIBRARIES})
