# mtgodot-poc — top level
# Phase 1 (macOS) scaffolding. See docs/GODOT-POC-PLAN.md §M0'.
#
# libgr2 / formats / oracle / tools were vendored in from the retired xrender-poc
# repo (2026-08-29). libgr2 is the shared core (gr2 v6/v7 reader, oracle-verified);
# formats = .msa/.msm parsers (needed M2 T2.2/T2.3); tools = libgr2 validation.
cmake_minimum_required(VERSION 3.20)
project(mtgodot_poc CXX C)

include(CTest)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(MTGODOT_BUILD_EXTENSION "Build the Godot GDExtension (pulls in godot-cpp)" ON)
option(MTGODOT_BUILD_TOOLS     "Build libgr2 validation tools (gr2dump/gr2fuzz/oracle_diff)" OFF)

# --- shared, cross-platform core (no godot-cpp, no third-party) ---
add_subdirectory(libgr2)
add_subdirectory(formats)

if(MTGODOT_BUILD_TOOLS)
    add_subdirectory(tools)
endif()

# --- the Godot extension ---
# Phase 1 was macOS-only; Phase 2 (BACKLOG F1/F2) adds iOS + Android. The three
# native deps are vendored (extension/third_party), so the only gate now is
# "is this a platform we've wired output naming + a toolchain for".
if(MTGODOT_BUILD_EXTENSION)
    set(_mt_plat "${CMAKE_SYSTEM_NAME}")
    if(_mt_plat STREQUAL "Darwin" OR _mt_plat STREQUAL "iOS" OR _mt_plat STREQUAL "Android")
        message(STATUS "mtgodot extension: building for ${_mt_plat}")
    else()
        message(FATAL_ERROR
            "MTGODOT_BUILD_EXTENSION: supported targets are macOS / iOS / Android "
            "(got CMAKE_SYSTEM_NAME='${_mt_plat}'). See docs/PLATFORMS.md. "
            "Use -DMTGODOT_BUILD_EXTENSION=OFF to build just libgr2/formats/tools.")
    endif()
    add_subdirectory(extension)
endif()
