Updated saving paths for highgui tests
[profile/ivi/opencv.git] / CMakeLists.txt
1 # ----------------------------------------------------------------------------
2 #  Root CMake file for OpenCV
3 #
4 #    From the off-tree build directory, invoke:
5 #      $ cmake <PATH_TO_OPENCV_ROOT>
6 #
7 #
8 #   - OCT-2008: Initial version <joseluisblancoc@gmail.com>
9 #
10 # ----------------------------------------------------------------------------
11
12 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
13
14 # --------------------------------------------------------------
15 # Indicate CMake 2.7 and above that we don't want to mix relative
16 #  and absolute paths in linker lib lists.
17 # Run "cmake --help-policy CMP0003" for more information.
18 # --------------------------------------------------------------
19 if(COMMAND cmake_policy)
20   cmake_policy(SET CMP0003 NEW)
21 endif()
22
23 # Following block can broke build in case of cross-compilng
24 # but CMAKE_CROSSCOMPILING variable will be set only on project(OpenCV) command
25 # so we will try to detect crosscompiling by presense of CMAKE_TOOLCHAIN_FILE
26 if(NOT CMAKE_TOOLCHAIN_FILE)
27   # it _must_ go before project(OpenCV) in order to work
28   if(WIN32)
29     set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
30   else()
31     set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory")
32   endif()
33
34   if(MSVC)
35     set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)
36   endif()
37 else(NOT CMAKE_TOOLCHAIN_FILE)
38   #Android: set output folder to ${CMAKE_BINARY_DIR}
39   set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to" )
40 endif(NOT CMAKE_TOOLCHAIN_FILE)
41
42 # --------------------------------------------------------------
43 # Top level OpenCV project
44 # --------------------------------------------------------------
45 if(NOT IOS)
46   cmake_minimum_required(VERSION 2.6.3)
47 else()
48   cmake_minimum_required(VERSION 2.8)
49 endif()
50
51 set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
52 if(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8")
53   set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} )
54 endif()
55
56 project(OpenCV)
57
58 include(cmake/OpenCVUtils.cmake REQUIRED)
59
60 # ----------------------------------------------------------------------------
61 # Detect compiler and target platform architecture
62 # ----------------------------------------------------------------------------
63 include(cmake/OpenCVDetectCXXCompiler.cmake REQUIRED)
64
65 # Add these standard paths to the search paths for FIND_LIBRARY
66 # to find libraries from these locations first
67 if(UNIX AND NOT ANDROID)
68   if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
69     if(EXISTS /lib64)
70       list(APPEND CMAKE_LIBRARY_PATH /lib64)
71     else()
72       list(APPEND CMAKE_LIBRARY_PATH /lib)
73     endif()
74     if(EXISTS /usr/lib64)
75       list(APPEND CMAKE_LIBRARY_PATH /usr/lib64)
76     else()
77       list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
78     endif()
79   elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
80     if(EXISTS /lib32)
81       list(APPEND CMAKE_LIBRARY_PATH /lib32)
82     else()
83       list(APPEND CMAKE_LIBRARY_PATH /lib)
84     endif()
85     if(EXISTS /usr/lib32)
86       list(APPEND CMAKE_LIBRARY_PATH /usr/lib32)
87     else()
88       list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
89     endif()
90   endif()
91 endif()
92
93
94 # ----------------------------------------------------------------------------
95 # OpenCV cmake options
96 # ----------------------------------------------------------------------------
97
98 # Optional 3rd party components
99 # ===================================================
100 OCV_OPTION(WITH_1394           "Include IEEE1394 support"                    ON   IF (UNIX AND NOT ANDROID AND NOT IOS) )
101 OCV_OPTION(WITH_AVFOUNDATION   "Use AVFoundation for Video I/O"              ON   IF IOS)
102 OCV_OPTION(WITH_CARBON         "Use Carbon for UI instead of Cocoa"          OFF  IF APPLE )
103 OCV_OPTION(WITH_CUBLAS         "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT ANDROID AND NOT IOS) )
104 OCV_OPTION(WITH_CUDA           "Include NVidia Cuda Runtime support"         ON   IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT ANDROID AND NOT IOS) )
105 OCV_OPTION(WITH_CUFFT          "Include NVidia Cuda Fast Fourier Transform (FFT) library support"            ON  IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT ANDROID AND NOT IOS) )
106 OCV_OPTION(WITH_EIGEN          "Include Eigen2/Eigen3 support"               ON)
107 OCV_OPTION(WITH_FFMPEG         "Include FFMPEG support"                      ON   IF (UNIX AND NOT ANDROID AND NOT IOS) )
108 OCV_OPTION(WITH_GSTREAMER      "Include Gstreamer support"                   ON   IF (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS) )
109 OCV_OPTION(WITH_GTK            "Include GTK support"                         ON   IF (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS) )
110 OCV_OPTION(WITH_IPP            "Include Intel IPP support"                   OFF  IF (MSVC OR X86 OR X86_64) )
111 OCV_OPTION(WITH_JASPER         "Include JPEG2K support"                      ON   IF (NOT IOS) )
112 OCV_OPTION(WITH_JPEG           "Include JPEG support"                        ON   IF (NOT IOS) )
113 OCV_OPTION(WITH_OPENEXR        "Include ILM support via OpenEXR"             ON   IF (NOT IOS) )
114 OCV_OPTION(WITH_OPENGL         "Include OpenGL support"                      OFF  IF (NOT ANDROID AND NOT IOS) )
115 OCV_OPTION(WITH_OPENNI         "Include OpenNI support"                      OFF  IF (NOT ANDROID AND NOT IOS) )
116 OCV_OPTION(WITH_PNG            "Include PNG support"                         ON   IF (NOT IOS) )
117 OCV_OPTION(WITH_PVAPI          "Include Prosilica GigE support"              ON   IF (UNIX AND NOT ANDROID AND NOT IOS) )
118 OCV_OPTION(WITH_QT             "Build with Qt Backend support"               OFF  IF (NOT ANDROID AND NOT IOS) )
119 OCV_OPTION(WITH_QUICKTIME      "Use QuickTime for Video I/O insted of QTKit" OFF  IF APPLE )
120 OCV_OPTION(WITH_TBB            "Include Intel TBB support"                   OFF  IF (NOT IOS) )
121 OCV_OPTION(WITH_TIFF           "Include TIFF support"                        ON   IF (NOT IOS) )
122 OCV_OPTION(WITH_UNICAP         "Include Unicap support (GPL)"                OFF  IF (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS) )
123 OCV_OPTION(WITH_V4L            "Include Video 4 Linux support"               ON   IF (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS) )
124 OCV_OPTION(WITH_VIDEOINPUT     "Build HighGUI with DirectShow support"       ON   IF WIN32 )
125 OCV_OPTION(WITH_XIMEA          "Include XIMEA cameras support"               OFF  IF WIN32 )
126 OCV_OPTION(WITH_XINE           "Include Xine support (GPL)"                  OFF  IF (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS) )
127
128 # OpenCV build components
129 # ===================================================
130 OCV_OPTION(BUILD_SHARED_LIBS        "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" NOT (ANDROID OR IOS) )
131 OCV_OPTION(BUILD_ANDROID_EXAMPLES   "Build examples for Android platform"         ON  IF ANDROID )
132 OCV_OPTION(BUILD_DOCS               "Create build rules for OpenCV Documentation" ON )
133 OCV_OPTION(BUILD_EXAMPLES           "Build all examples"                          OFF )
134 OCV_OPTION(BUILD_PACKAGE            "Enables 'make package_source' command"       ON )
135 OCV_OPTION(BUILD_PERF_TESTS         "Build performance tests"                     ON  IF (NOT IOS) )
136 OCV_OPTION(BUILD_TESTS              "Build accuracy & regression tests"           ON  IF (NOT IOS) )
137 OCV_OPTION(BUILD_WITH_DEBUG_INFO    "Include debug info into debug libs (not MSCV only)" ON )
138 OCV_OPTION(BUILD_WITH_STATIC_CRT    "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC )
139 OCV_OPTION(BUILD_FAT_JAVA_LIB       "Create fat java wrapper containing the whole OpenCV library" ON IF ANDROID AND NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX )
140
141 # 3rd party libs
142 OCV_OPTION(BUILD_ZLIB               "Build zlib from source"         WIN32 OR IOS )
143 OCV_OPTION(BUILD_TIFF               "Build libtiff from source"      WIN32 OR IOS OR ANDROID )
144 OCV_OPTION(BUILD_JASPER             "Build libjasper from source"    WIN32 OR IOS OR ANDROID )
145 OCV_OPTION(BUILD_JPEG               "Build libjpeg from source"      WIN32 OR IOS OR ANDROID )
146 OCV_OPTION(BUILD_PNG                "Build libpng from source"       WIN32 OR IOS OR ANDROID )
147
148 # OpenCV installation options
149 # ===================================================
150 OCV_OPTION(INSTALL_C_EXAMPLES       "Install C examples"        OFF )
151 OCV_OPTION(INSTALL_PYTHON_EXAMPLES  "Install Python examples"   OFF )
152 OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples"  OFF  IF ANDROID )
153 OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT IOS AND BUILD_SHARED_LIBS) )
154
155 # OpenCV build options
156 # ===================================================
157 OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers"                                  ON   IF (NOT IOS) )
158 OCV_OPTION(ENABLE_SOLUTION_FOLDERS    "Solution folder in Visual Studio or in other IDEs"        MSVC_IDE IF (CMAKE_VERSION VERSION_GREATER "2.8.0") )
159 OCV_OPTION(ENABLE_PROFILING           "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF  IF CMAKE_COMPILER_IS_GNUCXX )
160 OCV_OPTION(ENABLE_OMIT_FRAME_POINTER  "Enable -fomit-frame-pointer for GCC"                      ON   IF CMAKE_COMPILER_IS_GNUCXX )
161 OCV_OPTION(ENABLE_POWERPC             "Enable PowerPC for GCC"                                   ON   IF (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
162 OCV_OPTION(ENABLE_FAST_MATH           "Enable -ffast-math (not recommended for GCC 4.6.x)"       OFF  IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
163 OCV_OPTION(ENABLE_SSE                 "Enable SSE instructions"                                  ON   IF (MSVC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
164 OCV_OPTION(ENABLE_SSE2                "Enable SSE2 instructions"                                 ON   IF (MSVC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
165 OCV_OPTION(ENABLE_SSE3                "Enable SSE3 instructions"                                 OFF  IF (CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
166 OCV_OPTION(ENABLE_SSSE3               "Enable SSSE3 instructions"                                OFF  IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
167 OCV_OPTION(ENABLE_SSE41               "Enable SSE4.1 instructions"                               OFF  IF (CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
168 OCV_OPTION(ENABLE_SSE42               "Enable SSE4.2 instructions"                               OFF  IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
169 OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors"                                 OFF )
170
171 # uncategorized options
172 # ===================================================
173 OCV_OPTION(CMAKE_VERBOSE "Verbose mode" OFF )
174
175 # backward compatibility
176 # ===================================================
177 include(cmake/OpenCVLegacyOptions.cmake OPTIONAL)
178
179
180 # ----------------------------------------------------------------------------
181 #  Get actual OpenCV version number from sources
182 # ----------------------------------------------------------------------------
183 include(cmake/OpenCVVersion.cmake REQUIRED)
184
185
186 # ----------------------------------------------------------------------------
187 #  Build & install layouts
188 # ----------------------------------------------------------------------------
189
190 # Save libs and executables in the same place
191 set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Output directory for libraries" )
192 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Output directory for applications" )
193
194 if(ANDROID OR WIN32)
195     set(OPENCV_DOC_INSTALL_PATH doc)
196 elseif(INSTALL_TO_MANGLED_PATHS)
197     set(OPENCV_DOC_INSTALL_PATH share/OpenCV-${OPENCV_VERSION}/doc)
198 else()
199     set(OPENCV_DOC_INSTALL_PATH share/OpenCV/doc)
200 endif()
201
202 if(ANDROID)
203     set(OPENCV_LIB_INSTALL_PATH libs/${ANDROID_NDK_ABI_NAME})
204 else()
205     set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX})
206 endif()
207
208 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}")
209 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
210
211 set(OPENCV_INCLUDE_PREFIX include)
212 if(INSTALL_TO_MANGLED_PATHS)
213   set(OPENCV_INCLUDE_PREFIX include/opencv-${OPENCV_VERSION})
214 endif()
215
216 if(WIN32)
217   # Postfix of DLLs:
218   set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
219   set(OPENCV_DEBUG_POSTFIX d)
220 else()
221   # Postfix of so's:
222   set(OPENCV_DLLVERSION "")
223   set(OPENCV_DEBUG_POSTFIX "")
224 endif()
225
226 if(DEFINED CMAKE_DEBUG_POSTFIX)
227   set(OPENCV_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
228 endif()
229
230 if(CMAKE_VERBOSE)
231   set(CMAKE_VERBOSE_MAKEFILE 1)
232 endif()
233
234
235 # ----------------------------------------------------------------------------
236 #  Path for build/platform -specific headers
237 # ----------------------------------------------------------------------------
238 set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h")
239 add_definitions(-DHAVE_CVCONFIG_H)
240 ocv_include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR})
241
242
243 # ----------------------------------------------------------------------------
244 # Use statically or dynamically linked CRT?
245 # Default: dynamic
246 # ----------------------------------------------------------------------------
247 if(MSVC)
248   include(cmake/OpenCVCRTLinkage.cmake REQUIRED)
249 endif(MSVC)
250
251
252 # ----------------------------------------------------------------------------
253 #  Autodetect if we are in a SVN repository
254 # ----------------------------------------------------------------------------
255 find_host_program(SVNVERSION_PATH svnversion)
256 mark_as_advanced(force SVNVERSION_PATH)
257 if(SVNVERSION_PATH)
258     message(STATUS "Extracting svn version, please wait...")
259     execute_process(COMMAND ${SVNVERSION_PATH} -n ${OpenCV_SOURCE_DIR} OUTPUT_VARIABLE SVNVERSION_RESULT)
260
261     if(SVNVERSION_RESULT MATCHES "exported")
262         # This is NOT a svn repository:
263         set(OPENCV_SVNVERSION "")
264         message(STATUS "SVNVERSION: exported")
265     else()
266         set(OPENCV_SVNVERSION " svn:${SVNVERSION_RESULT}")
267         message(STATUS "SVNVERSION: ${OPENCV_SVNVERSION}")
268     endif()
269 else()
270     # We don't have svnversion:
271     set(OPENCV_SVNVERSION "")
272 endif()
273
274
275 # ----------------------------------------------------------------------------
276 # OpenCV compiler and linker options
277 # ----------------------------------------------------------------------------
278 include(cmake/OpenCVCompilerOptions.cmake REQUIRED)
279
280 # In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release:
281 if(CMAKE_GENERATOR MATCHES "Makefiles" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
282   set(CMAKE_BUILD_TYPE Release)
283 endif()
284
285
286 # ----------------------------------------------------------------------------
287 #       CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC..
288 # ----------------------------------------------------------------------------
289 if(UNIX)
290   include(cmake/OpenCVFindPkgConfig.cmake OPTIONAL)
291   include(CheckFunctionExists)
292   include(CheckIncludeFile)
293 endif()
294
295 include(cmake/OpenCVPCHSupport.cmake REQUIRED)
296 include(cmake/OpenCVModule.cmake REQUIRED)
297
298 if(ANDROID)
299   include(cmake/OpenCVAndroidProject.cmake REQUIRED)
300 endif()
301
302
303 # ----------------------------------------------------------------------------
304 #  Detect 3rd-party tools and libraries
305 # ----------------------------------------------------------------------------
306
307 # IO libraries
308 include(cmake/OpenCVIOLibs.cmake REQUIRED)
309
310 #Graphic libraries
311 set(HAVE_OPENGL 0)
312 if(UNIX)
313     if(NOT APPLE)
314       if(WITH_GTK)
315         CHECK_MODULE(gtk+-2.0 HAVE_GTK)
316         CHECK_MODULE(gthread-2.0 HAVE_GTHREAD)
317         if(WITH_OPENGL)
318             CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT)
319             if(HAVE_GTKGLEXT)
320                 find_package(OpenGL QUIET)
321                 if(OPENGL_FOUND)
322                     set(HAVE_OPENGL 1)
323                     set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES})
324                     ocv_include_directories(${OPENGL_INCLUDE_DIR})
325                 endif()
326             endif()
327         endif()
328       else()
329         set(HAVE_GTK FALSE)
330         set(HAVE_GTHREAD FALSE)
331       endif()
332       if(WITH_GSTREAMER)
333         CHECK_MODULE(gstreamer-base-0.10 HAVE_GSTREAMER)
334         CHECK_MODULE(gstreamer-app-0.10 HAVE_GSTREAMER)
335         CHECK_MODULE(gstreamer-video-0.10 HAVE_GSTREAMER)
336       else()
337         set(HAVE_GSTREAMER FALSE)
338       endif()
339     endif()
340
341     if(WITH_UNICAP)
342       CHECK_MODULE(libunicap HAVE_UNICAP_)
343       CHECK_MODULE(libucil HAVE_UNICAP_UCIL)
344       if(HAVE_UNICAP_ AND HAVE_UNICAP_UCIL)
345         set(HAVE_UNICAP 1)
346       endif()
347     else()
348       set(HAVE_UNICAP FALSE)
349     endif()
350
351     if(WITH_PVAPI)
352       find_path(PVAPI_INCLUDE_PATH "PvApi.h"
353                 PATHS "/usr/local/include" "/usr/include"
354                 DOC "The path to PvAPI header")
355       if(PVAPI_INCLUDE_PATH)
356         set(HAVE_PVAPI 1)
357       endif()
358     endif()
359
360     set(HAVE_FFMPEG 0)
361     if(WITH_FFMPEG)
362       CHECK_MODULE(libavcodec HAVE_FFMPEG_CODEC)
363       CHECK_MODULE(libavformat HAVE_FFMPEG_FORMAT)
364       CHECK_MODULE(libavutil HAVE_FFMPEG_UTIL)
365       CHECK_MODULE(libswscale HAVE_FFMPEG_SWSCALE)
366       CHECK_INCLUDE_FILE(libavformat/avformat.h HAVE_GENTOO_FFMPEG)
367       CHECK_INCLUDE_FILE(ffmpeg/avformat.h HAVE_FFMPEG_FFMPEG)
368       if(NOT HAVE_GENTOO_FFMPEG AND NOT HAVE_FFMPEG_FFMPEG)
369         if(EXISTS /usr/include/ffmpeg/libavformat/avformat.h OR HAVE_FFMPEG_SWSCALE)
370           set(HAVE_GENTOO_FFMPEG 1)
371         endif()
372       endif()
373       if(HAVE_FFMPEG_CODEC AND HAVE_FFMPEG_FORMAT AND HAVE_FFMPEG_UTIL)
374         if(HAVE_FFMPEG_SWSCALE OR NOT HAVE_GENTOO_FFMPEG)
375             set(HAVE_FFMPEG 1)
376         endif()
377       endif()
378
379       # Find the bzip2 library because it is required on some systems
380       FIND_LIBRARY(BZIP2_LIBRARIES NAMES bz2 bzip2)
381       if(NOT BZIP2_LIBRARIES)
382         # Do an other trial
383         FIND_FILE(BZIP2_LIBRARIES NAMES libbz2.so.1 PATHS /lib)
384       endif()
385     endif()
386
387     if(HAVE_FFMPEG)
388     CHECK_MODULE(libavformat>=52.111.0 NEW_FFMPEG)
389     endif()
390
391     if(WITH_1394)
392       CHECK_MODULE(libdc1394-2 HAVE_DC1394_2)
393       if(NOT HAVE_DC1394_2)
394         CHECK_MODULE(libdc1394 HAVE_DC1394)
395       endif()
396     else()
397       set(HAVE_DC1394_2 FALSE)
398       set(HAVE_DC1394 FALSE)
399     endif()
400
401     if(NOT APPLE)
402         CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
403         CHECK_FUNCTION_EXISTS(alloca HAVE_ALLOCA)
404         CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
405         CHECK_INCLUDE_FILE(pthread.h HAVE_LIBPTHREAD)
406
407         if(WITH_XINE)
408             CHECK_MODULE(libxine HAVE_XINE)
409         else()
410             set(HAVE_XINE FALSE)
411         endif()
412         if(WITH_V4L)
413             CHECK_MODULE(libv4l1 HAVE_LIBV4L)
414             CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
415             CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
416         else()
417             set(HAVE_LIBV4L FALSE)
418             set(HAVE_CAMV4L FALSE)
419             set(HAVE_CAMV4L2 FALSE)
420         endif()
421
422         if(ANDROID)
423             set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m log)
424         elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
425             set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} m pthread)
426         else()
427             set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m pthread rt)
428         endif()
429     else()
430         add_definitions(-DHAVE_ALLOCA -DHAVE_ALLOCA_H -DHAVE_LIBPTHREAD -DHAVE_UNISTD_H)
431     endif()
432 endif()
433
434 #################### LATEX for dpf documentation ##################
435 if(BUILD_DOCS)
436   include(cmake/OpenCVFindLATEX.cmake REQUIRED)
437 endif()
438
439 ########################## Python Support #########################
440 include(cmake/OpenCVDetectPython.cmake REQUIRED)
441
442 ########################### Java Support ##########################
443 # current implementation of Java wrappers generator requires python at build time
444 if((NOT DEFINED BUILD_opencv_java OR BUILD_opencv_java) AND PYTHON_EXECUTABLE)
445   if(ANDROID)
446     include(cmake/OpenCVDetectAndroidSDK.cmake REQUIRED)
447     if(NOT ANDROID_TOOLS_Pkg_Revision GREATER 13)
448       message(WARNING "OpenCV requires Android SDK tool revision 14 or newer. Otherwise tests and samples will no be compiled.")
449     endif()
450   endif()
451   include(cmake/OpenCVDetectApacheAnt.cmake REQUIRED)
452
453   if(ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_TOOLS_Pkg_Revision GREATER 13))
454     SET(CAN_BUILD_ANDROID_PROJECTS TRUE)
455   else()
456     SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
457   endif()
458 endif()
459
460 ############################### QT ################################
461 set(HAVE_QT 0)
462 set(HAVE_QT_OPENGL 0)
463
464 if(WITH_QT)
465   find_package(Qt4)
466   if(QT4_FOUND)
467     set(HAVE_QT 1)
468     add_definitions(-DHAVE_QT) #We need to define te macro this way, using cvconfig.h.cmake does not work
469
470     if(WITH_OPENGL)
471       find_package (OpenGL QUIET)
472       if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
473         set(HAVE_OPENGL 1)
474         set(HAVE_QT_OPENGL 1)
475         add_definitions(-DHAVE_QT_OPENGL)
476         set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES})
477       endif()
478     endif()
479   endif()
480 endif()
481
482 ############################### TBB ################################
483 if(WITH_TBB)
484   include(cmake/OpenCVDetectTBB.cmake REQUIRED)
485 endif()
486
487 ############################ Intel IPP #############################
488 set(IPP_FOUND)
489
490 if(WITH_IPP)
491   include(cmake/OpenCVFindIPP.cmake)
492 endif()
493
494 if(IPP_FOUND)
495   add_definitions(-DHAVE_IPP)
496   ocv_include_directories(${IPP_INCLUDE_DIRS})
497   link_directories(${IPP_LIBRARY_DIRS})
498   set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_LIBRARIES})
499 endif()
500
501 ############################### CUDA ################################
502 if(WITH_CUDA)
503   include(cmake/OpenCVDetectCUDA.cmake REQUIRED)
504 endif()
505
506 ############################### OpenNI ################################
507 set(HAVE_OPENNI FALSE)
508 set(HAVE_OPENNI_PRIME_SENSOR_MODULE FALSE)
509
510 if(WITH_OPENNI)
511   include(cmake/OpenCVFindOpenNI.cmake)
512 endif()
513
514 ############################### XIMEA ################################
515 set(HAVE_XIMEA FALSE)
516
517 if(WITH_XIMEA)
518   include(cmake/OpenCVFindXimea.cmake)
519 endif()
520
521 if(XIMEA_FOUND)
522   set(HAVE_XIMEA TRUE)
523 endif()
524
525 ############################## Eigen ##############################
526 if(WITH_EIGEN)
527   find_path(EIGEN_INCLUDE_PATH "Eigen/Core"
528             PATHS "/usr/local/include/eigen2" "/opt/include/eigen2" "/usr/include/eigen2"
529                   "/usr/local/include/eigen3" "/opt/include/eigen3" "/usr/include/eigen3"
530             DOC "The path to Eigen2/Eigen3 headers")
531   if(EIGEN_INCLUDE_PATH)
532     ocv_include_directories(${EIGEN_INCLUDE_PATH})
533     set(HAVE_EIGEN 1)
534   endif()
535 endif()
536
537 ################## Extra HighGUI libs on Windows ###################
538 if(WIN32)
539   set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} comctl32 gdi32 ole32)
540
541   if(WITH_VIDEOINPUT)
542     set(HAVE_VIDEOINPUT 1)
543   endif()
544
545   if(MSVC)
546     set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32)
547   endif()
548
549   if(MINGW)
550     if(MINGW64)
551       set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} msvfw32 avifil32 avicap32 winmm)
552     else()
553       set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32 winmm)
554     endif()
555   endif()
556
557   if(WITH_OPENGL AND NOT HAVE_QT_OPENGL)
558     find_package(OpenGL QUIET)
559
560     if(OPENGL_FOUND)
561       set(HAVE_OPENGL 1)
562       set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES})
563       ocv_include_directories(${OPENGL_INCLUDE_DIR})
564     endif()
565   endif()
566 endif()
567
568
569 # ----------------------------------------------------------------------------
570 # Solution folders:
571 # ----------------------------------------------------------------------------
572 if(ENABLE_SOLUTION_FOLDERS)
573   set_property(GLOBAL PROPERTY USE_FOLDERS ON)
574   set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
575 endif()
576
577 # Extra OpenCV targets: uninstall, package_source, perf, etc.
578 include(cmake/OpenCVExtraTargets.cmake REQUIRED)
579
580
581 # ----------------------------------------------------------------------------
582 # Process subdirectories
583 # ----------------------------------------------------------------------------
584
585 # opencv.hpp and legacy headers
586 add_subdirectory(include)
587
588 # OpenCV modules
589 add_subdirectory(modules)
590
591 # Generate targets for documentation
592 add_subdirectory(doc)
593
594 # various data that is used by cv libraries and/or demo applications.
595 add_subdirectory(data)
596
597 # extra applications
598 add_subdirectory(apps)
599
600 # examples
601 if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES)
602   add_subdirectory(samples)
603 endif()
604
605
606 # ----------------------------------------------------------------------------
607 # Finalization: generate configuration-based files
608 # ----------------------------------------------------------------------------
609 ocv_track_build_dependencies()
610
611 # Generate platform-dependent and configuration-dependent headers
612 include(cmake/OpenCVGenHeaders.cmake REQUIRED)
613
614 # Generate opencv.pc for pkg-config command
615 include(cmake/OpenCVGenPkgconfig.cmake REQUIRED)
616
617 # Generate OpenCV.mk for ndk-build (Android build tool)
618 include(cmake/OpenCVGenAndroidMK.cmake REQUIRED)
619
620 # Generate OpenCVСonfig.cmake and OpenCVConfig-version.cmake for cmake projects
621 include(cmake/OpenCVGenConfig.cmake REQUIRED)
622
623
624 # ----------------------------------------------------------------------------
625 # Summary:
626 # ----------------------------------------------------------------------------
627 status("")
628 status("General configuration for OpenCV ${OPENCV_VERSION} =====================================")
629
630 #build platform
631 status("")
632 status("  Platform:")
633 status("    Host:"             ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR})
634 status("    Target:"           ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR})
635 status("    CMake:"            ${CMAKE_VERSION})
636 status("    CMake generator:"  ${CMAKE_GENERATOR})
637 status("    CMake build tool:" ${CMAKE_BUILD_TOOL})
638 if(MSVC)
639   status("    MSVC:"           ${MSVC_VERSION})
640 endif()
641 if(CMAKE_GENERATOR MATCHES Xcode)
642   status("    Xcode:"          ${XCODE_VERSION})
643 endif()
644
645 # C/C++ options
646 status("")
647 status("  C++:")
648 status("    Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO)
649 status("    C++ Compiler:"           CMAKE_COMPILER    THEN "${CMAKE_COMPILER}" ELSE "${CMAKE_CXX_COMPILER}")
650 status("    C++ flags (Release):"    ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
651 status("    C++ flags (Debug):"      ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
652 if(WIN32)
653   status("    Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
654   status("    Linker flags (Debug):"   ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
655 else()
656   status("    Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
657   status("    Linker flags (Debug):"   ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
658 endif()
659
660 # OpenCV modules
661 status("")
662 status("  OpenCV modules:")
663 string(REPLACE "opencv_" "" OPENCV_MODULES_BUILD_ST          "${OPENCV_MODULES_BUILD}")
664 string(REPLACE "opencv_" "" OPENCV_MODULES_DISABLED_USER_ST  "${OPENCV_MODULES_DISABLED_USER}")
665 string(REPLACE "opencv_" "" OPENCV_MODULES_DISABLED_FORCE_ST "${OPENCV_MODULES_DISABLED_FORCE}")
666 set(OPENCV_MODULES_DISABLED_AUTO_ST "")
667 foreach(m ${OPENCV_MODULES_DISABLED_AUTO})
668   set(__mdeps "")
669   foreach(d ${OPENCV_MODULE_${m}_DEPS})
670     if(d MATCHES "^opencv_" AND NOT HAVE_${d})
671       list(APPEND __mdeps ${d})
672     endif()
673   endforeach()
674   list(APPEND OPENCV_MODULES_DISABLED_AUTO_ST "${m}(deps: ${__mdeps})")
675 endforeach()
676 string(REPLACE "opencv_" "" OPENCV_MODULES_DISABLED_AUTO_ST  "${OPENCV_MODULES_DISABLED_AUTO_ST}")
677
678 status("    To be built:"            OPENCV_MODULES_BUILD          THEN ${OPENCV_MODULES_BUILD_ST}          ELSE "-")
679 status("    Disabled by user:"       OPENCV_MODULES_DISABLED_USER  THEN ${OPENCV_MODULES_DISABLED_USER_ST}  ELSE "-")
680 status("    Disabled by dependency:" OPENCV_MODULES_DISABLED_AUTO  THEN ${OPENCV_MODULES_DISABLED_AUTO_ST}  ELSE "-")
681 status("    Unavailable:"            OPENCV_MODULES_DISABLED_FORCE THEN ${OPENCV_MODULES_DISABLED_FORCE_ST} ELSE "-")
682
683 # Android extra
684 if(ANDROID)
685   status("")
686   status("  Android: ")
687   status("    Android ABI:" ${ANDROID_ABI})
688   status("    Native API level:" android-${ANDROID_NATIVE_API_LEVEL})
689   status("    SDK target:" "${ANDROID_SDK_TARGET}")
690   if(BUILD_WITH_ANDROID_NDK)
691     status("    Android NDK:" "${ANDROID_NDK} (toolchain: ${ANDROID_TOOLCHAIN_NAME})")
692   elseif(BUILD_WITH_STANDALONE_TOOLCHAIN)
693     status("    Android toolchain:" "${ANDROID_STANDALONE_TOOLCHAIN}")
694   endif()
695   status("    android tool:"  ANDROID_EXECUTABLE  THEN "${ANDROID_EXECUTABLE} (${ANDROID_TOOLS_Pkg_Desc})" ELSE NO)
696   status("    ant:"           ANT_EXECUTABLE      THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})"            ELSE NO)
697 endif()
698
699 #YV
700 status("")
701 status("  GUI: ")
702
703 if (HAVE_QT)
704   status("    QT 4.x:"            HAVE_QT        THEN YES ELSE NO)
705   status("    QT OpenGL support:" HAVE_QT_OPENGL THEN YES ELSE NO)
706 else()
707   if(WIN32)
708     status("    Win32 UI:" YES)
709   else()
710     if(APPLE)
711       if(WITH_CARBON)
712         status("    Carbon:" YES)
713       else()
714         status("    Cocoa:"  YES)
715       endif()
716     else()
717       status("    GTK+ 2.x:" HAVE_GTK      THEN YES ELSE NO)
718       status("    GThread :" HAVE_GTHREAD  THEN YES ELSE NO)
719       status("    GtkGlExt:" HAVE_GTKGLEXT THEN YES ELSE NO)
720     endif()
721   endif()
722 endif()
723
724 status("    OpenGL support:" HAVE_OPENGL THEN YES ELSE NO)
725
726 # media
727 status("")
728 status("  Media I/O: ")
729 status("    ZLib:"         ZLIB_FOUND    THEN "${ZLIB_LIBRARY}"    ELSE build)
730
731 if(WITH_JPEG)
732   status("    JPEG:"       JPEG_FOUND    THEN "${JPEG_LIBRARY}"    ELSE build)
733 else()
734   status("    JPEG:"       "NO")
735 endif()
736 if(WITH_PNG)
737   status("    PNG:"        PNG_FOUND     THEN "${PNG_LIBRARY}"     ELSE build)
738 else()
739   status("    PNG:"        "NO")
740 endif()
741 if(WITH_TIFF)
742   status("    TIFF:"       TIFF_FOUND    THEN "${TIFF_LIBRARY}"    ELSE build)
743 else()
744   status("    TIFF:"       "NO")
745 endif()
746 if(WITH_JASPER)
747   status("    JPEG 2000:"  JASPER_FOUND  THEN "${JASPER_LIBRARY}"  ELSE build)
748 else()
749   status("    JPEG 2000:"  "NO")
750 endif()
751
752 status("    OpenEXR:"   WITH_OPENEXR AND OPENEXR_FOUND     THEN YES             ELSE NO)
753 status("    OpenNI:"    HAVE_OPENNI                        THEN YES             ELSE NO)
754 status("    OpenNI PrimeSensor Modules:"
755                         HAVE_OPENNI_PRIME_SENSOR_MODULE    THEN YES             ELSE NO)
756 if(WIN32)
757   status("    XIMEA:"     HAVE_XIMEA  THEN YES ELSE NO)
758 endif()
759
760 # video
761 status("")
762 if(UNIX AND NOT APPLE)
763   status("  Video I/O:")
764   status("    DC1394 1.x:"     HAVE_DC1394         THEN YES ELSE NO)
765   status("    DC1394 2.x:"     HAVE_DC1394_2       THEN YES ELSE NO)
766   status("    FFMPEG:"         HAVE_FFMPEG         THEN YES ELSE NO)
767   status("      codec:"        HAVE_FFMPEG_CODEC   THEN YES ELSE NO)
768   status("      format:"       HAVE_FFMPEG_FORMAT  THEN YES ELSE NO)
769   status("      util:"         HAVE_FFMPEG_UTIL    THEN YES ELSE NO)
770   status("      swscale:"      HAVE_FFMPEG_SWSCALE THEN YES ELSE NO)
771   status("      gentoo-style:" HAVE_GENTOO_FFMPEG  THEN YES ELSE NO)
772   status("    GStreamer:"      HAVE_GSTREAMER      THEN YES ELSE NO)
773   status("    UniCap:"         HAVE_UNICAP         THEN YES ELSE NO)
774   status("    PvAPI:"          HAVE_PVAPI          THEN YES ELSE NO)
775   status("    V4L/V4L2:"       HAVE_LIBV4L         THEN "Using libv4l" ELSE ${HAVE_CAMV4L}/${HAVE_CAMV4L2})
776   status("    Xine:"           HAVE_XINE           THEN YES ELSE NO)
777
778   if(ANDROID)
779     if(HAVE_opencv_androidcamera)
780       status("    AndroidNativeCamera:" BUILD_ANDROID_CAMERA_WRAPPER THEN "YES, build for Android ${ANDROID_VERSION}" ELSE "YES, use prebuilt libraries")
781     else()
782       status("    AndroidNativeCamera:" "NO (native camera requires Android API level 8 or higher)")
783     endif()
784   endif()
785 elseif(APPLE)
786   if(NOT IOS)
787     status("  Video I/O:"    WITH_QUICKTIME      THEN QuickTime ELSE QTKit)
788   else()
789     status("  Video I/O: AVFoundation")
790   endif()
791 elseif(WIN32)
792   status("  Video I/O:"        HAVE_VIDEOINPUT     THEN DirectShow ELSE NO)
793 endif()
794
795 # Other third-party libraries
796 status("")
797 status("  Other third-party libraries:")
798
799 if(WITH_IPP AND IPP_FOUND)
800   status("    Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]")
801   status("         at:" "${IPP_ROOT_DIR}")
802 else()
803   status("    Use IPP:"   WITH_IPP AND NOT IPP_FOUND THEN "IPP not found" ELSE NO)
804 endif()
805
806 status("    Use TBB:"   HAVE_TBB   THEN YES ELSE NO)
807 status("    Use Cuda:"  HAVE_CUDA  THEN YES ELSE NO)
808 status("    Use Eigen:" HAVE_EIGEN THEN YES ELSE NO)
809
810 status("")
811 status("  Python interpreter:"  PYTHON_EXECUTABLE        THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO)
812 # interfaces to other languages
813 status("")
814 status("  Interfaces:")
815 status("    Python:"              HAVE_opencv_python THEN YES ELSE NO)
816 status("    Python numpy:"        PYTHON_USE_NUMPY THEN YES ELSE "NO (Python wrappers can not be generated)")
817 if(ANDROID)
818   status("    Java:" HAVE_opencv_java THEN YES ELSE NO)
819 endif()
820
821 # documentation
822 status("")
823 status("  Documentation:")
824 status("    Sphinx:"              HAVE_SPHINX              THEN "${SPHINX_BUILD} (ver ${SPHINX_VERSION})" ELSE NO)
825 status("    PdfLaTeX compiler:"   PDFLATEX_COMPILER        THEN "${PDFLATEX_COMPILER}" ELSE NO)
826 if(BUILD_DOCS AND HAVE_SPHINX)
827   status("    Build Documentation:" PDFLATEX_COMPILER    THEN YES ELSE "YES (only HTML without math expressions)")
828 else()
829   status("    Build Documentation:" NO)
830 endif()
831
832 # samples and tests
833 status("")
834 status("  Tests and samples:")
835 status("    Tests:"             BUILD_TESTS AND HAVE_opencv_ts       THEN YES ELSE NO)
836 status("    Performance tests:" BUILD_PERF_TESTS AND HAVE_opencv_ts  THEN YES ELSE NO)
837 status("    Examples:"          BUILD_EXAMPLES                       THEN YES ELSE NO)
838
839 if(ANDROID)
840   status("    Android tests:"    BUILD_TESTS AND CAN_BUILD_ANDROID_PROJECTS THEN YES ELSE NO)
841   status("    Android examples:" BUILD_ANDROID_EXAMPLES                     THEN YES ELSE NO)
842 endif()
843
844 #auxiliary
845 status("")
846 status("  Install path:" "${CMAKE_INSTALL_PREFIX}")
847 status("")
848 status("  cvconfig.h is in:" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}")
849 status("-----------------------------------------------------------------")
850 status("")
851
852 # ----------------------------------------------------------------------------
853 # Warn in the case of in-source build
854 # ----------------------------------------------------------------------------
855 if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
856   message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree")
857 endif()
858