cmake_minimum_required(VERSION 3.21)

function(kpn_example name)
    add_executable(${name} ${name}/main.cpp)
    target_link_libraries(${name} PRIVATE kpn)
endfunction()

kpn_example(01_hello_pipeline)
kpn_example(02_named_ports)
kpn_example(03_multi_output)
kpn_example(04_storage_policy)
kpn_example(05_error_handling)
kpn_example(06_watchdog)
kpn_example(10_static_hello_pipeline)
kpn_example(11_static_fanout)
if(KPN_WEB_DEBUG)
    kpn_target_enable_web_debug(06_watchdog)
endif()
# 07 and 08 require the Python bindings — only add if built
if(KPN_BUILD_PYTHON)
    # These are Python scripts, not compiled targets — installed alongside kpn_python
endif()

# 09 requires OpenCV — only build if found
find_package(OpenCV QUIET COMPONENTS core imgproc highgui videoio)
if(OpenCV_FOUND)
    add_executable(09_opencv_cellshade 09_opencv_cellshade/main.cpp)
    target_link_libraries(09_opencv_cellshade PRIVATE kpn ${OpenCV_LIBS})

    add_executable(12_static_cellshade 12_static_cellshade/main.cpp)
    target_link_libraries(12_static_cellshade PRIVATE kpn ${OpenCV_LIBS})

    add_executable(13_debug_cellshade 13_debug_cellshade/main.cpp)
    target_link_libraries(13_debug_cellshade PRIVATE kpn ${OpenCV_LIBS})

    if(KPN_WEB_DEBUG)
        kpn_target_enable_web_debug(09_opencv_cellshade)
        kpn_target_enable_web_debug(13_debug_cellshade)
    endif()
    message(STATUS "KPN++ example 09_opencv_cellshade: OpenCV ${OpenCV_VERSION} found — building")
else()
    message(STATUS "KPN++ example 09_opencv_cellshade: OpenCV not found — skipping")
endif()
