plugin.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function(ocv_create_builtin_dnn_plugin name target)
  2. ocv_debug_message("ocv_create_builtin_dnn_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 "DNN: add builtin plugin '${name}'")
  10. set(ENABLE_PRECOMPILED_HEADERS OFF) # no support for PCH in plugins, conflicts with module's source files
  11. # TODO: update CPU optimizations scripts to support plugins
  12. add_definitions(-D__OPENCV_BUILD=1)
  13. add_definitions(-DBUILD_PLUGIN=1)
  14. include_directories("${OPENCV_MODULE_opencv_dnn_BINARY_DIR}") # Cannot open include file: 'layers/layers_common.simd_declarations.hpp'
  15. foreach(src ${ARGN})
  16. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/src/${src}")
  17. list(APPEND sources "${CMAKE_CURRENT_LIST_DIR}/src/${src}")
  18. elseif(IS_ABSOLUTE "${src}")
  19. list(APPEND sources "${src}")
  20. else()
  21. message(FATAL_ERROR "Unknown source: ${src}")
  22. endif()
  23. endforeach()
  24. if(OPENCV_MODULE_${the_module}_SOURCES_DISPATCHED)
  25. list(APPEND sources ${OPENCV_MODULE_${the_module}_SOURCES_DISPATCHED})
  26. endif()
  27. set(__${name}_DEPS_EXT "")
  28. ocv_compiler_optimization_process_sources(sources __${name}_DEPS_EXT ${name})
  29. add_library(${name} MODULE ${sources})
  30. target_include_directories(${name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
  31. target_link_libraries(${name} PRIVATE ${target} ${__${name}_DEPS_EXT})
  32. target_link_libraries(${name} PRIVATE ${__plugin_libs})
  33. foreach(mod opencv_dnn
  34. opencv_core
  35. opencv_imgproc
  36. opencv_dnn
  37. )
  38. ocv_target_link_libraries(${name} LINK_PRIVATE ${mod})
  39. ocv_target_include_directories(${name} "${OPENCV_MODULE_${mod}_LOCATION}/include")
  40. endforeach()
  41. if(WIN32)
  42. set(OPENCV_PLUGIN_VERSION "${OPENCV_DLLVERSION}" CACHE STRING "")
  43. if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
  44. set(OPENCV_PLUGIN_ARCH "_64" CACHE STRING "")
  45. else()
  46. set(OPENCV_PLUGIN_ARCH "" CACHE STRING "")
  47. endif()
  48. else()
  49. set(OPENCV_PLUGIN_VERSION "" CACHE STRING "")
  50. set(OPENCV_PLUGIN_ARCH "" CACHE STRING "")
  51. endif()
  52. set_target_properties(${name} PROPERTIES
  53. CXX_STANDARD 11
  54. CXX_VISIBILITY_PRESET hidden
  55. DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
  56. OUTPUT_NAME "${name}${OPENCV_PLUGIN_VERSION}${OPENCV_PLUGIN_ARCH}"
  57. )
  58. if(WIN32)
  59. set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
  60. install(TARGETS ${name} OPTIONAL LIBRARY DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT plugins)
  61. else()
  62. install(TARGETS ${name} OPTIONAL LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT plugins)
  63. endif()
  64. add_dependencies(opencv_dnn_plugins ${name})
  65. endfunction()