# port/input: the input layers: the libpad
# subset (pad_host.c), the pad script reader (pad_script.c, the headless and
# test source), the virtual pad's arithmetic (vpad.c), the binding layer
# (bindings.c, input_config.c), the touch overlay's mapper (touch.c) and the
# mouse camera's capture rule and photo look accumulator (mouse_look.c), the
# camera speed and range the game's hand camera asks for (mouse_camera.c) and
# the menus' mouse pointer (pointer.c). The SDL3 device layer
# (input_sdl.c) is part of the window build only; the headless build has no
# SDL dependency.
add_library(ico_input STATIC
    bindings.c
    input_config.c
    input_record.c
    mouse_camera.c
    mouse_look.c
    pad_host.c
    pad_script.c
    pointer.c
    touch.c
    touch_edit.c
    touch_gap.c
    vpad.c)
target_include_directories(ico_input
    PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}"
    PRIVATE "${ICO_COMPAT_DIR}" "${CMAKE_SOURCE_DIR}/port/platform")
target_compile_options(ico_input PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
# stick fix and mirror are port/game/options.c's
target_link_libraries(ico_input PUBLIC ico_options)
# input_record.c opens its file through host_fs (UTF-8 paths on Windows)
target_link_libraries(ico_input PRIVATE ico_host_fs)
if(NOT ICO_HEADLESS AND TARGET SDL3::SDL3)
    target_sources(ico_input PRIVATE input_sdl.c)
    target_link_libraries(ico_input PUBLIC SDL3::SDL3)
    # input_sdl.c's rate-limited lines (diag_host.h ico_log_limited), so
    # they join the end-of-run summary's counts
    target_link_libraries(ico_input PRIVATE ico_platform)
endif()

# binding resolution, quantisation, the stick fix, merging, the libpad buffer
# and rumble. config.toml's reader lives in host_config.c, which ico_pc
# compiles itself, so the test compiles it too.
add_executable(input_test test/input_test.c ../platform/host_config.c)
target_include_directories(input_test PRIVATE "${ICO_COMPAT_DIR}" "${CMAKE_SOURCE_DIR}/port/platform")
target_compile_options(input_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(input_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME input COMMAND input_test)
endif()

# the pad recording (input_record.c): its format, the round trip
# through the pad script reader, and the sample point in scePadRead
add_executable(input_record_test test/input_record_test.c ../platform/host_config.c)
target_include_directories(input_record_test PRIVATE "${ICO_COMPAT_DIR}" "${CMAKE_SOURCE_DIR}/port/platform")
target_compile_options(input_record_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(input_record_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME input_record COMMAND input_record_test "${CMAKE_CURRENT_BINARY_DIR}")
endif()

# the touch overlay's mapper (touch.c): layouts, the floating
# stick, buttons under several fingers, the look pad, visibility and fades,
# and the merged pad through ico_input_vpad_to_frame
add_executable(touch_test test/touch_test.c)
target_compile_options(touch_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(touch_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME touch COMMAND touch_test)
endif()

# the touch layout edits and the layout editor (touch.c's apply_edits,
# touch_edit.c): an unedited layout is the default to the byte, the anchors,
# the clamp, hidden controls, the config text, the editor's state machine
# and the toolbar's spot
add_executable(touch_edit_test test/touch_edit_test.c)
target_compile_options(touch_edit_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(touch_edit_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME touch_edit COMMAND touch_edit_test)
endif()

# the Frame rate counter's place among the player's actual touch controls
# (touch_gap.c): the default layout's old place, Start moved to the top-left
# (drawn, Hidden, Off), every control Off, no room, the stick's ring
add_executable(touch_gap_test test/touch_gap_test.c)
target_compile_options(touch_gap_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(touch_gap_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME touch_gap COMMAND touch_gap_test)
endif()

# Touch controls "Always, Start only in scenes" (touch.c
# ico_touch_scene_alpha): the other modes unchanged, every control without the
# Start bit fading out over 300 ms in a scene, Start kept (or kept hidden), the
# mapper's layout untouched, the Frame rate counter's place on the faded copy
add_executable(touch_scene_test test/touch_scene_test.c)
target_compile_options(touch_scene_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(touch_scene_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME touch_scene COMMAND touch_scene_test)
endif()

# the mouse camera's speed and range for the hand camera: the step arithmetic
# and the gating on the mouse's stick driving the camera
add_executable(mouse_camera_test test/mouse_camera_test.c ../platform/host_config.c)
target_include_directories(mouse_camera_test PRIVATE "${ICO_COMPAT_DIR}" "${CMAKE_SOURCE_DIR}/port/platform")
target_compile_options(mouse_camera_test PRIVATE ${ICO_SEMANTIC_OPTIONS} ${ICO_PORT_WARNINGS})
target_link_libraries(mouse_camera_test PRIVATE ico_input)
if(ICO_RUN_TESTS)
    add_test(NAME mouse_camera COMMAND mouse_camera_test)
endif()
