# MB Maniax – webová verze JNEXT. Přidává ji kořenový CMakeLists.txt JNEXT (viz jnext.patch),
# když se sestavuje Emscriptenem s -DJNEXT_WEB_DIR=<tato složka>.

# Síťová část správy SD karty (curl/OpenSSL) se ve webu nahrazuje prázdnou a příprava
# obrazu pro Raspberry Pi (nextpi, potřebuje OpenSSL a používá ho jen desktopová aplikace) se vynechá.
target_sources(jnext_core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/sdcard_net_stub.cpp)
get_target_property(_jnext_core_sources jnext_core SOURCES)
list(FILTER _jnext_core_sources EXCLUDE REGEX "nextpi_provisioner\\.cpp$")
set_property(TARGET jnext_core PROPERTY SOURCES ${_jnext_core_sources})

# Kolize makra PAGE_SIZE z <limits.h> Emscriptenu – viz web_compat.h.
foreach(_t jnext_core jnext_cpu jnext_memory jnext_video jnext_audio jnext_port
           jnext_peripheral jnext_input jnext_save jnext_debug jnext_profiler)
    target_compile_options(${_t} PRIVATE "SHELL:-include \"${CMAKE_CURRENT_SOURCE_DIR}/web_compat.h\"")
endforeach()

add_executable(jnext_web jnext_web.cpp)
target_link_libraries(jnext_web PRIVATE
    jnext_core jnext_cpu jnext_memory
    jnext_video jnext_audio jnext_port
    jnext_peripheral jnext_input
    jnext_save jnext_debug jnext_profiler
    ${JNEXT_SDL3_TARGET})
target_include_directories(jnext_web PRIVATE ${CMAKE_SOURCE_DIR}/src "${CMAKE_BINARY_DIR}/generated")

set_target_properties(jnext_web PROPERTIES OUTPUT_NAME "jnext" SUFFIX ".js")
target_link_options(jnext_web PRIVATE
    "-sMODULARIZE=1"
    "-sEXPORT_NAME=createJnext"
    "-sENVIRONMENT=web"
    "-sALLOW_MEMORY_GROWTH=1"
    "-sINITIAL_MEMORY=64MB"
    "-sSTACK_SIZE=1MB"
    "-sFORCE_FILESYSTEM=1"
    "-sEXPORTED_RUNTIME_METHODS=FS,ccall,HEAPU8,HEAP16,HEAPU32"
    "-sEXPORTED_FUNCTIONS=_malloc,_free"
    "-sINVOKE_RUN=0"
    "-sEXIT_RUNTIME=0")
