cmake_minimum_required(VERSION 3.20)
project(XML1DSP LANGUAGES C)
add_library(xml1-dsp STATIC dsp.c dsp_c.c dsp_dma.c interp/dsp_cpu.c interp/debug.c)
target_include_directories(xml1-dsp PUBLIC . PRIVATE compat)
target_compile_features(xml1-dsp PRIVATE c_std_11)
target_compile_definitions(xml1-dsp PRIVATE _CRT_SECURE_NO_WARNINGS)
set(OPENXML1_DSP56300_LIBRARY "" CACHE FILEPATH "Optional pinned DSP56300 MSVC static library for comparison")
set(OPENXML1_DSP56300_INCLUDE_DIR "" CACHE PATH "DSP56300 C header directory")
if(OPENXML1_DSP56300_LIBRARY)
    if(NOT EXISTS "${OPENXML1_DSP56300_LIBRARY}" OR NOT EXISTS "${OPENXML1_DSP56300_INCLUDE_DIR}/dsp56300.h")
        message(FATAL_ERROR "DSP56300 comparison library/header not found")
    endif()
    target_sources(xml1-dsp PRIVATE dsp_jit.c)
    target_compile_definitions(xml1-dsp PRIVATE XML1_HAVE_DSP_JIT=1)
    target_include_directories(xml1-dsp PRIVATE "${OPENXML1_DSP56300_INCLUDE_DIR}")
    target_link_libraries(xml1-dsp PUBLIC "${OPENXML1_DSP56300_LIBRARY}" bcrypt ntdll userenv ws2_32)
endif()
if(MSVC)
    target_compile_options(xml1-dsp PRIVATE /W3 /UNDEBUG)
endif()
add_executable(dsp-core-test ../../tests/dsp_core_test.c)
target_link_libraries(dsp-core-test PRIVATE xml1-dsp)
