cmake_minimum_required(VERSION 3.22)
project(engine_native LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 宿主构建（默认）用于 L1/L3 测试与 CI；Android 构建由 build_android.sh 传入 NDK 工具链。
option(ENGINE_HOST_BUILD "Host build (no GPU API)" ON)
option(ENGINE_BUILD_TESTS "Build C++ unit tests" ON)

add_library(engine_native STATIC
    src/renderer/renderer.cpp
    src/renderer/backend_null.cpp
    src/renderer/backend_vulkan.cpp
    src/renderer/backend_gles.cpp
    src/platform/device_probe.cpp
    src/platform/vulkan_loader.cpp
    src/platform/ndk_window.cpp
)

target_include_directories(engine_native PUBLIC include)
target_compile_definitions(engine_native PUBLIC
    $<$<BOOL:${ENGINE_HOST_BUILD}>:ENGINE_HOST_BUILD>
)

if(ENGINE_BUILD_TESTS)
    enable_testing()
    add_executable(engine_native_tests
        tests/test_math.cpp
        tests/test_arena.cpp
        tests/test_shader_cache.cpp
        tests/test_ffi.cpp
    )
    target_link_libraries(engine_native_tests PRIVATE engine_native)
    add_test(NAME engine_native_tests COMMAND engine_native_tests)
endif()
