efe31a1cac0033236276c1acd58d2872667d9a26
[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_opencv_androidcamera)
128   list(APPEND highgui_srcs src/cap_android.cpp)
129   add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line
130 endif(HAVE_opencv_androidcamera)
131
132 if(HAVE_XIMEA)
133   list(APPEND highgui_srcs src/cap_ximea.cpp)
134   ocv_include_directories(${XIMEA_PATH})
135   if(XIMEA_LIBRARY_DIR)
136     link_directories("${XIMEA_LIBRARY_DIR}")
137   endif()
138   if(X86_64)
139     list(APPEND HIGHGUI_LIBRARIES m3apiX64)
140   else()
141     list(APPEND HIGHGUI_LIBRARIES m3api)
142   endif()
143 endif(HAVE_XIMEA)
144
145 if(HAVE_FFMPEG)
146   if(UNIX AND BZIP2_LIBRARIES)
147     list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
148   endif()
149   if(APPLE)
150     list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2)
151   endif()
152 endif(HAVE_FFMPEG)
153
154 if(HAVE_PVAPI)
155   add_definitions(-DHAVE_PVAPI)
156   add_definitions(${PVAPI_DEFINITIONS})
157   ocv_include_directories(${PVAPI_INCLUDE_PATH})
158   set(highgui_srcs src/cap_pvapi.cpp ${highgui_srcs})
159   list(APPEND HIGHGUI_LIBRARIES ${PVAPI_LIBRARY})
160 endif()
161
162 if(HAVE_GIGE_API)
163   add_definitions(-DHAVE_GIGE_API)
164   ocv_include_directories(${GIGEAPI_INCLUDE_PATH})
165   set(highgui_srcs src/cap_giganetix.cpp ${highgui_srcs})
166   list(APPEND HIGHGUI_LIBRARIES ${GIGEAPI_LIBRARIES})
167   list(APPEND highgui_srcs src/cap_giganetix.cpp)
168 endif(HAVE_GIGE_API)
169
170 if(HAVE_AVFOUNDATION)
171   list(APPEND highgui_srcs src/cap_avfoundation.mm)
172   list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
173 endif()
174
175 if(HAVE_QUICKTIME)
176   list(APPEND highgui_srcs src/cap_qt.cpp)
177   list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
178 elseif(HAVE_QTKIT)
179   list(APPEND highgui_srcs src/cap_qtkit.mm)
180   list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit")
181 endif()
182
183 if(HAVE_INTELPERC)
184   list(APPEND highgui_srcs src/cap_intelperc.cpp)
185   ocv_include_directories(${INTELPERC_INCLUDE_DIR})
186   list(APPEND HIGHGUI_LIBRARIES ${INTELPERC_LIBRARIES})
187 endif(HAVE_INTELPERC)
188
189 if(IOS)
190   add_definitions(-DHAVE_IOS=1)
191   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)
192   list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary")
193 endif()
194
195 if(WIN32)
196   link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only
197   include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW
198   include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include/ffmpeg_") # for tests
199 endif()
200
201 if(UNIX)
202   #these variables are set by CHECK_MODULE macro
203   foreach(P ${HIGHGUI_INCLUDE_DIRS})
204     ocv_include_directories(${P})
205   endforeach()
206
207   foreach(P ${HIGHGUI_LIBRARY_DIRS})
208     link_directories(${P})
209   endforeach()
210 endif()
211
212 source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
213 source_group("Include" FILES ${highgui_ext_hdrs})
214 ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs})
215 ocv_module_include_directories()
216
217 ocv_create_module(${HIGHGUI_LIBRARIES})
218
219 if(APPLE)
220   ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS)
221   if(HAVE_OBJC_EXCEPTIONS)
222     foreach(source ${OPENCV_MODULE_${the_module}_SOURCES})
223       if("${source}" MATCHES "\\.mm$")
224         get_source_file_property(flags "${source}" COMPILE_FLAGS)
225         if(flags)
226           set(flags "${_flags} -fobjc-exceptions")
227         else()
228           set(flags "-fobjc-exceptions")
229         endif()
230
231         set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}")
232       endif()
233     endforeach()
234   endif()
235 endif()
236
237 if(BUILD_SHARED_LIBS)
238   add_definitions(-DHIGHGUI_EXPORTS)
239 endif()
240
241 if(MSVC)
242   set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
243 endif()
244
245 #stop automatic dependencies propagation for this module
246 set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
247
248 ocv_add_precompiled_headers(${the_module})
249 ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
250
251 if(WIN32 AND WITH_FFMPEG)
252   #copy ffmpeg dll to the output folder
253   if(MSVC64 OR MINGW64)
254     set(FFMPEG_SUFFIX _64)
255   endif()
256
257   set(ffmpeg_bare_name "opencv_ffmpeg${FFMPEG_SUFFIX}.dll")
258   set(ffmpeg_bare_name_ver "opencv_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll")
259   set(ffmpeg_path "${OpenCV_SOURCE_DIR}/3rdparty/ffmpeg/${ffmpeg_bare_name}")
260
261   if(MSVC_IDE)
262     add_custom_command(TARGET ${the_module} POST_BUILD
263                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Release/${ffmpeg_bare_name_ver}"
264                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Debug/${ffmpeg_bare_name_ver}"
265                        COMMENT "Copying ${ffmpeg_path} to the output directory")
266   elseif(MSVC AND (CMAKE_GENERATOR MATCHES "Visual"))
267     add_custom_command(TARGET ${the_module} POST_BUILD
268                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${ffmpeg_bare_name_ver}"
269                        COMMENT "Copying ${ffmpeg_path} to the output directory")
270   else()
271     add_custom_command(TARGET ${the_module} POST_BUILD
272                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${ffmpeg_bare_name_ver}"
273                        COMMENT "Copying ${ffmpeg_path} to the output directory")
274   endif()
275
276   install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs RENAME "${ffmpeg_bare_name_ver}")
277 endif()
278
279 ocv_add_accuracy_tests()
280 ocv_add_perf_tests()