cmake_minimum_required(VERSION 3.24)
project(BadBobPlayground VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(OpenCV 4.13 REQUIRED COMPONENTS core imgproc imgcodecs videoio highgui dnn)
if(NOT OpenCV_VERSION VERSION_LESS 5)
  message(FATAL_ERROR "This reference targets the OpenCV4.x API; use4.13or later4.x")
endif()
find_package(Threads REQUIRED)
add_library(badbob-core src/detection.cpp src/window_events.cpp)
target_include_directories(badbob-core PUBLIC include)
add_library(badbob-runtime src/opencv_detector.cpp src/runner.cpp src/output.cpp)
target_include_directories(badbob-runtime SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(badbob-runtime PUBLIC badbob-core ${OpenCV_LIBS} Threads::Threads)
add_executable(badbob-camera src/main.cpp)
target_link_libraries(badbob-camera PRIVATE badbob-runtime)
if(APPLE)
  target_link_options(badbob-camera PRIVATE "LINKER:-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_SOURCE_DIR}/Info.plist")
endif()
include(CTest)
if(BUILD_TESTING)
  add_executable(core-tests tests/core_tests.cpp)
  target_link_libraries(core-tests PRIVATE badbob-core)
  add_test(NAME geometry-decoder COMMAND core-tests)
  add_executable(slot-tests tests/slot_tests.cpp)
  target_link_libraries(slot-tests PRIVATE badbob-core Threads::Threads)
  add_test(NAME bounded-results COMMAND slot-tests)
  add_executable(runtime-tests tests/runtime_tests.cpp)
  target_link_libraries(runtime-tests PRIVATE badbob-runtime)
  add_test(NAME worker-lifecycle COMMAND runtime-tests)
  set_tests_properties(worker-lifecycle PROPERTIES TIMEOUT 10)
  add_executable(output-tests tests/output_tests.cpp)
  target_link_libraries(output-tests PRIVATE badbob-runtime)
  add_test(NAME exclusive-output COMMAND output-tests "${CMAKE_CURRENT_BINARY_DIR}")
  set_tests_properties(exclusive-output PROPERTIES TIMEOUT 10)
  add_executable(window-tests tests/window_tests.cpp)
  target_link_libraries(window-tests PRIVATE badbob-core)
  add_test(NAME window-event-policy COMMAND window-tests)
endif()
foreach(target badbob-core badbob-runtime badbob-camera core-tests slot-tests runtime-tests output-tests window-tests)
  if(TARGET ${target})
    if(MSVC)
      target_compile_options(${target} PRIVATE /W4 /WX)
    else()
      target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror)
    endif()
  endif()
endforeach()
