Openni2 support
[profile/ivi/opencv.git] / modules / highgui / CMakeLists.txt
1 set(the_description "High-level GUI and Media I/O")
2 ocv_add_module(highgui opencv_imgproc opencv_imgcodecs OPTIONAL opencv_androidcamera)
3
4 # ----------------------------------------------------------------------------
5 #  CMake file for highgui. See root CMakeLists.txt
6 #   Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
7 #   Jose Luis Blanco, 2008
8 # ----------------------------------------------------------------------------
9
10 if(HAVE_WINRT_CX)
11   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
12 endif()
13
14 if(APPLE)
15   ocv_include_directories(${ZLIB_INCLUDE_DIRS})
16   list(APPEND HIGHGUI_LIBRARIES ${ZLIB_LIBRARIES})
17 endif()
18
19 set(highgui_hdrs
20     src/precomp.hpp
21     src/cap_ffmpeg_impl.hpp
22     )
23
24 set(highgui_srcs
25     src/cap.cpp
26     src/cap_images.cpp
27     src/cap_ffmpeg.cpp
28     src/window.cpp
29     )
30
31 file(GLOB highgui_ext_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
32
33 if(HAVE_QT5)
34   set(CMAKE_AUTOMOC ON)
35   set(CMAKE_INCLUDE_CURRENT_DIR ON)
36
37   QT5_ADD_RESOURCES(_RCC_OUTFILES src/window_QT.qrc)
38   list(APPEND highgui_srcs src/window_QT.cpp src/window_QT.h ${_RCC_OUTFILES})
39
40   foreach(dt5_dep Core Gui Widgets Test Concurrent)
41     add_definitions(${Qt5${dt5_dep}_DEFINITIONS})
42     include_directories(${Qt5${dt5_dep}_INCLUDE_DIRS})
43     list(APPEND HIGHGUI_LIBRARIES ${Qt5${dt5_dep}_LIBRARIES})
44   endforeach()
45
46   if(HAVE_QT_OPENGL)
47     add_definitions(${Qt5OpenGL_DEFINITIONS})
48     include_directories(${Qt5OpenGL_INCLUDE_DIRS})
49     list(APPEND HIGHGUI_LIBRARIES ${Qt5OpenGL_LIBRARIES})
50   endif()
51
52 elseif(HAVE_QT)
53   if (HAVE_QT_OPENGL)
54     set(QT_USE_QTOPENGL TRUE)
55   endif()
56   include(${QT_USE_FILE})
57
58   QT4_ADD_RESOURCES(_RCC_OUTFILES src/window_QT.qrc)
59   QT4_WRAP_CPP(_MOC_OUTFILES src/window_QT.h)
60
61   list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES})
62   list(APPEND highgui_srcs src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES})
63   ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag)
64   if(${_have_flag})
65     set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
66   endif()
67 elseif(HAVE_WIN32UI)
68   list(APPEND highgui_srcs src/window_w32.cpp)
69 elseif(HAVE_GTK OR HAVE_GTK3)
70   list(APPEND highgui_srcs src/window_gtk.cpp)
71 elseif(HAVE_CARBON)
72   list(APPEND highgui_srcs src/window_carbon.cpp)
73   list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime")
74 elseif(HAVE_COCOA)
75   list(APPEND highgui_srcs src/window_cocoa.mm)
76   list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
77 endif()
78
79 if(WIN32 AND NOT ARM)
80   list(APPEND highgui_srcs src/cap_cmu.cpp)
81 endif()
82
83 if (WIN32 AND HAVE_DSHOW)
84   list(APPEND highgui_srcs src/cap_dshow.cpp)
85 endif()
86
87 if (WIN32 AND HAVE_MSMF)
88   list(APPEND highgui_srcs src/cap_msmf.cpp)
89 endif()
90
91 if (WIN32 AND HAVE_VFW)
92   list(APPEND highgui_srcs src/cap_vfw.cpp)
93 endif()
94
95 if(HAVE_XINE)
96   list(APPEND highgui_srcs src/cap_xine.cpp)
97 endif(HAVE_XINE)
98
99 if(HAVE_DC1394_2)
100   list(APPEND highgui_srcs src/cap_dc1394_v2.cpp)
101 endif(HAVE_DC1394_2)
102
103 if(HAVE_DC1394)
104   list(APPEND highgui_srcs src/cap_dc1394.cpp)
105 endif(HAVE_DC1394)
106
107 if(HAVE_GSTREAMER)
108   list(APPEND highgui_srcs src/cap_gstreamer.cpp)
109 endif(HAVE_GSTREAMER)
110
111 if(HAVE_UNICAP)
112   list(APPEND highgui_srcs src/cap_unicap.cpp)
113 endif(HAVE_UNICAP)
114
115 if(HAVE_LIBV4L)
116   list(APPEND highgui_srcs src/cap_libv4l.cpp)
117 elseif(HAVE_CAMV4L OR HAVE_CAMV4L2 OR HAVE_VIDEOIO)
118   list(APPEND highgui_srcs src/cap_v4l.cpp)
119 endif()
120
121 if(HAVE_OPENNI)
122   list(APPEND highgui_srcs src/cap_openni.cpp)
123   ocv_include_directories(${OPENNI_INCLUDE_DIR})
124   list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY})
125 endif(HAVE_OPENNI)
126
127 if(HAVE_OPENNI2)
128   list(APPEND highgui_srcs src/cap_openni2.cpp)
129   ocv_include_directories(${OPENNI2_INCLUDE_DIR})
130   list(APPEND HIGHGUI_LIBRARIES ${OPENNI2_LIBRARY})
131 endif(HAVE_OPENNI2)
132
133 if(HAVE_opencv_androidcamera)
134   list(APPEND highgui_srcs src/cap_android.cpp)
135   add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line
136 endif(HAVE_opencv_androidcamera)
137
138 if(HAVE_XIMEA)
139   list(APPEND highgui_srcs src/cap_ximea.cpp)
140   ocv_include_directories(${XIMEA_PATH})
141   if(XIMEA_LIBRARY_DIR)
142     link_directories("${XIMEA_LIBRARY_DIR}")
143   endif()
144   if(X86_64)
145     list(APPEND HIGHGUI_LIBRARIES m3apiX64)
146   else()
147     list(APPEND HIGHGUI_LIBRARIES m3api)
148   endif()
149 endif(HAVE_XIMEA)
150
151 if(HAVE_FFMPEG)
152   if(UNIX AND BZIP2_LIBRARIES)
153     list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
154   endif()
155   if(APPLE)
156     list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2)
157   endif()
158 endif(HAVE_FFMPEG)
159
160 if(HAVE_PVAPI)
161   add_definitions(-DHAVE_PVAPI)
162   add_definitions(${PVAPI_DEFINITIONS})
163   ocv_include_directories(${PVAPI_INCLUDE_PATH})
164   set(highgui_srcs src/cap_pvapi.cpp ${highgui_srcs})
165   list(APPEND HIGHGUI_LIBRARIES ${PVAPI_LIBRARY})
166 endif()
167
168 if(HAVE_GIGE_API)
169   add_definitions(-DHAVE_GIGE_API)
170   ocv_include_directories(${GIGEAPI_INCLUDE_PATH})
171   set(highgui_srcs src/cap_giganetix.cpp ${highgui_srcs})
172   list(APPEND HIGHGUI_LIBRARIES ${GIGEAPI_LIBRARIES})
173   list(APPEND highgui_srcs src/cap_giganetix.cpp)
174 endif(HAVE_GIGE_API)
175
176 if(HAVE_AVFOUNDATION)
177   list(APPEND highgui_srcs src/cap_avfoundation.mm)
178   list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
179 endif()
180
181 if(HAVE_QUICKTIME)
182   list(APPEND highgui_srcs src/cap_qt.cpp)
183   list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
184 elseif(HAVE_QTKIT)
185   list(APPEND highgui_srcs src/cap_qtkit.mm)
186   list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit")
187 endif()
188
189 if(HAVE_INTELPERC)
190   list(APPEND highgui_srcs src/cap_intelperc.cpp)
191   ocv_include_directories(${INTELPERC_INCLUDE_DIR})
192   list(APPEND HIGHGUI_LIBRARIES ${INTELPERC_LIBRARIES})
193 endif(HAVE_INTELPERC)
194
195 if(IOS)
196   add_definitions(-DHAVE_IOS=1)
197   list(APPEND highgui_srcs src/ios_conversions.mm src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm)
198   list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary")
199 endif()
200
201 if(WIN32)
202   link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only
203   include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW
204   include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include/ffmpeg_") # for tests
205 endif()
206
207 if(UNIX)
208   #these variables are set by CHECK_MODULE macro
209   foreach(P ${HIGHGUI_INCLUDE_DIRS})
210     ocv_include_directories(${P})
211   endforeach()
212
213   foreach(P ${HIGHGUI_LIBRARY_DIRS})
214     link_directories(${P})
215   endforeach()
216 endif()
217
218 source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
219 source_group("Include" FILES ${highgui_ext_hdrs})
220 ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs})
221 ocv_module_include_directories()
222
223 ocv_create_module(${HIGHGUI_LIBRARIES})
224
225 if(APPLE)
226   ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS)
227   if(HAVE_OBJC_EXCEPTIONS)
228     foreach(source ${OPENCV_MODULE_${the_module}_SOURCES})
229       if("${source}" MATCHES "\\.mm$")
230         get_source_file_property(flags "${source}" COMPILE_FLAGS)
231         if(flags)
232           set(flags "${_flags} -fobjc-exceptions")
233         else()
234           set(flags "-fobjc-exceptions")
235         endif()
236
237         set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}")
238       endif()
239     endforeach()
240   endif()
241 endif()
242
243 if(BUILD_SHARED_LIBS)
244   add_definitions(-DHIGHGUI_EXPORTS)
245 endif()
246
247 if(MSVC)
248   set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
249 endif()
250
251 #stop automatic dependencies propagation for this module
252 set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
253
254 ocv_add_precompiled_headers(${the_module})
255 ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
256
257 if(WIN32 AND WITH_FFMPEG)
258   #copy ffmpeg dll to the output folder
259   if(MSVC64 OR MINGW64)
260     set(FFMPEG_SUFFIX _64)
261   endif()
262
263   set(ffmpeg_bare_name "opencv_ffmpeg${FFMPEG_SUFFIX}.dll")
264   set(ffmpeg_bare_name_ver "opencv_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll")
265   set(ffmpeg_path "${OpenCV_SOURCE_DIR}/3rdparty/ffmpeg/${ffmpeg_bare_name}")
266
267   if(MSVC_IDE)
268     add_custom_command(TARGET ${the_module} POST_BUILD
269                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Release/${ffmpeg_bare_name_ver}"
270                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Debug/${ffmpeg_bare_name_ver}"
271                        COMMENT "Copying ${ffmpeg_path} to the output directory")
272   elseif(MSVC AND (CMAKE_GENERATOR MATCHES "Visual"))
273     add_custom_command(TARGET ${the_module} POST_BUILD
274                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${ffmpeg_bare_name_ver}"
275                        COMMENT "Copying ${ffmpeg_path} to the output directory")
276   else()
277     add_custom_command(TARGET ${the_module} POST_BUILD
278                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${ffmpeg_bare_name_ver}"
279                        COMMENT "Copying ${ffmpeg_path} to the output directory")
280   endif()
281
282   install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs RENAME "${ffmpeg_bare_name_ver}")
283 endif()
284
285 ocv_add_accuracy_tests()
286 ocv_add_perf_tests()