Neither Python example was registered as a test, so `ctest -L examples` in CI skipped them entirely -- which is how 08's missing Python node went unnoticed. Add a kpn_python_example() helper (gated on KPN_BUILD_PYTHON) that runs each script with PYTHONPATH pointed at the freshly-built module, so it does not depend on cwd or a hard-coded build/python path, and register 07 and 08. Also del the network in 07 for deterministic teardown.
84 lines
3.2 KiB
CMake
84 lines
3.2 KiB
CMake
cmake_minimum_required(VERSION 3.21)
|
|
|
|
# Build an example and register it as a CTest smoke test.
|
|
# Examples that are self-terminating (fixed sleep → net.stop()) pass when
|
|
# they exit 0 within TIMEOUT seconds. OpenCV/UI examples are excluded.
|
|
function(kpn_example name)
|
|
add_executable(${name} ${name}/main.cpp)
|
|
target_link_libraries(${name} PRIVATE kpn)
|
|
add_test(NAME example_${name} COMMAND ${name})
|
|
set_tests_properties(example_${name} PROPERTIES
|
|
TIMEOUT 15
|
|
LABELS examples
|
|
)
|
|
endfunction()
|
|
|
|
# Register a Python example script as a CTest smoke test. Runs the script with
|
|
# PYTHONPATH pointing at the freshly-built kpn_python module, so it does not
|
|
# depend on the caller's working directory or a hard-coded "build/python" path.
|
|
function(kpn_python_example name)
|
|
if(NOT KPN_BUILD_PYTHON)
|
|
return()
|
|
endif()
|
|
add_test(
|
|
NAME example_${name}
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
"PYTHONPATH=$<TARGET_FILE_DIR:kpn_python>"
|
|
${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${name}/example.py
|
|
)
|
|
set_tests_properties(example_${name} PROPERTIES
|
|
TIMEOUT 15
|
|
LABELS examples
|
|
)
|
|
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)
|
|
set_tests_properties(example_06_watchdog PROPERTIES TIMEOUT 40)
|
|
kpn_example(10_static_hello_pipeline)
|
|
kpn_example(11_static_fanout)
|
|
kpn_example(15_node_error_handler)
|
|
kpn_example(16_event_callbacks)
|
|
if(KPN_WEB_DEBUG)
|
|
kpn_target_enable_web_debug(06_watchdog)
|
|
|
|
add_executable(14_debug_hub 14_debug_hub/main.cpp)
|
|
target_link_libraries(14_debug_hub PRIVATE kpn)
|
|
kpn_target_enable_web_debug(14_debug_hub)
|
|
endif()
|
|
# 07 and 08 are Python scripts — no compiled target, but run as smoke tests.
|
|
kpn_python_example(07_python_network)
|
|
kpn_python_example(08_python_subport)
|
|
|
|
# 09 requires OpenCV — only build if found
|
|
find_package(OpenCV QUIET COMPONENTS core imgproc highgui videoio)
|
|
if(OpenCV_FOUND)
|
|
# Hybrid Python example: kpn_opencv module (requires both OpenCV and nanobind)
|
|
if(KPN_BUILD_PYTHON)
|
|
nanobind_add_module(kpn_opencv 09_opencv_cellshade/kpn_opencv.cpp)
|
|
target_link_libraries(kpn_opencv PRIVATE kpn ${OpenCV_LIBS})
|
|
target_compile_definitions(kpn_opencv PRIVATE KPN_BUILD_PYTHON)
|
|
message(STATUS "KPN++ kpn_opencv Python module: building (OpenCV ${OpenCV_VERSION})")
|
|
endif()
|
|
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()
|