cmake_minimum_required(VERSION 3.22.1)
project("elnative")

#
# CMakeLists.txt for native-hello-android
#
# Sources:
#   el_android.c        — Android JNI widget bridge
#   el_seed.c           — OS-boundary __-prefixed primitives
#   el_runtime.c        — High-level el builtins (str_len, json_*, etc.)
#   el_native_vessel.c  — el-native vessel (compiled from vessels/el-native/src/main.el)
#   native_hello.c      — App entry point (compiled from examples/native-hello/src/main.el)
#
# el_runtime.c and el_seed.c both define __-prefixed symbols. On Android the
# linker accepts duplicate weak symbols; the shared library loads one copy.
# The EL_TARGET_ANDROID guard in el_android.c ensures only the Android widget
# backend is compiled in.
#

add_library(
    elnative
    SHARED

    # native_hello.c listed first so its main() takes precedence over the
    # vessel's main() when --allow-multiple-definition is in effect.
    native_hello.c
    el_native_vessel.c
    el_android.c
    el_seed.c
    el_runtime.c
)

# EL_TARGET_ANDROID activates the Android JNI widget backend in el_android.c
# and the corresponding guards in el_seed.c / el_native_target.h.
target_compile_definitions(elnative PRIVATE
    EL_TARGET_ANDROID
)

target_include_directories(elnative PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
)

# el_runtime.c and el_seed.c both define __-prefixed OS-boundary symbols.
# el_runtime.c's copies are weaker definitions; allow-multiple-definition lets
# the linker pick one copy silently (el_seed.c listed later = its copy wins
# in the Android linker's right-to-left resolution order).
target_link_options(elnative PRIVATE
    "-Wl,--allow-multiple-definition"
)

find_library(log-lib log)
find_library(android-lib android)

target_link_libraries(elnative
    ${log-lib}
    ${android-lib}
)
