cmake_minimum_required(VERSION 3.16)
project(framecache C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -O2")

# ── libmicrohttpd ────────────────────────────────────────────────────
find_library(MHD_LIB microhttpd REQUIRED)
find_path(MHD_INCLUDE microhttpd.h REQUIRED)
include_directories(${MHD_INCLUDE})

# ── framecache server ────────────────────────────────────────────────
add_executable(framecache
    src/framecache.c
    src/slot.c
    src/registry.c
)
target_link_libraries(framecache ${MHD_LIB} rt pthread)

# ── fc_client static library (used by bridges + test) ───────────────
add_library(fc_client STATIC
    client/fc_client.c
    src/slot.c       # client needs fc_slot_shm_size / fc_frame_at
)
target_include_directories(fc_client PUBLIC src client)
target_link_libraries(fc_client rt pthread)

# ── test consumer (dev utility) ──────────────────────────────────────
if(BUILD_TESTS)
    add_executable(fc_test_consumer
        client/fc_test_consumer.c
    )
    target_link_libraries(fc_test_consumer fc_client)
    target_include_directories(fc_test_consumer PRIVATE src client)
endif()

install(TARGETS framecache DESTINATION bin)
install(FILES client/fc_client.h src/slot.h DESTINATION include/framecache)
install(TARGETS fc_client DESTINATION lib)
