cmake_minimum_required(VERSION 3.22.1)
project(lck_streaming)

find_library(log-lib log)
find_library(android-lib android)
find_library(mediandk-lib mediandk)
find_library(egl-lib EGL)
find_library(glesv3-lib GLESv3)
find_library(nativewindow-lib nativewindow)

add_library(lck_streaming SHARED
    jni_bridge.cpp
    rtmp_client.cpp
    rtmp_sink.cpp
    egl_context.cpp
    composition_pipeline.cpp
    streaming_engine.cpp
    clip_recorder.cpp
    cortex_recorder.cpp
    faststart.cpp
)

target_include_directories(lck_streaming PRIVATE
    ${CMAKE_SOURCE_DIR}/third_party/librtmp/include
)

# Import pre-built librtmp from jniLibs
# IMPORTED_NO_SONAME prevents CMake from embedding the absolute build path
# as DT_NEEDED — the Android linker will find the .so by name in the APK.
add_library(rtmp SHARED IMPORTED)
set_target_properties(rtmp PROPERTIES
    IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/arm64-v8a/librtmp.so
    IMPORTED_NO_SONAME TRUE
)

add_library(ssl SHARED IMPORTED)
set_target_properties(ssl PROPERTIES
    IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/arm64-v8a/libssl.so
    IMPORTED_NO_SONAME TRUE
)

add_library(crypto SHARED IMPORTED)
set_target_properties(crypto PROPERTIES
    IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/arm64-v8a/libcrypto.so
    IMPORTED_NO_SONAME TRUE
)

target_link_libraries(lck_streaming
    ${log-lib}
    ${android-lib}
    ${mediandk-lib}
    ${egl-lib}
    ${glesv3-lib}
    ${nativewindow-lib}
    rtmp
    ssl
    crypto
)
