# Native build: the shared C++ engine (../../../../core, the same code the iOS app
# runs), its JNI glue (jni_engine.cpp) and the Oboe (AAudio) low-latency output.
cmake_minimum_required(VERSION 3.22.1)
project(sizzle_native)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Oboe ships as a prefab package inside the com.google.oboe:oboe AAR; AGP exposes
# it here when `buildFeatures { prefab = true }` is set in build.gradle.kts.
find_package(oboe REQUIRED CONFIG)

# The engine as an object library, not a static one: the devices are found through
# weak placeholder makers (core/src/fx/Registry.cpp), so every object must be linked
# in or the placeholders would win. Optimised even in debug builds (the DSP must
# keep up in real time).
set(CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../core)
file(GLOB CORE_SRC CONFIGURE_DEPENDS ${CORE_DIR}/src/*.cpp ${CORE_DIR}/src/*/*.cpp)
add_library(sizzle_core OBJECT ${CORE_SRC})
target_include_directories(sizzle_core PUBLIC ${CORE_DIR}/include ${CORE_DIR}/src ${CORE_DIR}/src/fx)
target_compile_options(sizzle_core PRIVATE -O2 -Wno-unused-parameter)

add_library(sizzle_native SHARED native_audio.cpp jni_engine.cpp $<TARGET_OBJECTS:sizzle_core>)
target_include_directories(sizzle_native PRIVATE ${CORE_DIR}/include ${CORE_DIR}/src ${CORE_DIR}/src/fx)
target_compile_options(sizzle_native PRIVATE -O2)

target_link_libraries(sizzle_native
    oboe::oboe
    z
    log)

# Align ELF load segments to 16 KB so the library works on Android 15+ devices
# using 16 KB memory pages (and passes Google Play's requirement). NDK r27+ does
# this by default; on r26 we set it explicitly. -Bsymbolic is unrelated; the key
# flag is max-page-size.
target_link_options(sizzle_native PRIVATE
    "-Wl,-z,max-page-size=16384")
