cmake_minimum_required(VERSION 3.13)

# 1. Define the INTERFACE library target for the Lost + Found HC-SR04 driver
add_library(lf-hcsr04 INTERFACE)

# Expose the source files from src/
target_sources(lf-hcsr04 INTERFACE
    ${CMAKE_CURRENT_LIST_DIR}/src/lf_hcsr04.c
)

# Expose the public header file search path from include/
target_include_directories(lf-hcsr04 INTERFACE
    ${CMAKE_CURRENT_LIST_DIR}/include
)

# Link hardware dependencies from the Pico C SDK
target_link_libraries(lf-hcsr04 INTERFACE
    pico_stdlib
    hardware_gpio
)

# 2. Standalone Demo Compilation (when run as root project for testing)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
    include(pico_sdk_import.cmake)
    project(lf_hcsr04_demo C CXX ASM)
    pico_sdk_init()

    add_executable(hcsr04_demo example.c)
    target_link_libraries(hcsr04_demo lf-hcsr04)

    # Enable USB CDC serial output and UART output
    pico_enable_stdio_usb(hcsr04_demo 1)
    pico_enable_stdio_uart(hcsr04_demo 1)

    # Generate UF2 and build outputs
    pico_add_extra_outputs(hcsr04_demo)
endif()
