# Standalone armeabi-v7a tracing agent for the native ARM32 investigation
# (see ARM64_TRANSLATION_LAYER.md's "Native ARM32 tracing harness" plan).
# Deliberately NOT wired into the main Gradle build (settings.gradle.kts) -
# this is a diagnostic-only artifact built and pushed to the device
# independently via build.sh, never bundled into any APK. Runs exclusively
# on the "native32" flavor's real, unmodified libapp.so on the Galaxy A9.
cmake_minimum_required(VERSION 3.22.1)
project(trace_agent)

add_library(trace_agent SHARED
    libc_gles_trace.cpp
    jni_trace.cpp
)

# Deliberately NOT linking against libGLESv2.so here, even though the GLES
# wrappers exist below - confirmed live on-device that an eager DT_NEEDED
# dependency on it crashes the WHOLE process immediately on launch (exit
# code 1, right after Zygote's early "-Xcheck:jni" specialization, well
# before any Activity/EGL/GL context exists to make libGLESv2.so resolvable
# that early). Each GLES wrapper already resolves its real implementation
# lazily via dlsym(RTLD_NEXT, ...) on first real call - by then the app's
# own GL usage has long since loaded libGLESv2.so itself, so no explicit
# link-time dependency is needed at all. <GLES2/gl2.h> is included only for
# its type definitions (GLenum/GLuint/...), not any function linkage.
find_library(log-lib log)
find_library(dl-lib dl)

target_link_libraries(trace_agent
    ${log-lib}
    ${dl-lib}
)

target_compile_options(trace_agent PRIVATE -Wall -Wno-unused-parameter)

# __dynamic_cast is also defined in libc++abi.a, which the NDK links
# statically into this agent. Interposing it (task #58 - counting the real
# call rate on native hardware) therefore produces a duplicate-symbol link
# error. Our definition comes from this target's own objects, which the
# linker sees before the archive, so it wins; the archive copy is simply
# left unused. Scoped to this target rather than set globally.
target_link_options(trace_agent PRIVATE "-Wl,--allow-multiple-definition")
