build: fix MSVS2010
[platform/upstream/opencv.git] / modules / dnn / CMakeLists.txt
1 if(WINRT)
2   ocv_module_disable(dnn)
3 endif()
4
5 if(DEFINED BUILD_opencv_dnn AND NOT BUILD_opencv_dnn)
6   return()
7 endif()
8
9 include(${OpenCV_SOURCE_DIR}/cmake/OpenCVFindLibProtobuf.cmake)
10 if(NOT Protobuf_FOUND)
11   ocv_module_disable(opencv_dnn)
12 endif()
13
14 set(the_description "Deep neural network module. It allows to load models from different frameworks and to make forward pass")
15
16 ocv_add_dispatched_file("layers/layers_common" AVX AVX2)
17
18 ocv_add_module(dnn opencv_core opencv_imgproc WRAP python matlab java)
19 ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-shadow -Wno-parentheses -Wmaybe-uninitialized -Wsign-promo
20                                      -Wmissing-declarations -Wmissing-prototypes
21 )
22 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4701 /wd4100)
23
24 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/ocl4dnn/include ${OPENCL_INCLUDE_DIRS})
25
26 if(MSVC)
27   add_definitions( -D_CRT_SECURE_NO_WARNINGS=1 )
28   ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
29                                        /wd4305 /wd4127 /wd4100 /wd4512 /wd4125 /wd4389 /wd4510 /wd4610
30                                        /wd4702 /wd4456 /wd4457 /wd4065 /wd4310 /wd4661 /wd4506
31   )
32 else()
33   ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
34                                        -Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo
35                                        -Wundef -Wtautological-undefined-compare -Wignored-qualifiers -Wextra
36                                        -Wunused-function -Wunused-const-variable -Wdeprecated-declarations
37   )
38 endif()
39
40 if(APPLE_FRAMEWORK)
41   ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshorten-64-to-32)
42 endif()
43
44 if(ANDROID)
45   add_definitions(-DDISABLE_POSIX_MEMALIGN -DTH_DISABLE_HEAP_TRACKING)
46 endif()
47
48 #supress warnings in autogenerated caffe.pb.* files
49 add_definitions(-DHAVE_PROTOBUF=1)
50 ocv_warnings_disable(CMAKE_CXX_FLAGS
51     -Wunused-parameter -Wundef -Wignored-qualifiers -Wno-enum-compare
52     -Wdeprecated-declarations
53     /wd4125 /wd4267 /wd4127 /wd4244 /wd4512 /wd4702
54     /wd4456 /wd4510 /wd4610 /wd4800
55     -wd858 -wd2196
56 )
57
58 if(PROTOBUF_UPDATE_FILES)
59   file(GLOB proto_files src/tensorflow/*.proto)
60   list(APPEND proto_files src/caffe/caffe.proto)
61   PROTOBUF_GENERATE_CPP(Protobuf_HDRS Protobuf_SRCS ${proto_files})
62 else()
63   file(GLOB fw_srcs ${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow/*.cc)
64   file(GLOB fw_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow/*.h)
65   list(APPEND fw_srcs ${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe/caffe.pb.cc)
66   list(APPEND fw_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe/caffe.pb.h)
67   list(APPEND Protobuf_SRCS ${fw_srcs})
68   list(APPEND Protobuf_HDRS ${fw_hdrs})
69   list(APPEND Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe)
70   list(APPEND Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow)
71 endif()
72
73 ocv_source_group("Src\\protobuf" FILES ${Protobuf_SRCS} ${Protobuf_HDRS})
74 ocv_module_include_directories(include ${Protobuf_INCLUDE_DIRS})
75
76 ocv_glob_module_sources(${Protobuf_SRCS} ${Protobuf_HDRS} ${CBLAS_H_PROXY_PATH})
77 ocv_create_module(${Protobuf_LIBRARIES} ${LAPACK_LIBRARIES})
78 ocv_add_samples()
79 ocv_add_accuracy_tests()
80 ocv_add_perf_tests()
81
82 ocv_option(${the_module}_PERF_CAFFE "Add performance tests of Caffe framework" OFF)
83 ocv_option(${the_module}_PERF_CLCAFFE "Add performance tests of clCaffe framework" OFF)
84 if(BUILD_PERF_TESTS)
85   if (${the_module}_PERF_CAFFE)
86     find_package(Caffe QUIET)
87     if (Caffe_FOUND)
88       add_definitions(-DHAVE_CAFFE=1)
89       ocv_target_link_libraries(opencv_perf_dnn caffe)
90     endif()
91   elseif(${the_module}_PERF_CLCAFFE)
92     find_package(Caffe QUIET)
93     if (Caffe_FOUND)
94       add_definitions(-DHAVE_CLCAFFE=1)
95       ocv_target_link_libraries(opencv_perf_dnn caffe)
96     endif()
97   endif()
98 endif()
99
100 # ----------------------------------------------------------------------------
101 # Torch7 importer of blobs and models, produced by Torch.nn module
102 # ----------------------------------------------------------------------------
103 OCV_OPTION(${the_module}_BUILD_TORCH_IMPORTER "Build Torch model importer" ON)
104 if(${the_module}_BUILD_TORCH_IMPORTER)
105     message(STATUS "Torch importer has been enabled. To run the tests you have to install Torch "
106       "('th' executable should be available) "
107       "and generate testdata using opencv_extra/testdata/dnn/generate_torch_models.py script.")
108     add_definitions(-DENABLE_TORCH_IMPORTER=1)
109     ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4702 /wd4127 /wd4267) #supress warnings in original torch files
110 endif()