# ============================================================================
#  mlx-magic — root build orchestration ONLY.
# ----------------------------------------------------------------------------
#  This file wires the build's SHAPE, not its contents. Every source directory
#  under src/ owns its own CMakeLists.txt and attaches its own translation units
#  to mlx-magic-lib via mlxm_sources() (filesystem-as-registry: drop a file, the
#  next build compiles it — zero edits here). Reusable logic lives in cmake/*.cmake,
#  one concern per module.
#
#  // NEVER DELETE COMMENTS — explain every non-obvious line.
#  // Update comments with the code; do not strip them.
# ============================================================================
cmake_minimum_required(VERSION 3.24)                 # file(GLOB CONFIGURE_DEPENDS) + cross-dir target_sources
project(mlx-magic VERSION 0.1.0 LANGUAGES CXX OBJCXX)

# Release builds set this to a machine-neutral relative root. Developer builds leave it empty
# and retain source-tree defaults, so tests still discover their fixtures without an install.
set(MLXM_RESOURCE_ROOT "" CACHE STRING "Runtime resource root embedded in the server")

# cmake/ holds the reusable helper modules this file include()s below.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(Toolchain)        # C++26 standard + Apple-Silicon guard
include(Dependencies)     # absl / protobuf (+ PROTO_SRCS) / httplib / mlx / frameworks
include(Sources)          # defines mlxm_sources()      — per-dir source attach
include(ArchPacks)        # defines mlxm_subpacks()     — per-dir CHILD-DIR discovery (drop-in arch packs)
include(Metal)            # defines mlxm_add_metallib()  — .metal -> default.metallib
include(ForceLoad)        # defines mlxm_force_load()    — preserve static registrars
include(AddMlxTest)       # defines add_mlx_test()       — one ctest exe per file

# The shared static library. Born with only the generated protobuf sources; every
# other translation unit is attached by its OWN directory during add_subdirectory(src).
add_library(mlx-magic-lib STATIC ${PROTO_SRCS})

include(LibraryConfig)    # defines mlxm_configure_lib() (needs the target to exist)
mlxm_configure_lib()      # include dirs, link libs, warnings, compile defs

add_subdirectory(src)     # recurse the tree — each dir attaches its own sources / targets

# ── Tests + benchmarks (separate top-level concerns, own their own lists) ──────
enable_testing()
add_subdirectory(bench)
add_subdirectory(tests)
