2017-06-26 18:35:51 +08:00
if ( WINRT )
ocv_module_disable ( dnn )
endif ( )
2018-02-01 21:30:23 +08:00
if ( NOT HAVE_PROTOBUF )
2017-06-26 18:35:51 +08:00
ocv_module_disable ( opencv_dnn )
endif ( )
set ( the_description "Deep neural network module. It allows to load models from different frameworks and to make forward pass" )
2018-02-12 19:48:20 +08:00
ocv_add_dispatched_file_force_all ( "layers/layers_common" AVX AVX2 AVX512_SKX )
2017-07-13 23:42:36 +08:00
2018-09-17 19:55:42 +08:00
ocv_add_module ( dnn opencv_core opencv_imgproc WRAP python java js )
2018-02-28 18:58:55 +08:00
2018-06-26 14:35:18 +08:00
ocv_option ( OPENCV_DNN_OPENCL "Build with OpenCL support" HAVE_OPENCL AND NOT APPLE )
2018-02-28 18:58:55 +08:00
if ( OPENCV_DNN_OPENCL AND HAVE_OPENCL )
add_definitions ( -DCV_OCL4DNN=1 )
else ( )
ocv_cmake_hook_append ( INIT_MODULE_SOURCES_opencv_dnn "${CMAKE_CURRENT_LIST_DIR}/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake" )
endif ( )
2021-11-04 17:59:19 +08:00
if ( HAVE_TENGINE )
add_definitions ( -DHAVE_TENGINE=1 )
endif ( )
2017-06-26 18:35:51 +08:00
if ( MSVC )
add_definitions ( -D_CRT_SECURE_NO_WARNINGS=1 )
ocv_warnings_disable ( CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
/ w d 4 3 0 5 / w d 4 1 2 7 / w d 4 1 0 0 / w d 4 5 1 2 / w d 4 1 2 5 / w d 4 3 8 9 / w d 4 5 1 0 / w d 4 6 1 0
/ w d 4 7 0 2 / w d 4 4 5 6 / w d 4 4 5 7 / w d 4 0 6 5 / w d 4 3 1 0 / w d 4 6 6 1 / w d 4 5 0 6
)
else ( )
ocv_warnings_disable ( CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
2018-11-15 04:25:23 +08:00
- W u n u s e d - p a r a m e t e r - W s i g n - c o m p a r e
2017-06-26 18:35:51 +08:00
)
endif ( )
2019-08-08 20:49:32 +08:00
if ( HAVE_CUDA )
ocv_warnings_disable ( CMAKE_CXX_FLAGS -Wundef )
endif ( )
2018-11-15 04:25:23 +08:00
if ( NOT HAVE_CXX11 )
ocv_warnings_disable ( CMAKE_CXX_FLAGS -Wno-undef ) # LANG_CXX11 from protobuf files
endif ( )
2017-06-26 18:35:51 +08:00
if ( APPLE_FRAMEWORK )
ocv_warnings_disable ( CMAKE_CXX_FLAGS -Wshorten-64-to-32 )
endif ( )
if ( ANDROID )
add_definitions ( -DDISABLE_POSIX_MEMALIGN -DTH_DISABLE_HEAP_TRACKING )
endif ( )
2018-07-09 22:19:35 +08:00
if ( NOT BUILD_PROTOBUF )
add_definitions ( -DOPENCV_DNN_EXTERNAL_PROTOBUF=1 )
endif ( )
2017-06-26 18:35:51 +08:00
add_definitions ( -DHAVE_PROTOBUF=1 )
2018-02-01 21:30:23 +08:00
2018-02-12 20:07:39 +08:00
#suppress warnings in autogenerated caffe.pb.* files
2017-06-26 18:35:51 +08:00
ocv_warnings_disable ( CMAKE_CXX_FLAGS
/ w d 4 1 2 5 / w d 4 2 6 7 / w d 4 1 2 7 / w d 4 2 4 4 / w d 4 5 1 2 / w d 4 7 0 2
/ w d 4 4 5 6 / w d 4 5 1 0 / w d 4 6 1 0 / w d 4 8 0 0
2018-01-16 03:49:36 +08:00
/ w d 4 7 0 1 / w d 4 7 0 3 # potentially uninitialized local/pointer variable 'value' used
/ w d 4 5 0 5 # unreferenced local function has been removed
2019-12-12 01:16:58 +08:00
/ w d 4 4 5 8 # declaration of 'x' hides class member. GCC still works, MSVC bug is here: https://developercommunity.visualstudio.com/content/problem/219311/c-c4458-declaration-hides-class-member-warning-iss.html
2017-06-26 18:35:51 +08:00
- w d 8 5 8 - w d 2 1 9 6
2018-01-16 03:49:36 +08:00
- W i n v a l i d - o f f s e t o f # Apple Clang (attr_value.pb.cc)
2017-06-26 18:35:51 +08:00
)
2020-04-26 12:42:42 +08:00
set ( include_dirs "" )
set ( libs "" )
2017-06-26 18:35:51 +08:00
if ( PROTOBUF_UPDATE_FILES )
2018-09-11 02:07:51 +08:00
file ( GLOB proto_files "${CMAKE_CURRENT_LIST_DIR}/src/tensorflow/*.proto" "${CMAKE_CURRENT_LIST_DIR}/src/caffe/opencv-caffe.proto" "${CMAKE_CURRENT_LIST_DIR}/src/onnx/opencv-onnx.proto" )
2017-11-15 19:07:41 +08:00
set ( PROTOBUF_GENERATE_CPP_APPEND_PATH ON ) # required for tensorflow
2018-02-01 21:30:23 +08:00
protobuf_generate_cpp ( fw_srcs fw_hdrs ${ proto_files } )
2017-06-26 18:35:51 +08:00
else ( )
2018-09-11 02:07:51 +08:00
file ( GLOB fw_srcs "${CMAKE_CURRENT_LIST_DIR}/misc/tensorflow/*.cc" "${CMAKE_CURRENT_LIST_DIR}/misc/caffe/opencv-caffe.pb.cc" "${CMAKE_CURRENT_LIST_DIR}/misc/onnx/opencv-onnx.pb.cc" )
file ( GLOB fw_hdrs "${CMAKE_CURRENT_LIST_DIR}/misc/tensorflow/*.h" "${CMAKE_CURRENT_LIST_DIR}/misc/caffe/opencv-caffe.pb.h" "${CMAKE_CURRENT_LIST_DIR}/misc/onnx/opencv-onnx.pb.h" )
set ( fw_inc "${CMAKE_CURRENT_LIST_DIR}/misc/caffe" "${CMAKE_CURRENT_LIST_DIR}/misc/tensorflow" "${CMAKE_CURRENT_LIST_DIR}/misc/onnx" )
2017-06-26 18:35:51 +08:00
endif ( )
2020-04-26 12:42:42 +08:00
list ( APPEND include_dirs ${ fw_inc } )
list ( APPEND libs ${ Protobuf_LIBRARIES } )
if ( NOT BUILD_PROTOBUF )
list ( APPEND include_dirs ${ Protobuf_INCLUDE_DIRS } )
endif ( )
2018-02-28 18:58:55 +08:00
set ( sources_options "" )
2019-12-02 21:16:06 +08:00
2020-04-26 12:42:42 +08:00
list ( APPEND libs ${ LAPACK_LIBRARIES } )
2018-02-28 18:58:55 +08:00
if ( OPENCV_DNN_OPENCL AND HAVE_OPENCL )
list ( APPEND include_dirs ${ OPENCL_INCLUDE_DIRS } )
else ( )
set ( sources_options EXCLUDE_OPENCL )
endif ( )
2018-03-28 21:34:37 +08:00
2020-03-09 22:59:23 +08:00
if ( HAVE_TENGINE )
list ( APPEND include_dirs ${ TENGINE_INCLUDE_DIRS } )
if ( EXISTS ${ TENGINE_LIBRARIES } )
list ( APPEND libs ${ TENGINE_LIBRARIES } )
else ( )
ocv_add_dependencies ( opencv_dnn tengine )
list ( APPEND libs ${ TENGINE_LIBRARIES } )
endif ( )
endif ( )
2018-02-28 18:58:55 +08:00
ocv_module_include_directories ( ${ include_dirs } )
2018-03-20 18:26:13 +08:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
ocv_append_source_files_cxx_compiler_options ( fw_srcs "-Wno-suggest-override" ) # GCC
2020-03-27 19:39:07 +08:00
ocv_append_source_files_cxx_compiler_options ( fw_srcs "-Wno-array-bounds" ) # GCC 9.3.0 (Ubuntu 20.04)
2018-03-20 18:26:13 +08:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
ocv_append_source_files_cxx_compiler_options ( fw_srcs "-Wno-inconsistent-missing-override" ) # Clang
endif ( )
2019-12-02 21:16:06 +08:00
set ( dnn_runtime_libs "" )
2022-02-09 22:25:08 +08:00
ocv_option ( OPENCV_DNN_OPENVINO "Build with OpenVINO support (2021.4+)" ( TARGET ocv.3rdparty.openvino ) )
if ( TARGET ocv.3rdparty.openvino AND OPENCV_DNN_OPENVINO )
if ( NOT HAVE_OPENVINO AND NOT HAVE_NGRAPH )
message ( FATAL_ERROR "DNN: Inference Engine is not supported without enabled 'nGraph'. Check build configuration." )
endif ( )
2022-01-15 05:53:19 +08:00
list ( APPEND dnn_runtime_libs ocv.3rdparty.openvino )
2019-12-02 21:16:06 +08:00
endif ( )
2018-02-28 18:58:55 +08:00
ocv_glob_module_sources ( ${ sources_options } SOURCES ${ fw_srcs } )
2019-12-02 21:16:06 +08:00
ocv_create_module ( ${ libs } ${ dnn_runtime_libs } )
2017-06-26 18:35:51 +08:00
ocv_add_samples ( )
2019-12-02 21:16:06 +08:00
ocv_add_accuracy_tests ( ${ dnn_runtime_libs } )
2019-03-29 21:42:58 +08:00
set ( perf_path "${CMAKE_CURRENT_LIST_DIR}/perf" )
file ( GLOB_RECURSE perf_srcs "${perf_path}/*.cpp" )
file ( GLOB_RECURSE perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h" )
2022-01-15 05:53:19 +08:00
ocv_add_perf_tests ( ${ dnn_runtime_libs }
2019-03-31 16:51:09 +08:00
F I L E S t e s t _ c o m m o n " $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / t e s t / t e s t _ c o m m o n . h p p " " $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / t e s t / t e s t _ c o m m o n . i m p l . h p p "
2019-03-29 21:42:58 +08:00
F I L E S S r c $ { p e r f _ s r c s }
F I L E S I n c l u d e $ { p e r f _ h d r s }
)
2017-06-26 18:35:51 +08:00
2021-04-26 23:36:51 +08:00
ocv_option ( OPENCV_DNN_PERF_CAFFE "Add performance tests of Caffe framework" OFF )
ocv_option ( OPENCV_DNN_PERF_CLCAFFE "Add performance tests of clCaffe framework" OFF )
2017-08-04 20:09:57 +08:00
if ( BUILD_PERF_TESTS )
2021-04-26 23:36:51 +08:00
if ( OPENCV_DNN_PERF_CAFFE
O R $ { t h e _ m o d u l e } _ P E R F _ C A F F E # compatibility for deprecated option
)
2017-08-04 20:09:57 +08:00
find_package ( Caffe QUIET )
if ( Caffe_FOUND )
add_definitions ( -DHAVE_CAFFE=1 )
ocv_target_link_libraries ( opencv_perf_dnn caffe )
endif ( )
2021-04-26 23:36:51 +08:00
elseif ( OPENCV_DNN_PERF_CLCAFFE
O R $ { t h e _ m o d u l e } _ P E R F _ C A F F E # compatibility for deprecated option
)
2017-08-04 20:09:57 +08:00
find_package ( Caffe QUIET )
if ( Caffe_FOUND )
add_definitions ( -DHAVE_CLCAFFE=1 )
ocv_target_link_libraries ( opencv_perf_dnn caffe )
endif ( )
endif ( )
endif ( )