cmake_minimum_required(VERSION 3.16)
project(rnoh_ffmpeg_kit LANGUAGES CXX)

execute_process(
  COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/build-native.sh" "${CMAKE_SYSROOT}" "${OHOS_ARCH}"
  OUTPUT_VARIABLE FFMPEG_BUILD
  OUTPUT_STRIP_TRAILING_WHITESPACE
  RESULT_VARIABLE FFMPEG_BUILD_RESULT
)
if(NOT FFMPEG_BUILD_RESULT EQUAL 0)
  message(FATAL_ERROR "Building the Harmony FFmpegKit libraries failed")
endif()

add_library(rnoh_ffmpeg_kit SHARED
  RNFFmpegKitModule.cpp
  RnohReactNativeHarmonyFFmpegKitPackage.cpp
)
target_compile_features(rnoh_ffmpeg_kit PRIVATE cxx_std_17)
target_compile_options(rnoh_ffmpeg_kit PRIVATE "-iquote${FFMPEG_BUILD}/include/ffmpegkit")
target_include_directories(rnoh_ffmpeg_kit
  PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}"
  PRIVATE "${FFMPEG_BUILD}/include" "${FFMPEG_BUILD}/prefix/include"
)
target_link_options(rnoh_ffmpeg_kit PRIVATE "-Wl,--exclude-libs,ALL")
target_link_libraries(rnoh_ffmpeg_kit PRIVATE
  -Wl,--start-group
  "${FFMPEG_BUILD}/prefix/lib/libffmpegkit.a"
  "${FFMPEG_BUILD}/prefix/lib/libavdevice.a"
  "${FFMPEG_BUILD}/prefix/lib/libavformat.a"
  "${FFMPEG_BUILD}/prefix/lib/libavfilter.a"
  "${FFMPEG_BUILD}/prefix/lib/libavcodec.a"
  "${FFMPEG_BUILD}/prefix/lib/libavutil.a"
  "${FFMPEG_BUILD}/prefix/lib/libswscale.a"
  "${FFMPEG_BUILD}/prefix/lib/libswresample.a"
  "${FFMPEG_BUILD}/prefix/lib/libpostproc.a"
  "${FFMPEG_BUILD}/prefix/lib/libx264.a"
  -Wl,--end-group
  rnoh
)
