plugin.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function(ocv_create_builtin_videoio_plugin name target)
  2. ocv_debug_message("ocv_create_builtin_videoio_plugin(${ARGV})")
  3. if(NOT TARGET ${target})
  4. message(FATAL_ERROR "${target} does not exist!")
  5. endif()
  6. if(NOT OpenCV_SOURCE_DIR)
  7. message(FATAL_ERROR "OpenCV_SOURCE_DIR must be set to build the plugin!")
  8. endif()
  9. message(STATUS "Video I/O: add builtin plugin '${name}'")
  10. foreach(src ${ARGN})
  11. list(APPEND sources "${CMAKE_CURRENT_LIST_DIR}/src/${src}")
  12. endforeach()
  13. add_library(${name} MODULE ${sources})
  14. target_include_directories(${name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
  15. target_compile_definitions(${name} PRIVATE BUILD_PLUGIN)
  16. target_link_libraries(${name} PRIVATE ${target})
  17. foreach(mod opencv_videoio opencv_core opencv_imgproc opencv_imgcodecs)
  18. ocv_target_link_libraries(${name} LINK_PRIVATE ${mod})
  19. ocv_target_include_directories(${name} "${OPENCV_MODULE_${mod}_LOCATION}/include")
  20. endforeach()
  21. if(WIN32)
  22. set(OPENCV_PLUGIN_VERSION "${OPENCV_DLLVERSION}" CACHE STRING "")
  23. if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
  24. set(OPENCV_PLUGIN_ARCH "_64" CACHE STRING "")
  25. else()
  26. set(OPENCV_PLUGIN_ARCH "" CACHE STRING "")
  27. endif()
  28. else()
  29. set(OPENCV_PLUGIN_VERSION "" CACHE STRING "")
  30. set(OPENCV_PLUGIN_ARCH "" CACHE STRING "")
  31. endif()
  32. set_target_properties(${name} PROPERTIES
  33. CXX_STANDARD 11
  34. CXX_VISIBILITY_PRESET hidden
  35. DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
  36. OUTPUT_NAME "${name}${OPENCV_PLUGIN_VERSION}${OPENCV_PLUGIN_ARCH}"
  37. )
  38. if(WIN32)
  39. set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
  40. install(TARGETS ${name} OPTIONAL LIBRARY DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT plugins)
  41. else()
  42. install(TARGETS ${name} OPTIONAL LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT plugins)
  43. endif()
  44. add_dependencies(opencv_videoio_plugins ${name})
  45. endfunction()