cmake_minimum_required(VERSION 3.23)
if(NOT DEFINED OpenCV_FOUND)
  find_package( OpenCV QUITE )
endif()
set(EXAMPLE_NAME rgbimageplot_opencv)
if (OpenCV_FOUND)

  set(EXENAME jkqtptest_${EXAMPLE_NAME})

  message( STATUS "..   Building Example ${EXAMPLE_NAME}" )

  # Set up source files
  set(SOURCES ${EXAMPLE_NAME}.cpp)
  set(HEADERS )
  set(RESOURCES  )
  set(UIS  )

  add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
target_link_libraries(${EXENAME} JKQTPExampleToolsLib)
  target_include_directories(${EXENAME} PRIVATE ../../lib)
  target_link_libraries(${EXENAME} ${jkqtplotter_namespace}JKQTPlotter${jkqtplotter_LIBNAME_VERSION_PART})
  include_directories(${EXENAME} ${OpenCV_INCLUDE_DIRS} )
  target_link_libraries(${EXENAME} ${OpenCV_LIBS} )

  # precomiled headers to speed up compilation
  if (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS)
    target_precompile_headers(${EXENAME} REUSE_FROM jkqtptest_simpletest)
  endif (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS)


  # Installation
  install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  #Installation of Qt DLLs on Windows
  jkqtplotter_deployqt(${EXENAME})
  #Installation of OpenCV DLLs on Windows
  jkqtplotter_deployopencv(${EXENAME})
  add_custom_command(TARGET ${EXENAME} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/rgbimageplot_opencv_example.bmp" $<TARGET_FILE_DIR:${EXENAME}>
  )
else()
  message( STATUS "..   SKIPPING Example ${EXAMPLE_NAME}, OpenCV not found" )

endif(OpenCV_FOUND)
