# mm_rsp — statically-recompiled RSP microcode + recomp::rsp::callbacks_t glue.
#
# Compiles the RSPRecomp-generated audio ucode (generated/aspMain.cpp) and the
# host-side task-dispatch glue into a static library used by the executable.
#
# The generated ucode references librecomp internals (dmem[], rspReciprocals[],
# the RSP VU implementation in rsp_vu_impl.hpp, recomp::rsp::run_task), so this
# lib declares a PUBLIC dependency on librecomp, so consumers get the headers
# and symbol definitions transitively.
#
# generated/ is build output (regenerated by `tools/N64Recomp/build/RSPRecomp
# aspMain.us1.rsp.toml`); it is intentionally not committed.

add_library(mm_rsp STATIC
    ${CMAKE_CURRENT_SOURCE_DIR}/generated/aspMain.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/rsp_callbacks.cpp
)

target_include_directories(mm_rsp PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}     # mm_rsp.hpp via "rsp/mm_rsp.hpp" from src/
    PRIVATE
    ${RUNTIME_INCLUDES}             # librecomp/*.hpp, recomp.h, ultramodern
)

# PUBLIC: w1's game target gets librecomp's headers + objects when it links
# mm_rsp (the generated ucode and the callback glue both call into librecomp).
target_link_libraries(mm_rsp PUBLIC librecomp mm_diagnostics)

# The generated ucode uses rabbitizer-emitted type-punning and -Wunused patterns
# similar to the game recomp; mirror mm_recompiled's permissive flags.
#
# rsp_vu_impl.hpp (included by the generated ucode) uses SSE4.1/SSSE3 intrinsics
# (_mm_shuffle_epi8, pcmpgtq, ...) on x86_64. The TU must be built with those
# ISA extensions enabled or the always_inline intrinsics fail with "target
# specific option mismatch". The reference (Zelda64Recomp) uses -march=nehalem
# for the same reason; -msse4.1 alone is sufficient (it implies SSSE3 on gcc).
target_compile_options(mm_rsp PRIVATE
    -fno-strict-aliasing
    -Wno-unused-variable
    -Wno-unused-but-set-variable
    $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>>:-msse4.1>
)
