cmake_minimum_required(VERSION 3.16)
project(rubo C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# The core is target-independent: everything between the framer and the
# interpreter is shared by the host and Pico builds (docs/flow.md §2).
add_library(rubo_core STATIC
    src/sym.c
    src/lexer.c
    src/registry.c
    src/parser.c
    src/exec.c
    src/framer.c
    src/session.c
    src/rubo.c
    src/natives.c
    src/stdlib.c
)
target_include_directories(rubo_core PUBLIC include)
target_compile_options(rubo_core PRIVATE
    -Wall -Wextra -Wpedantic -Wshadow -Wstrict-prototypes
)

# ----------------------------------------------------------------- host build
# Simulated HAL + stdio transport: the whole stack, no hardware.
add_library(rubo_sim STATIC src/hal_sim.c)
target_link_libraries(rubo_sim PUBLIC rubo_core)

add_executable(rubo_host host/main.c host/transport_stdio.c)
target_link_libraries(rubo_host PRIVATE rubo_core rubo_sim)

# ---------------------------------------------------------------------- tests
enable_testing()
add_executable(test_rubo tests/test_rubo.c)
target_link_libraries(test_rubo PRIVATE rubo_core rubo_sim)
target_include_directories(test_rubo PRIVATE src)
add_test(NAME rubo COMMAND test_rubo)

# ----------------------------------------------------------------- pico build
# Swapping in the real hardware means providing exactly two things: a
# rubo_transport_t over USB CDC / lwIP / BLE NUS, and a rubo_hal_t driving
# the motors. Nothing in rubo_core changes.
if(DEFINED ENV{PICO_SDK_PATH} OR DEFINED PICO_SDK_PATH)
    message(STATUS "rubo: PICO_SDK_PATH set, but pico/ is not implemented yet")
endif()
