mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 19:50:38 +08:00
153 lines
5.8 KiB
CMake
153 lines
5.8 KiB
CMake
if(WINRT)
|
|
ocv_module_disable(dnn)
|
|
endif()
|
|
|
|
if(NOT HAVE_PROTOBUF)
|
|
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")
|
|
|
|
ocv_add_dispatched_file_force_all("layers/layers_common" AVX AVX2 AVX512_SKX)
|
|
|
|
ocv_add_module(dnn opencv_core opencv_imgproc WRAP python java js)
|
|
|
|
ocv_option(OPENCV_DNN_OPENCL "Build with OpenCL support" HAVE_OPENCL AND NOT APPLE)
|
|
if(HAVE_TENGINE)
|
|
add_definitions(-DHAVE_TENGINE=1)
|
|
endif()
|
|
|
|
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()
|
|
|
|
if(MSVC)
|
|
add_definitions( -D_CRT_SECURE_NO_WARNINGS=1 )
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
|
|
/wd4305 /wd4127 /wd4100 /wd4512 /wd4125 /wd4389 /wd4510 /wd4610
|
|
/wd4702 /wd4456 /wd4457 /wd4065 /wd4310 /wd4661 /wd4506
|
|
)
|
|
else()
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
|
|
-Wunused-parameter -Wsign-compare
|
|
)
|
|
endif()
|
|
if(HAVE_CUDA)
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
|
|
endif()
|
|
if(NOT HAVE_CXX11)
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-undef) # LANG_CXX11 from protobuf files
|
|
endif()
|
|
|
|
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()
|
|
|
|
if(NOT BUILD_PROTOBUF)
|
|
add_definitions(-DOPENCV_DNN_EXTERNAL_PROTOBUF=1)
|
|
endif()
|
|
|
|
add_definitions(-DHAVE_PROTOBUF=1)
|
|
|
|
#suppress warnings in autogenerated caffe.pb.* files
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS
|
|
/wd4125 /wd4267 /wd4127 /wd4244 /wd4512 /wd4702
|
|
/wd4456 /wd4510 /wd4610 /wd4800
|
|
/wd4701 /wd4703 # potentially uninitialized local/pointer variable 'value' used
|
|
/wd4505 # unreferenced local function has been removed
|
|
/wd4458 # 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
|
|
-wd858 -wd2196
|
|
-Winvalid-offsetof # Apple Clang (attr_value.pb.cc)
|
|
)
|
|
|
|
if(PROTOBUF_UPDATE_FILES)
|
|
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")
|
|
set(PROTOBUF_GENERATE_CPP_APPEND_PATH ON) # required for tensorflow
|
|
protobuf_generate_cpp(fw_srcs fw_hdrs ${proto_files})
|
|
else()
|
|
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")
|
|
endif()
|
|
|
|
set(include_dirs ${fw_inc})
|
|
set(sources_options "")
|
|
|
|
set(libs libprotobuf ${LAPACK_LIBRARIES})
|
|
if(OPENCV_DNN_OPENCL AND HAVE_OPENCL)
|
|
list(APPEND include_dirs ${OPENCL_INCLUDE_DIRS})
|
|
else()
|
|
set(sources_options EXCLUDE_OPENCL)
|
|
endif()
|
|
|
|
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()
|
|
|
|
|
|
ocv_module_include_directories(${include_dirs})
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
ocv_append_source_files_cxx_compiler_options(fw_srcs "-Wno-suggest-override") # GCC
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
ocv_append_source_files_cxx_compiler_options(fw_srcs "-Wno-inconsistent-missing-override") # Clang
|
|
endif()
|
|
|
|
set(dnn_runtime_libs "")
|
|
if(INF_ENGINE_TARGET)
|
|
ocv_option(OPENCV_DNN_IE_NN_BUILDER_2019 "Build with Inference Engine NN Builder API support" ON) # future: NOT HAVE_NGRAPH
|
|
if(OPENCV_DNN_IE_NN_BUILDER_2019)
|
|
message(STATUS "DNN: Enabling Inference Engine NN Builder API support")
|
|
add_definitions(-DHAVE_DNN_IE_NN_BUILDER_2019=1)
|
|
endif()
|
|
list(APPEND dnn_runtime_libs ${INF_ENGINE_TARGET})
|
|
endif()
|
|
if(HAVE_NGRAPH)
|
|
message(STATUS "DNN: Enabling Inference Engine nGraph API support")
|
|
add_definitions(-DHAVE_DNN_NGRAPH)
|
|
list(APPEND dnn_runtime_libs ngraph::ngraph)
|
|
endif()
|
|
|
|
ocv_glob_module_sources(${sources_options} SOURCES ${fw_srcs})
|
|
ocv_create_module(${libs} ${dnn_runtime_libs})
|
|
ocv_add_samples()
|
|
ocv_add_accuracy_tests(${dnn_runtime_libs})
|
|
|
|
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")
|
|
ocv_add_perf_tests(${INF_ENGINE_TARGET}
|
|
FILES test_common "${CMAKE_CURRENT_LIST_DIR}/test/test_common.hpp" "${CMAKE_CURRENT_LIST_DIR}/test/test_common.impl.hpp"
|
|
FILES Src ${perf_srcs}
|
|
FILES Include ${perf_hdrs}
|
|
)
|
|
|
|
ocv_option(${the_module}_PERF_CAFFE "Add performance tests of Caffe framework" OFF)
|
|
ocv_option(${the_module}_PERF_CLCAFFE "Add performance tests of clCaffe framework" OFF)
|
|
if(BUILD_PERF_TESTS)
|
|
if (${the_module}_PERF_CAFFE)
|
|
find_package(Caffe QUIET)
|
|
if (Caffe_FOUND)
|
|
add_definitions(-DHAVE_CAFFE=1)
|
|
ocv_target_link_libraries(opencv_perf_dnn caffe)
|
|
endif()
|
|
elseif(${the_module}_PERF_CLCAFFE)
|
|
find_package(Caffe QUIET)
|
|
if (Caffe_FOUND)
|
|
add_definitions(-DHAVE_CLCAFFE=1)
|
|
ocv_target_link_libraries(opencv_perf_dnn caffe)
|
|
endif()
|
|
endif()
|
|
endif()
|