7180b78c2aef8456f88f8b435a17b6a87d19844a
[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 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 ocv_clear_vars(GRFMT_LIBS)
11
12 if(WITH_PNG OR WITH_TIFF OR WITH_OPENEXR)
13   ocv_include_directories(${ZLIB_INCLUDE_DIR})
14   list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
15 endif()
16
17 if(WITH_JPEG)
18   add_definitions(-DHAVE_JPEG)
19   ocv_include_directories(${JPEG_INCLUDE_DIR})
20   list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
21 endif()
22
23 if(WITH_PNG)
24   add_definitions(-DHAVE_PNG)
25   add_definitions(${PNG_DEFINITIONS})
26   ocv_include_directories(${PNG_INCLUDE_DIR})
27   list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
28 endif()
29
30 if(WITH_TIFF)
31   add_definitions(-DHAVE_TIFF)
32   ocv_include_directories(${TIFF_INCLUDE_DIR})
33   list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
34 endif()
35
36 if(WITH_JASPER)
37   add_definitions(-DHAVE_JASPER)
38   ocv_include_directories(${JASPER_INCLUDE_DIR})
39   list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
40 endif()
41
42 if(WITH_OPENEXR AND OPENEXR_FOUND)
43   add_definitions(-DHAVE_OPENEXR)
44   ocv_include_directories(${OPENEXR_INCLUDE_PATHS})
45   list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
46 endif()
47
48 file(GLOB grfmt_hdrs src/grfmt*.hpp)
49 file(GLOB grfmt_srcs src/grfmt*.cpp)
50 list(APPEND grfmt_hdrs src/bitstrm.hpp)
51 list(APPEND grfmt_srcs src/bitstrm.cpp)
52
53 source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
54
55 set(highgui_hdrs
56     src/precomp.hpp
57     src/utils.hpp
58     src/cap_ffmpeg_impl.hpp
59     )
60
61 set(highgui_srcs
62     src/cap.cpp
63     src/cap_images.cpp
64     src/cap_ffmpeg.cpp
65     src/loadsave.cpp
66     src/precomp.cpp
67     src/utils.cpp
68     src/window.cpp
69     )
70
71 file(GLOB highgui_ext_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
72
73 if(HAVE_QT)
74   if (HAVE_QT_OPENGL)
75     set(QT_USE_QTOPENGL TRUE)
76   endif()
77   include(${QT_USE_FILE})
78
79   QT4_ADD_RESOURCES(_RCC_OUTFILES src/window_QT.qrc)
80   QT4_WRAP_CPP(_MOC_OUTFILES src/window_QT.h)
81
82   list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
83   list(APPEND highgui_srcs src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES} )
84 elseif(WIN32)
85   list(APPEND highgui_srcs src/window_w32.cpp)
86 elseif(HAVE_GTK)
87   list(APPEND highgui_srcs src/window_gtk.cpp)
88 elseif(APPLE)
89   if(WITH_CARBON)
90     add_definitions(-DHAVE_CARBON=1)
91     list(APPEND highgui_srcs src/window_carbon.cpp)
92     list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime")
93   elseif(NOT IOS)
94     add_definitions(-DHAVE_COCOA=1)
95     list(APPEND highgui_srcs src/window_cocoa.mm)
96     list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
97   endif()
98 endif()
99     
100 if(WIN32)
101   list(APPEND highgui_srcs src/cap_vfw.cpp src/cap_cmu.cpp src/cap_dshow.cpp)
102 endif(WIN32)
103
104 if(HAVE_XINE)
105   list(APPEND highgui_srcs src/cap_xine.cpp)
106 endif(HAVE_XINE)
107
108 if(HAVE_DC1394_2)
109   list(APPEND highgui_srcs src/cap_dc1394_v2.cpp)
110 endif(HAVE_DC1394_2)
111
112 if(HAVE_DC1394)
113   list(APPEND highgui_srcs src/cap_dc1394.cpp)
114 endif(HAVE_DC1394)
115
116 if(HAVE_GSTREAMER)
117   list(APPEND highgui_srcs src/cap_gstreamer.cpp)
118 endif(HAVE_GSTREAMER)
119
120 if(HAVE_UNICAP)
121   list(APPEND highgui_srcs src/cap_unicap.cpp)
122 endif(HAVE_UNICAP)
123
124 if(HAVE_LIBV4L)
125   list(APPEND highgui_srcs src/cap_libv4l.cpp)
126 elseif(HAVE_CAMV4L OR HAVE_CAMV4L2)
127   list(APPEND highgui_srcs src/cap_v4l.cpp)
128 endif()
129
130 if(HAVE_OPENNI)
131   list(APPEND highgui_srcs src/cap_openni.cpp)
132   ocv_include_directories(${OPENNI_INCLUDE_DIR})
133   list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY})
134 endif(HAVE_OPENNI)
135
136 if(HAVE_opencv_androidcamera)
137   list(APPEND highgui_srcs src/cap_android.cpp)
138   add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line
139 endif(HAVE_opencv_androidcamera)
140
141 if(HAVE_XIMEA)
142   list(APPEND highgui_srcs src/cap_ximea.cpp)
143   ocv_include_directories(${XIMEA_PATH})
144   link_directories(${XIMEA_LIBRARY_DIR})
145   list(APPEND HIGHGUI_LIBRARIES m3api)
146 endif(HAVE_XIMEA)
147
148 if(HAVE_FFMPEG)
149   if(UNIX AND BZIP2_LIBRARIES)
150     list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
151   elseif(APPLE)
152     list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration")
153   endif()
154 endif(HAVE_FFMPEG)
155
156 if(HAVE_PVAPI)
157   add_definitions(-DHAVE_PVAPI)
158   ocv_include_directories(${PVAPI_INCLUDE_PATH})
159   if(X86)
160     set(PVAPI_SDK_SUBDIR x86)
161   elseif(X86_64)
162     set(PVAPI_SDK_SUBDIR x64)
163   elseif(CMAKE_SYSTEM_PROCESSOR MATCHES arm)
164     set(PVAPI_SDK_SUBDIR arm)
165   endif()
166   if(PVAPI_SDK_SUBDIR AND CMAKE_COMPILER_IS_GNUCXX)
167     get_filename_component(PVAPI_EXPECTED_LIB_PATH "${PVAPI_INCLUDE_PATH}/../lib-pc/${PVAPI_SDK_SUBDIR}/${CMAKE_OPENCV_GCC_VERSION_MAJOR}.${CMAKE_OPENCV_GCC_VERSION_MINOR}" ABSOLUTE)
168     link_directories(${PVAPI_EXPECTED_LIB_PATH})
169   endif()
170   set(highgui_srcs src/cap_pvapi.cpp ${highgui_srcs})
171   set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} PvAPI)
172 endif()
173
174 if(WITH_IMAGEIO)
175   add_definitions(-DHAVE_IMAGEIO=1)
176   if(IOS)
177     list(APPEND HIGHGUI_LIBRARIES "-framework ImageIO")
178   endif()
179   #TODO: check if need to link with some framework on OS X: -framework ApplicationServices ??
180 endif(WITH_IMAGEIO)
181
182 if(WITH_AVFOUNDATION)
183   add_definitions(-DHAVE_AVFOUNDATION=1)
184   list(APPEND highgui_srcs src/cap_avfoundation.mm)
185   list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
186 elseif(APPLE)
187   add_definitions(-DHAVE_QUICKTIME=1)
188   if(WITH_QUICKTIME)
189     list(APPEND highgui_srcs src/cap_qt.cpp)
190     list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
191   else()
192     list(APPEND highgui_srcs src/cap_qtkit.mm)
193     list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore")
194   endif()
195 endif()
196
197 if(WIN32)
198   link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only
199   include_directories(AFTER "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW
200 endif()
201
202 if(UNIX)
203   #these variables are set by CHECK_MODULE macro
204   foreach(P ${HIGHGUI_INCLUDE_DIRS})
205     ocv_include_directories(${P})
206   endforeach()
207
208   foreach(P ${HIGHGUI_LIBRARY_DIRS})
209     link_directories(${P})
210   endforeach()
211 endif()
212
213 source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
214 source_group("Include" FILES ${highgui_ext_hdrs})
215 ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
216 ocv_module_include_directories()
217
218 ocv_list_unique(HIGHGUI_LIBRARIES)
219 ocv_create_module(${GRFMT_LIBS} ${HIGHGUI_LIBRARIES})
220
221 if(BUILD_SHARED_LIBS)
222   add_definitions(-DHIGHGUI_EXPORTS)
223 endif()
224
225 if(MSVC)
226   set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
227 endif()
228
229 #stop automatic dependencies propagation for this module
230 set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
231
232 ocv_add_precompiled_headers(${the_module})
233
234 if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
235   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
236 endif()
237
238 if(WIN32 AND WITH_FFMPEG)
239   #copy ffmpeg dll to the output folder
240   if(MSVC64 OR MINGW64)
241     set(FFMPEG_SUFFIX _64)
242   endif()
243   
244   set(ffmpeg_bare_name "opencv_ffmpeg${FFMPEG_SUFFIX}.dll")
245   set(ffmpeg_bare_name_ver "opencv_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll")
246   set(ffmpeg_path "${OpenCV_SOURCE_DIR}/3rdparty/ffmpeg/${ffmpeg_bare_name}")
247   
248   #if(MSVC AND CMAKE_VERSION VERSION_GREATER "2.8.2")
249   #  add_custom_command(TARGET ${the_module} POST_BUILD
250   #                     COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/$<CONFIGURATION>/${ffmpeg_bare_name_ver}"
251   #                     COMMENT "Copying ${ffmpeg_path} to the output directory")
252   #else
253   if(MSVC_IDE)
254     add_custom_command(TARGET ${the_module} POST_BUILD
255                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Release/${ffmpeg_bare_name_ver}"
256                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Debug/${ffmpeg_bare_name_ver}"
257                        COMMENT "Copying ${ffmpeg_path} to the output directory")
258   elseif(MSVC)
259     add_custom_command(TARGET ${the_module} POST_BUILD
260                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${ffmpeg_bare_name_ver}"
261                        COMMENT "Copying ${ffmpeg_path} to the output directory")
262   else()
263     add_custom_command(TARGET ${the_module} POST_BUILD
264                        COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${ffmpeg_bare_name_ver}"
265                        COMMENT "Copying ${ffmpeg_path} to the output directory")
266   endif()
267   
268   install(FILES "${ffmpeg_path}" DESTINATION bin COMPONENT main RENAME "${ffmpeg_bare_name_ver}")
269 endif()
270
271 ocv_add_accuracy_tests()
272 ocv_add_perf_tests()