cmake_minimum_required(VERSION 3.22)
project(ts3audio LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)

# Oboe and libopus from source, built static into our one library together with a static
# libc++, so the app ships a single small .so per ABI.
include(FetchContent)
FetchContent_Declare(oboe
        URL https://github.com/google/oboe/archive/refs/tags/1.11.0.tar.gz
        URL_HASH SHA256=0ccf2110640a2b4489f1c93a404f2978656b434d8c5dc9cb6258f9cc95c79b15)
FetchContent_Declare(opus
        URL https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz
        URL_HASH SHA256=65c1d2f78b9f2fb20082c38cbe47c951ad5839345876e46941612ee87f9a7ce1)
set(OPUS_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE)
set(OPUS_BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(OPUS_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE)
set(OPUS_INSTALL_PKG_CONFIG_MODULE OFF CACHE BOOL "" FORCE)
set(OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(oboe opus)

add_library(ts3audio SHARED audio_line.cpp opus_jni.cpp)
target_link_libraries(ts3audio PRIVATE oboe opus log)
target_compile_options(ts3audio PRIVATE -Wall -Wextra)

# Only the JNI entry points are exported; everything else may be dropped.
set_target_properties(ts3audio PROPERTIES CXX_VISIBILITY_PRESET hidden C_VISIBILITY_PRESET hidden)
foreach(lib oboe opus)
    target_compile_options(${lib} PRIVATE -ffunction-sections -fdata-sections)
endforeach()
target_link_options(ts3audio PRIVATE -Wl,--gc-sections -Wl,--exclude-libs,ALL)
