cmake_minimum_required(VERSION 3.16)
project(gundam_w_static_core C)

file(GLOB GUNDAM_W_COMPACT_SCPU_GROUPS CONFIGURE_DEPENDS
    "${CMAKE_CURRENT_SOURCE_DIR}/generated/scpu/scpu_compact_group_*.c")

set(GUNDAM_W_CURRENT_SOURCES
    src/core_api.c
    src/machine_current.c
    src/bus_v06.c
    src/machine_v06.c
    src/scheduler_v07.c
    src/machine_v07.c
    src/dma_v08.c
    src/machine_v08.c
    src/ppu_v09.c
    src/machine_v09.c
    src/apuio_v10_1.c
    src/smp_current_support.c
    src/smp_v10_3_runtime.c
    src/scpu_current_ops.c
    src/input_current.c
    src/renderer_current.c
    src/raster_current.c
    src/sdsp_current.c
    src/sdsp_clock_current.c
    generated/scpu/scpu_index.c
    generated/scpu/scpu_compact_templates.c
    ${GUNDAM_W_COMPACT_SCPU_GROUPS}
    generated/smp_ipl_current/smp_ipl_current.c
    generated/smp_v10_3/smp_v10_3_index.c
    generated/smp_v10_3/smp_v10_3_phases.c
    generated/smp_v10_3/smp_v10_3_shard_04.c
    generated/smp_v10_3/smp_v10_3_shard_05.c
    generated/smp_v10_3/smp_v10_3_shard_06.c
    generated/smp_v10_3/smp_v10_3_shard_07.c
    generated/smp_v10_3/smp_v10_3_shard_08.c
    generated/smp_v10_3/smp_v10_3_shard_09.c
    generated/smp_v10_3/smp_v10_3_shard_0a.c
    generated/smp_v10_3/smp_v10_3_shard_0b.c
    generated/smp_v10_3/smp_v10_3_shard_0c.c
    generated/smp_v10_3/smp_v10_3_shard_0d.c
    generated/smp_v10_3/smp_v10_3_shard_0e.c
    generated/smp_v10_3/smp_v10_3_shard_0f.c
    generated/smp_v10_3/smp_v10_3_shard_10.c
    generated/smp_v10_3/smp_v10_3_shard_11.c
    generated/smp_v10_3/smp_v10_3_shard_12.c
    generated/smp_v10_3/smp_v10_3_shard_ff.c
)

# Current production deliberately selects exactly one V10.18 S-CPU primitive owner
# (src/scpu_current_ops.c) and one generated dispatcher/shard set.  The retained
# src/scpu_v05_ops.c file is historical reconstruction evidence only.
# Current production deliberately excludes historical execution owners:
#   src/machine_v10_1.c
#   src/machine_v10_2.c
#   src/machine_v10_3.c
#   src/smp_v10_2_runtime.c
#   generated/smp/* (the superseded 1,114-PC V10.2 dispatcher)
# They remain in the repository for certification/regression provenance only.

add_library(gundam-w-static-core STATIC ${GUNDAM_W_CURRENT_SOURCES})
option(GUNDAM_W_TEST_HOOKS "Enable explicit headless repair-only health recharge" OFF)
if(GUNDAM_W_TEST_HOOKS)
    target_compile_definitions(gundam-w-static-core PUBLIC GUNDAM_W_TEST_HOOKS=1)
endif()
target_include_directories(gundam-w-static-core
    PUBLIC include
    PRIVATE internal generated/scpu generated/smp_v10_3 generated/smp_ipl_current)
target_compile_features(gundam-w-static-core PUBLIC c_std_11)

# Historical owner files predate the current build graph and use dense one-line
# formatting. Keep warnings-as-errors globally but suppress only the stylistic
# misleading-indentation diagnostic on those unchanged semantic owners.
if(NOT MSVC)
    set_source_files_properties(
        src/bus_v06.c
        src/scheduler_v07.c
        src/machine_v07.c
        src/dma_v08.c
        src/apuio_v10_1.c
        src/smp_v10_3_runtime.c
        PROPERTIES COMPILE_OPTIONS "-Wno-misleading-indentation")
endif()

# The sealed V10.3 exact-PC generator intentionally gives every shard the same
# fixed scratch-variable frame. Some shards do not consume every scratch slot.
# Preserve those certified generated bytes and suppress only unused-variable for
# the generated shard translation units rather than hand-editing old authority.
file(GLOB GUNDAM_W_V10_3_SMP_SHARDS CONFIGURE_DEPENDS
    "${CMAKE_CURRENT_SOURCE_DIR}/generated/smp_v10_3/smp_v10_3_shard_*.c")
if(MSVC)
    set_source_files_properties(${GUNDAM_W_V10_3_SMP_SHARDS}
        PROPERTIES COMPILE_OPTIONS "/wd4189")
else()
    set_source_files_properties(${GUNDAM_W_V10_3_SMP_SHARDS}
        PROPERTIES COMPILE_OPTIONS "-Wno-unused-variable")
endif()

if(MSVC)
    target_compile_options(gundam-w-static-core PRIVATE /W4 /WX)
else()
    target_compile_options(gundam-w-static-core PRIVATE
        -Wall -Wextra -Wpedantic -Werror -ffunction-sections -fdata-sections)
endif()
