fixed cmake status of openni
[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 # Following block can broke build in case of cross-compilng
15 # but CMAKE_CROSSCOMPILING variable will be set only on project(OpenCV) command
16 # so we will try to detect crosscompiling by presense of CMAKE_TOOLCHAIN_FILE
17 if(NOT CMAKE_TOOLCHAIN_FILE)
18     # Add these standard paths to the search paths for FIND_LIBRARY
19     # to find libraries from these locations first
20     if(UNIX)
21         set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib)
22     endif()
23
24     # it _must_ go before PROJECT(OpenCV) in order to work
25     if(WIN32)
26         set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
27     else()
28         set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory")
29     endif()
30
31     if(MSVC)
32         set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)
33     endif()
34 endif(NOT CMAKE_TOOLCHAIN_FILE)
35
36 # --------------------------------------------------------------
37 # Top level OpenCV project
38 # --------------------------------------------------------------
39 cmake_minimum_required(VERSION 2.4)
40 project(OpenCV)
41
42 set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
43 if(DEFINED CMAKE_BUILD_TYPE)
44     set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} )
45 endif()
46
47 set(CMAKE_C_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
48 set(CMAKE_C_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
49 set(CMAKE_CXX_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
50 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
51 set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
52 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
53 set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
54 set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
55 set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
56 set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
57 set(CMAKE_VERBOSE OFF CACHE BOOL "Verbose mode")
58 if(CMAKE_VERBOSE)
59     set(CMAKE_VERBOSE_MAKEFILE 1)
60 endif()
61
62 # --------------------------------------------------------------
63 # Indicate CMake 2.7 and above that we don't want to mix relative
64 #  and absolute paths in linker lib lists.
65 # Run "cmake --help-policy CMP0003" for more information.
66 # --------------------------------------------------------------
67 if(COMMAND cmake_policy)
68     cmake_policy(SET CMP0003 NEW)
69 endif()
70
71 # ----------------------------------------------------------------------------
72 # Build static or dynamic libs?
73 # Default: dynamic libraries
74 # ----------------------------------------------------------------------------
75 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)")
76
77 # ----------------------------------------------------------------------------
78 # Include debug info into debug libs?
79 # Default: yes
80 # ----------------------------------------------------------------------------
81 set(BUILD_WITH_DEBUG_INFO ON CACHE BOOL "Include debug info into debug libs")
82
83 # ----------------------------------------------------------------------------
84 #  Get actual OpenCV version number from sources
85 # ----------------------------------------------------------------------------
86 SET(OPENCV_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/modules/core/include/opencv2/core/version.hpp")
87 FILE(STRINGS "${OPENCV_VERSION_FILE}" OPENCV_VERSION_PARTS REGEX "#define CV_.+OR_VERSION[ ]+[0-9]+" )
88 string(REGEX REPLACE ".+CV_MAJOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MAJOR "${OPENCV_VERSION_PARTS}")
89 string(REGEX REPLACE ".+CV_MINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MINOR "${OPENCV_VERSION_PARTS}")
90 string(REGEX REPLACE ".+CV_SUBMINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_PATCH "${OPENCV_VERSION_PARTS}")
91 set(OPENCV_VERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
92
93 set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}")
94
95 # create a dependency on version file
96 # we will never use output of the following command but cmake will rerun if version file changes
97 configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY)
98
99 if(WIN32)
100     # Postfix of DLLs:
101     set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
102     set(OPENCV_DEBUG_POSTFIX d)
103 else()
104     # Postfix of so's:
105     set(OPENCV_DLLVERSION "")
106     set(OPENCV_DEBUG_POSTFIX)
107 endif()
108
109 #name mangling
110 set(OPENCV_INCLUDE_PREFIX include)
111 if(UNIX AND NOT ANDROID AND BUILD_SHARED_LIBS)
112     option(OPENCV_MANGLED_INSTALL_PATHS "Enables mangled install paths, that help with side by side installs." False)
113     if(OPENCV_MANGLED_INSTALL_PATHS)
114       set(OPENCV_INCLUDE_PREFIX include/opencv-${OPENCV_VERSION})
115     endif()
116 endif()
117
118 # SUBDIRECTORIES:
119 # Save libs and executables in the same place
120 set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Output directory for libraries" )
121 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Output directory for applications" )
122
123 if(ANDROID OR WIN32)
124     set(OPENCV_DOC_INSTALL_PATH doc)
125 elseif(OPENCV_MANGLED_INSTALL_PATHS)
126     set(OPENCV_DOC_INSTALL_PATH share/OpenCV-${OPENCV_VERSION}/doc)
127 else()
128     set(OPENCV_DOC_INSTALL_PATH share/OpenCV/doc)
129 endif()
130
131 if(ANDROID)
132     set(OPENCV_LIB_INSTALL_PATH libs/${ARMEABI_NDK_NAME})
133 else()
134     set(OPENCV_LIB_INSTALL_PATH lib)
135 endif()
136
137 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}")
138 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
139
140 # search packages for host system instead of packages for target system
141 # in case of cross compilation thess macro should be defined by toolchain file
142 if(NOT COMMAND find_host_package)
143     macro(find_host_package)
144         find_package(${ARGN})
145     endmacro()
146 endif()
147 if(NOT COMMAND find_host_program)
148     macro(find_host_program)
149         find_program(${ARGN})
150     endmacro()
151 endif()
152
153 # ----------------------------------------------------------------------------
154 # Use statically or dynamically linked CRT?
155 # Default: dynamic
156 # ----------------------------------------------------------------------------
157 if(WIN32 AND NOT BUILD_SHARED_LIBS)
158   option (BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT" ON)
159 endif()
160   
161 if(MSVC)
162     if(BUILD_WITH_STATIC_CRT)
163         foreach(flag_var
164                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
165                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
166                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
167                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
168            if(${flag_var} MATCHES "/MD")
169               string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
170            endif()
171            if(${flag_var} MATCHES "/MDd")
172               string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
173            endif()
174         endforeach(flag_var)
175         
176         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib")
177         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib")
178         set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib")
179     else(BUILD_WITH_STATIC_CRT)
180         foreach(flag_var
181                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
182                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
183                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
184                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
185            if(${flag_var} MATCHES "/MT")
186               string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
187            endif()
188            if(${flag_var} MATCHES "/MTd")
189               string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}")
190            endif()
191         endforeach(flag_var)
192     endif(BUILD_WITH_STATIC_CRT)
193
194     if(NOT BUILD_WITH_DEBUG_INFO)
195         string(REPLACE "/debug" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
196         string(REPLACE "/DEBUG" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
197         string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
198         string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
199
200         string(REPLACE "/debug" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
201         string(REPLACE "/DEBUG" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
202         string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
203         string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
204
205         string(REPLACE "/debug" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
206         string(REPLACE "/DEBUG" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
207         string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
208         string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
209
210         string(REPLACE "/Zi" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
211         string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
212     endif()
213
214 endif(MSVC)
215
216 # ----------------------------------------------------------------------------
217 #  Variables for cvconfig.h.cmake
218 # ----------------------------------------------------------------------------
219 set(PACKAGE "opencv")
220 set(PACKAGE_BUGREPORT "opencvlibrary-devel@lists.sourceforge.net")
221 set(PACKAGE_NAME "opencv")
222 set(PACKAGE_STRING "${PACKAGE} ${OPENCV_VERSION}")
223 set(PACKAGE_TARNAME "${PACKAGE}")
224 set(PACKAGE_VERSION "${OPENCV_VERSION}")
225
226 # ----------------------------------------------------------------------------
227 #  Autodetect if we are in a SVN repository
228 # ----------------------------------------------------------------------------
229 find_host_program(SVNVERSION_PATH svnversion)
230 mark_as_advanced(force SVNVERSION_PATH)
231 if(SVNVERSION_PATH)
232     message(STATUS "Extracting svn version, please wait...")
233     execute_process(COMMAND ${SVNVERSION_PATH} -n ${OpenCV_SOURCE_DIR} OUTPUT_VARIABLE SVNVERSION_RESULT)
234
235     if(SVNVERSION_RESULT MATCHES "exported")
236         # This is NOT a svn repository:
237         set(OPENCV_SVNVERSION "")
238         message(STATUS "SVNVERSION: exported")
239     else()
240         set(OPENCV_SVNVERSION " svn:${SVNVERSION_RESULT}")
241         message(STATUS "SVNVERSION: ${OPENCV_SVNVERSION}")
242     endif()
243 else()
244     # We don't have svnversion:
245     set(OPENCV_SVNVERSION "")
246 endif()
247
248 # ----------------------------------------------------------------------------
249 # Detect Microsoft compiler:
250 # ----------------------------------------------------------------------------
251 if(CMAKE_CL_64)
252     set(MSVC64 1)
253 endif()
254
255 # ----------------------------------------------------------------------------
256 # Detect GNU version:
257 # ----------------------------------------------------------------------------
258 if(CMAKE_COMPILER_IS_GNUCXX)
259     execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
260                   OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
261                   OUTPUT_STRIP_TRAILING_WHITESPACE)
262     
263     execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
264                   ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
265                   OUTPUT_STRIP_TRAILING_WHITESPACE)           
266         
267     # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
268     # Look for the version number
269     string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
270
271     # Split the three parts:
272     string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
273
274     list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
275     list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
276
277     set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
278     math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
279     message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")
280
281     if(WIN32)
282         execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
283                   OUTPUT_VARIABLE CMAKE_OPENCV_GCC_TARGET_MACHINE
284                   OUTPUT_STRIP_TRAILING_WHITESPACE)
285         if(CMAKE_OPENCV_GCC_TARGET_MACHINE MATCHES "64")
286             set(MINGW64 1)
287         endif()
288     endif()
289 endif()
290
291 # ----------------------------------------------------------------------------
292 # Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
293 #  see  include/opencv/cxtypes.h file for related   ICC & CV_ICC defines.
294 # NOTE: The system needs to determine if the '-fPIC' option needs to be added
295 #  for the 3rdparty static libs being compiled.  The CMakeLists.txt files
296 #  in 3rdparty use the CV_ICC definition being set here to determine if
297 #  the -fPIC flag should be used.
298 # ----------------------------------------------------------------------------
299 if(UNIX)
300     if  (__ICL)
301         set(CV_ICC   __ICL)
302     elseif(__ICC)
303         set(CV_ICC   __ICC)
304     elseif(__ECL)
305         set(CV_ICC   __ECL)
306     elseif(__ECC)
307         set(CV_ICC   __ECC)
308     elseif(__INTEL_COMPILER)
309         set(CV_ICC   __INTEL_COMPILER)
310     elseif(CMAKE_C_COMPILER MATCHES "icc")
311         set(CV_ICC   icc_matches_c_compiler)
312     endif()
313 endif()
314
315 # ----------------------------------------------------------------------------
316 #       CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC..
317 # ----------------------------------------------------------------------------
318
319 # Build/install (or not) some apps:
320 # ===================================================
321 set(BUILD_EXAMPLES OFF CACHE BOOL "Build all examples")
322 set(INSTALL_C_EXAMPLES OFF CACHE BOOL "Install C examples")
323 set(INSTALL_PYTHON_EXAMPLES OFF CACHE BOOL "Install Python examples")
324 if(ANDROID)
325     set(INSTALL_ANDROID_EXAMPLES OFF CACHE BOOL "Install Android examples")
326 endif()
327
328 # Build tests:
329 # ===================================================
330 set(BUILD_TESTS ON CACHE BOOL "Build tests")
331
332 # Build 3rdparty libraries under unix
333 # ===================================================
334 if(WIN32)
335     set(OPENCV_BUILD_3RDPARTY_LIBS TRUE  CACHE BOOL "Build 3rd party libraries")
336 else()
337     set(OPENCV_BUILD_3RDPARTY_LIBS FALSE CACHE BOOL "Build 3rd party libraries")
338 endif()
339
340 include(OpenCVPCHSupport.cmake REQUIRED)
341 include(OpenCVModule.cmake REQUIRED)
342 if(ANDROID)
343     include(OpenCVAndroidProject.cmake REQUIRED)
344 endif()
345
346 if(PCHSupport_FOUND)
347     SET(USE_PRECOMPILED_HEADERS ON CACHE BOOL "Use precompiled headers")
348 else()
349     SET(USE_PRECOMPILED_HEADERS OFF CACHE BOOL "Use precompiled headers" FORCE)
350 endif()
351
352 if(UNIX)
353     include(OpenCVFindPkgConfig.cmake OPTIONAL)
354     include(CheckFunctionExists)
355     include(CheckIncludeFile)
356 endif()
357
358 if(CMAKE_COMPILER_IS_GNUCXX)
359     set(ENABLE_PROFILING OFF CACHE BOOL "Enable profiling in the GCC compiler (Add flags: -g -pg)")
360     set(USE_OMIT_FRAME_POINTER ON CACHE BOOL "Enable -fomit-frame-pointer for GCC")
361
362     if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64.*|x86_64.*)
363         set(X86_64 1)
364     endif()
365     if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686.*|i386.*|x86.*)
366         set(X86 1)
367     endif()
368     if(${CMAKE_SYSTEM_PROCESSOR} MATCHES powerpc.*)
369         set(ENABLE_POWERPC ON CACHE BOOL "Enable PowerPC for GCC")
370     endif ()
371
372     if(X86 OR X86_64)
373         # enable everything, since the available set of instructions is checked at runtime
374         IF ("${CMAKE_GCC_REGEX_VERSION}" VERSION_GREATER 4.5)
375             SET(_USE_FAST_MATH OFF)
376         ELSE()
377             SET(_USE_FAST_MATH ON)
378         ENDIF()
379         set(USE_FAST_MATH ${_USE_FAST_MATH} CACHE BOOL "Enable -ffast-math (not recommended for GCC 4.6.x)")
380         set(ENABLE_SSE ON CACHE BOOL "Enable SSE instructions")
381         set(ENABLE_SSE2 ON CACHE BOOL "Enable SSE2 instructions")
382         set(ENABLE_SSE3 OFF CACHE BOOL "Enable SSE3 instructions")
383         set(ENABLE_SSSE3 OFF CACHE BOOL "Enable SSSE3 instructions")
384         set(ENABLE_SSE41 OFF CACHE BOOL "Enable SSE4.1 instructions")
385         set(ENABLE_SSE42 OFF CACHE BOOL "Enable SSE4.2 instructions")
386     endif()
387 endif()
388
389 if(MSVC)
390     set(ENABLE_SSE ON CACHE BOOL "Enable SSE instructions for MSVC")
391     set(ENABLE_SSE2 ON CACHE BOOL "Enable SSE2 instructions for MSVC")
392     if(CMAKE_C_COMPILER MATCHES "icc")
393         set(ENABLE_SSE3 OFF CACHE BOOL "Enable SSE3 instructions for ICC")
394         set(ENABLE_SSE4_1 OFF CACHE BOOL "Enable SSE4.1 instructions for ICC")
395     endif()
396 endif()
397
398 # allow fine grained control over which libraries not to link, even if
399 # they are available on the system
400 # ====================================================================
401 set(WITH_PNG ON CACHE BOOL "Include PNG support")
402 set(WITH_JPEG ON CACHE BOOL "Include JPEG support")
403 set(WITH_JASPER ON CACHE BOOL "Include JPEG2K support")
404 set(WITH_TIFF ON CACHE BOOL "Include TIFF support")
405 set(WITH_OPENEXR ON CACHE BOOL "Include ILM support via OpenEXR")
406
407 if(UNIX)
408     set(WITH_FFMPEG ON CACHE BOOL "Include FFMPEG support")
409     if(NOT APPLE)
410         set(WITH_UNICAP OFF CACHE BOOL "Include Unicap support (GPL)")
411         set(WITH_GTK ON CACHE BOOL "Include GTK support")
412         set(WITH_GSTREAMER ON CACHE BOOL "Include Gstreamer support")
413         set(WITH_V4L ON CACHE BOOL "Include Video 4 Linux support")
414         set(WITH_XINE OFF CACHE BOOL "Include Xine support (GPL)")
415     endif()
416     set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support")
417     set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support")
418 endif()
419
420 if(APPLE)
421     set(WITH_CARBON OFF CACHE BOOL "Use Carbon for UI instead of Cocoa")
422     set(WITH_QUICKTIME OFF CACHE BOOL "Use QuickTime for Video I/O insted of QTKit")
423 endif()
424
425 set(WITH_TBB OFF CACHE BOOL "Include Intel TBB support")
426 set(WITH_IPP OFF CACHE BOOL "Include Intel IPP support")
427 set(WITH_EIGEN ON CACHE BOOL "Include Eigen2/Eigen3 support")
428 set(WITH_CUDA ON CACHE BOOL "Include NVidia Cuda Runtime support")
429
430 set(WITH_OPENNI OFF CACHE BOOL "Include OpenNI support")
431
432 # ===================================================
433 # Macros that checks if module have been installed.
434 # After it adds module to build and define
435 # constants passed as second arg
436 # ===================================================
437
438 macro(CHECK_MODULE module_name define)
439     set(${define} 0)
440     if(PKG_CONFIG_FOUND)
441         set(ALIAS               ALIASOF_${module_name})
442         set(ALIAS_FOUND                 ${ALIAS}_FOUND)
443         set(ALIAS_INCLUDE_DIRS   ${ALIAS}_INCLUDE_DIRS)
444         set(ALIAS_LIBRARY_DIRS   ${ALIAS}_LIBRARY_DIRS)
445         set(ALIAS_LIBRARIES         ${ALIAS}_LIBRARIES)
446
447         PKG_CHECK_MODULES(${ALIAS} ${module_name})
448
449         if (${ALIAS_FOUND})
450             set(${define} 1)
451             foreach(P "${ALIAS_INCLUDE_DIRS}")
452                 if (${P})
453                     list(APPEND HIGHGUI_INCLUDE_DIRS ${${P}})
454                 endif()
455             endforeach()
456
457             foreach(P "${ALIAS_LIBRARY_DIRS}")
458                 if (${P})
459                     list(APPEND HIGHGUI_LIBRARY_DIRS ${${P}})
460                 endif()
461             endforeach()
462
463             list(APPEND HIGHGUI_LIBRARIES ${${ALIAS_LIBRARIES}})
464         endif()
465     endif()
466 endmacro()
467
468 if(UNIX)
469     if(NOT APPLE)
470       if(WITH_GTK)
471         CHECK_MODULE(gtk+-2.0 HAVE_GTK)
472         CHECK_MODULE(gthread-2.0 HAVE_GTHREAD)
473       else()
474         set(HAVE_GTK FALSE)
475         set(HAVE_GTHREAD FALSE)
476       endif()
477       if(WITH_GSTREAMER)
478         CHECK_MODULE(gstreamer-base-0.10 HAVE_GSTREAMER)
479         CHECK_MODULE(gstreamer-app-0.10 HAVE_GSTREAMER)
480         CHECK_MODULE(gstreamer-video-0.10 HAVE_GSTREAMER)
481       else()
482         set(HAVE_GSTREAMER FALSE)
483       endif()
484     endif()
485
486     if(WITH_UNICAP)
487       CHECK_MODULE(libunicap HAVE_UNICAP_)
488       CHECK_MODULE(libucil HAVE_UNICAP_UCIL)
489       if(HAVE_UNICAP_ AND HAVE_UNICAP_UCIL)
490         set(HAVE_UNICAP 1)
491       endif()
492     else()
493       set(HAVE_UNICAP FALSE)
494     endif()
495
496     if(WITH_PVAPI)
497       find_path(PVAPI_INCLUDE_PATH "PvApi.h"
498                 PATHS "/usr/local/include" "/usr/include"
499                 DOC "The path to PvAPI header")
500       if(PVAPI_INCLUDE_PATH)
501         set(HAVE_PVAPI 1)
502       endif()
503     endif()
504
505     set(HAVE_FFMPEG 0)
506     if(WITH_FFMPEG)
507       CHECK_MODULE(libavcodec HAVE_FFMPEG_CODEC)
508       CHECK_MODULE(libavformat HAVE_FFMPEG_FORMAT)
509       CHECK_MODULE(libavutil HAVE_FFMPEG_UTIL)
510       CHECK_MODULE(libswscale HAVE_FFMPEG_SWSCALE)
511       CHECK_INCLUDE_FILE(libavformat/avformat.h HAVE_GENTOO_FFMPEG)
512       CHECK_INCLUDE_FILE(ffmpeg/avformat.h HAVE_FFMPEG_FFMPEG)
513       if(NOT HAVE_GENTOO_FFMPEG AND NOT HAVE_FFMPEG_FFMPEG)
514         if(EXISTS /usr/include/ffmpeg/libavformat/avformat.h OR HAVE_FFMPEG_SWSCALE)
515           set(HAVE_GENTOO_FFMPEG 1)
516         endif()
517       endif()
518       if(HAVE_FFMPEG_CODEC AND HAVE_FFMPEG_FORMAT AND HAVE_FFMPEG_UTIL)
519         if(HAVE_FFMPEG_SWSCALE OR NOT HAVE_GENTOO_FFMPEG)
520             set(HAVE_FFMPEG 1)
521         endif()
522       endif()
523       # Find the bzip2 library because it is required on some systems
524       FIND_LIBRARY(BZIP2_LIBRARIES NAMES bz2 bzip2)
525       if(NOT BZIP2_LIBRARIES)
526         # Do an other trial
527         FIND_FILE(BZIP2_LIBRARIES NAMES libbz2.so.1 PATHS /lib)
528       endif()
529     endif()
530
531     if(WITH_1394)
532       CHECK_MODULE(libdc1394-2 HAVE_DC1394_2)
533       if(NOT HAVE_DC1394_2)
534         CHECK_MODULE(libdc1394 HAVE_DC1394)
535       endif()
536     else()
537       set(HAVE_DC1394_2 FALSE)
538       set(HAVE_DC1394 FALSE)
539     endif()
540
541     if(NOT OPENCV_BUILD_3RDPARTY_LIBS)
542         include(FindZLIB)
543         if(WITH_PNG)
544             include(FindPNG)
545             if(PNG_FOUND)
546                 CHECK_INCLUDE_FILE(${PNG_PNG_INCLUDE_DIR}/png.h HAVE_PNG_H)
547                 CHECK_INCLUDE_FILE(${PNG_PNG_INCLUDE_DIR}/libpng/png.h HAVE_LIBPNG_PNG_H)
548             endif()
549         else()
550             set(PNG_FOUND FALSE)
551         endif()
552         if(WITH_TIFF)
553             include(FindTIFF)
554         else()
555             set(TIFF_FOUND FALSE)
556         endif()
557         if(WITH_JASPER)
558             include(FindJasper)
559         else()
560             set(JASPER_FOUND FALSE)
561         endif()
562         if(WITH_JPEG)
563             include(FindJPEG)
564         else()
565             set(JPEG_FOUND FALSE)
566         endif()
567     endif()
568
569     if(NOT APPLE)
570         CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
571         CHECK_FUNCTION_EXISTS(alloca HAVE_ALLOCA)
572         CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
573         CHECK_INCLUDE_FILE(pthread.h HAVE_LIBPTHREAD)
574
575         if(WITH_XINE)
576             CHECK_MODULE(libxine HAVE_XINE)
577         else()
578             set(HAVE_XINE FALSE)
579         endif()
580         if(WITH_V4L)
581             CHECK_MODULE(libv4l1 HAVE_LIBV4L)
582             CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
583             CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
584         else()
585             set(HAVE_LIBV4L FALSE)
586             set(HAVE_CAMV4L FALSE)
587             set(HAVE_CAMV4L2 FALSE)
588         endif()
589
590         if(ANDROID)
591             set(OPENCV_LINKER_LIBS dl m log)
592         elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
593             set(OPENCV_LINKER_LIBS m pthread)
594         else()
595             set(OPENCV_LINKER_LIBS dl m pthread rt)
596         endif()
597     else()
598         add_definitions(-DHAVE_ALLOCA -DHAVE_ALLOCA_H -DHAVE_LIBPTHREAD -DHAVE_UNISTD_H)
599     endif()
600 endif()
601
602 if(WITH_PNG AND NOT PNG_FOUND)
603     set(PNG_LIBRARIES libpng)
604 endif()
605
606 if(WITH_JPEG AND NOT JPEG_FOUND)
607     set(JPEG_LIBRARIES libjpeg)
608 endif()
609
610 if(WITH_TIFF AND NOT TIFF_FOUND)
611     set(TIFF_LIBRARIES libtiff)
612 endif()
613
614 if(WITH_JASPER AND NOT JASPER_FOUND)
615     set(JASPER_LIBRARIES libjasper)
616 endif()
617
618 if(NOT ZLIB_FOUND)
619     set(ZLIB_LIBRARY zlib)
620 endif()
621
622 #message(STATUS "Graphic libraries: ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${JASPER_LIBRARIES}")
623
624 if(WITH_OPENEXR)
625     include(OpenCVFindOpenEXR.cmake)
626 endif()
627
628 set(BUILD_DOCS ON CACHE BOOL "Build OpenCV Documentation")
629
630 if(BUILD_DOCS)
631   include(OpenCVFindLATEX.cmake REQUIRED)
632 endif()
633
634 set(BUILD_NEW_PYTHON_SUPPORT ON CACHE BOOL "Build with Python support")
635
636 if (WIN32)
637     if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
638         set(BUILD_NEW_PYTHON_SUPPORT OFF)
639     endif()
640 endif()
641
642 if(ANDROID)
643     set(BUILD_NEW_PYTHON_SUPPORT OFF)
644 endif()
645
646 # Always try to find python
647 # ===================================================
648 find_host_package(PythonInterp)
649 find_host_package(PythonLibs)
650
651 # cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND
652 if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH)
653     set(PYTHONLIBS_FOUND ON)
654 endif()
655
656 execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
657       ERROR_VARIABLE PYTHON_VERSION_FULL
658       OUTPUT_STRIP_TRAILING_WHITESPACE)
659
660 string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
661 if(CMAKE_HOST_UNIX)
662     execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()"
663                     RESULT_VARIABLE PYTHON_CVPY_PROCESS
664                     OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH
665                     OUTPUT_STRIP_TRAILING_WHITESPACE)
666     if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages")
667         set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages CACHE PATH "Where to install the python packages.")
668     else() #debian based assumed, install to the dist-packages.
669         set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages CACHE PATH "Where to install the python packages.")
670     endif()
671 endif()
672 if(CMAKE_HOST_WIN32)
673     get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE CACHE)
674     set(PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages")
675 endif()
676
677 IF ("${PYTHON_VERSION_MAJOR_MINOR}" VERSION_GREATER 2.4)
678     SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} -B)
679 ENDIF()
680
681 # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
682 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]"
683             RESULT_VARIABLE PYTHON_NUMPY_PROCESS
684             OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS
685             OUTPUT_STRIP_TRAILING_WHITESPACE)
686
687 if(PYTHON_NUMPY_PROCESS EQUAL 0)
688     set(PYTHON_USE_NUMPY 1)
689     add_definitions(-D PYTHON_USE_NUMPY=1)
690     include_directories(AFTER ${PYTHON_NUMPY_INCLUDE_DIRS})
691     message(STATUS "    Use NumPy headers from: ${PYTHON_NUMPY_INCLUDE_DIRS}")
692 else()
693     set(PYTHON_USE_NUMPY 0)
694 endif()
695
696 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sphinx; print sphinx.__version__"
697             RESULT_VARIABLE SPHINX_PROCESS
698             OUTPUT_VARIABLE SPHINX_VERSION
699             OUTPUT_STRIP_TRAILING_WHITESPACE)
700
701 set(HAVE_SPHINX 0)
702 if(SPHINX_PROCESS EQUAL 0)
703     find_host_program(SPHINX_BUILD sphinx-build)
704     if(SPHINX_BUILD)
705         set(HAVE_SPHINX 1)
706         message(STATUS "    Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
707     endif()
708 endif()
709
710 # Java support
711 # ===================================================
712 if (PYTHON_EXECUTABLE AND ANDROID AND ANDROID_API_LEVEL GREATER 7)
713     option(BUILD_JAVA_SUPPORT "Build with Java support" TRUE)
714 endif()
715
716 if (BUILD_JAVA_SUPPORT)
717     file(TO_CMAKE_PATH "$ENV{ANT_DIR}" ANT_DIR_ENV_PATH)
718     file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH)
719
720     if(ANDROID)
721         file(TO_CMAKE_PATH "$ENV{ANDROID_SDK}" ANDROID_SDK_ENV_PATH)
722         
723         #find android SDK
724         find_host_program(ANDROID_EXECUTABLE
725             NAMES android.bat android
726             PATHS "${ANDROID_SDK_ENV_PATH}/tools/"
727                   "${ProgramFiles_ENV_PATH}/Android/android-sdk/tools/"
728                   "/opt/android-sdk/tools/"
729                   "/opt/android-sdk-linux_x86/tools/"
730                   "/opt/android-sdk-mac_x86/tools/"
731                   "/opt/android-sdk-linux_86/tools/"
732                   "/opt/android-sdk-mac_86/tools/"
733             )
734         if(ANDROID_EXECUTABLE)
735             message(STATUS "    Found android tool: ${ANDROID_EXECUTABLE}")
736
737             get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH)
738
739             #read source.properties
740             if (EXISTS "${ANDROID_SDK_TOOLS_PATH}/source.properties")
741                 file(STRINGS "${ANDROID_SDK_TOOLS_PATH}/source.properties" ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$")
742                 foreach(line ${ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES})
743                     string(REPLACE "\\:" ":" line ${line})
744                     string(REPLACE "=" ";" line ${line})
745                     list(GET line 0 line_name)
746                     list(GET line 1 line_value)
747                     string(REPLACE "." "_" line_name ${line_name})
748                     SET(ANDROID_TOOLS_${line_name} "${line_value}")
749                     MARK_AS_ADVANCED(ANDROID_TOOLS_${line_name})
750                 endforeach()
751             endif()
752             if (NOT ANDROID_TOOLS_Pkg_Revision)
753                 SET(ANDROID_TOOLS_Pkg_Revision "Unknown")
754                 MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Revision)
755             endif()
756             if (NOT ANDROID_TOOLS_Pkg_Desc)
757                 SET(ANDROID_TOOLS_Pkg_Desc "Android SDK Tools, revision ${ANDROID_TOOLS_Pkg_Revision}.")
758                 if (NOT ANDROID_TOOLS_Pkg_Revision GREATER 11)
759                     SET(ANDROID_TOOLS_Pkg_Desc "${ANDROID_TOOLS_Pkg_Desc} It is recommended to update your SDK tools to revision 12 or newer.")
760                 endif()
761                 MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Desc)
762             endif()
763
764             #get installed targets
765             execute_process(COMMAND ${ANDROID_EXECUTABLE} list target
766                 RESULT_VARIABLE ANDROID_PROCESS
767                 OUTPUT_VARIABLE ANDROID_SDK_TARGETS_FULL
768                 ERROR_VARIABLE ANDROID_PROCESS_ERRORS
769                 OUTPUT_STRIP_TRAILING_WHITESPACE)
770             string(REGEX MATCHALL "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" ANDROID_SDK_TARGETS_FULL "${ANDROID_SDK_TARGETS_FULL}")
771
772             SET(ANDROID_SDK_TARGETS)
773             if (ANDROID_PROCESS EQUAL 0)
774                 foreach(line ${ANDROID_SDK_TARGETS_FULL})
775                     string(REGEX REPLACE "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" "\\2" line "${line}")
776                     list(APPEND ANDROID_SDK_TARGETS "${line}")
777                 endforeach()
778             endif()
779
780             # detect ANDROID_SDK_TARGET if no target is provided by user
781             if (NOT ANDROID_SDK_TARGET)
782                 set(desired_android_target_level ${ANDROID_API_LEVEL})
783                 if (desired_android_target_level LESS 8)
784                     set(desired_android_target_level 8)
785                 endif()
786                 if (ANDROID_PROCESS EQUAL 0)
787                     math(EXPR desired_android_target_level_1 "${desired_android_target_level}-1")
788
789                     foreach(target ${ANDROID_SDK_TARGETS})
790                         string(REGEX MATCH "[0-9]+$" target_level "${target}")
791                         if (target_level GREATER desired_android_target_level_1)
792                            set(ANDROID_SDK_TARGET "${target}")
793                            break()
794                         endif()
795                     endforeach()
796                 else()
797                     set(ANDROID_SDK_TARGET android-${desired_android_target_level})
798                     message(WARNING "Could not retrieve list of installed Android targets. Will try to use \"${ANDROID_SDK_TARGET}\" target")
799                 endif()
800             endif()
801
802             SET(ANDROID_SDK_TARGET ${ANDROID_SDK_TARGET} CACHE STRING "SDK target for Android tests and samples")
803             if (ANDROID_PROCESS EQUAL 0)
804                 set_property( CACHE ANDROID_SDK_TARGET PROPERTY STRINGS ${ANDROID_SDK_TARGETS} )
805             endif()
806             string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}")
807         endif()
808     endif()
809
810     #find apache ant
811     find_host_program(ANT_EXECUTABLE NAMES ant.bat ant
812         PATHS "${ANT_DIR_ENV_PATH}/bin"
813               "${ProgramFiles_ENV_PATH}/apache-ant/bin"
814         )
815     if(ANT_EXECUTABLE)
816         execute_process(COMMAND ${ANT_EXECUTABLE} -version
817             OUTPUT_VARIABLE ANT_VERSION_FULL
818             OUTPUT_STRIP_TRAILING_WHITESPACE)
819         string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" ANT_VERSION "${ANT_VERSION_FULL}")
820
821         message(STATUS "    Found apache ant ${ANT_VERSION}: ${ANT_EXECUTABLE}")
822     endif()
823
824     if (ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_SDK_TARGET_LEVEL GREATER 7))
825         SET(CAN_BUILD_ANDROID_PROJECTS TRUE)
826     else()
827         SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
828     endif()
829 endif()
830
831 if(CAN_BUILD_ANDROID_PROJECTS)
832     SET(BUILD_ANDROID_EXAMPLES TRUE CACHE BOOL "Build examples for Android platform")
833 endif()
834
835 #YV
836 ############################### QT ################################
837
838 set(WITH_QT OFF CACHE BOOL "Build with Qt Backend support")
839 set(WITH_QT_OPENGL OFF CACHE BOOL "Add OpenGL extension to Qt")
840
841 set(HAVE_QT 0)
842 set(HAVE_QT_OPENGL 0)
843
844 if (WITH_QT)
845     find_package(Qt4)
846     if (QT4_FOUND)
847         set(HAVE_QT 1)
848         add_definitions(-DHAVE_QT)#We need to define te macro this way, using cvconfig.h.cmake does not work
849         find_package (OpenGL QUIET)
850
851         #if (NOT WIN32)
852         if (WITH_QT_OPENGL)
853             if (QT_QTOPENGL_FOUND AND OPENGL_FOUND)
854                 set(HAVE_QT_OPENGL 1)
855                 add_definitions(-DHAVE_QT_OPENGL)
856                 #link_directories("${OPENGL_LIBRARIES}")
857                 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES})
858             endif()
859         endif()
860         #endif()
861     endif()
862 endif()
863
864 ############################### TBB ################################
865
866 if (WITH_TBB)
867     if (UNIX AND NOT APPLE AND NOT ANDROID)
868         PKG_CHECK_MODULES(TBB tbb)
869
870         if (TBB_FOUND)
871             set(HAVE_TBB 1)
872             if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "")
873                 include_directories(${TBB_INCLUDE_DIRS})
874             endif()
875             link_directories(${TBB_LIBRARY_DIRS})
876             set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES})        
877         endif()
878     endif()    
879     
880     if (NOT HAVE_TBB)
881         set(TBB_DEFAULT_INCLUDE_DIRS "/opt/intel/tbb" "/usr/local/include" "/usr/include" "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB" "C:/Program Files (x86)/TBB" "${CMAKE_INSTALL_PREFIX}/include")
882         
883         find_path(TBB_INCLUDE_DIR "tbb/tbb.h" PATHS ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers")
884         if (TBB_INCLUDE_DIR)
885             if (UNIX)
886                 set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory")
887                 link_directories("${TBB_LIB_DIR}")
888             endif()
889             if (APPLE)
890                 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib)
891             elseif (ANDROID)
892                 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbbmalloc tbb)
893                 add_definitions(-DTBB_USE_GCC_BUILTINS)
894             elseif (UNIX)
895                 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
896             elseif (WIN32)
897                 if (CMAKE_COMPILER_IS_GNUCXX)
898                     set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory")
899                     link_directories("${TBB_LIB_DIR}")
900                     set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
901                 else()
902                     get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIR}/../lib" ABSOLUTE)                          
903                    
904                     if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*|x86_64* OR MSVC64)
905                         set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/intel64")
906                     elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86*|i386*|i686*)
907                         set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/ia32")
908                     endif()
909
910                     if (MSVC80)
911                        set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8")
912                     elseif(MSVC90)
913                        set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9")                    
914                     elseif(MSVC10)
915                         set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10")
916                     endif()
917                     set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory")
918                     link_directories("${TBB_LIB_DIR}")
919                 endif()
920             endif()
921
922             set(HAVE_TBB 1)
923             if(NOT "${TBB_INCLUDE_DIR}" STREQUAL "")
924                 include_directories("${TBB_INCLUDE_DIR}")
925             endif()
926         endif()
927     endif()
928 endif(WITH_TBB)
929
930 #Threading Framework -- temporary decision for ARM-s instead of TBB
931 if (NOT HAVE_TBB)
932     file(GLOB THREADING_FRAMEWORK_HEADER "${OpenCV_SOURCE_DIR}/modules/core/include/opencv2/core/threading_framework.hpp")
933     file(GLOB THREADING_FRAMEWORK_SOURCE "${OpenCV_SOURCE_DIR}/modules/core/src/threading_framework.cpp")
934     if(THREADING_FRAMEWORK_HEADER AND THREADING_FRAMEWORK_SOURCE)
935         set(HAVE_THREADING_FRAMEWORK 1)
936     endif()
937 endif()
938
939 ############################ Intel IPP #############################
940 set(IPP_FOUND)
941
942 if(WITH_IPP)
943     include(OpenCVFindIPP.cmake)
944 endif()
945
946 if(IPP_FOUND)
947     add_definitions(-DHAVE_IPP)
948     include_directories(${IPP_INCLUDE_DIRS})
949     link_directories(${IPP_LIBRARY_DIRS})
950     set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_LIBRARIES})
951 endif()
952
953
954 ############################### CUDA ################################
955
956 if(WITH_CUDA)
957     find_package(CUDA 4.0)
958     
959     if(CUDA_FOUND)
960         set(HAVE_CUDA 1)
961         message(STATUS "CUDA detected: " ${CUDA_VERSION})
962
963         set(CUDA_ARCH_BIN "1.1 1.2 1.3 2.0 2.1(2.0)" CACHE STRING "Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported")
964         set(CUDA_ARCH_PTX "2.0" CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for")
965         
966         string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}")
967         string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}")
968         
969         # Ckeck if user specified 1.0 compute capability: we don't support it
970         string(REGEX MATCH "1.0" HAS_ARCH_10 "${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}")
971         set(CUDA_ARCH_BIN_OR_PTX_10 0)
972         if(NOT ${HAS_ARCH_10} STREQUAL "")
973             set(CUDA_ARCH_BIN_OR_PTX_10 1)
974         endif()
975         
976         # NVCC flags to be set
977         set(NVCC_FLAGS_EXTRA "")      
978         
979         # These vars will be passed into the templates
980         set(OPENCV_CUDA_ARCH_BIN "") 
981         set(OPENCV_CUDA_ARCH_PTX "") 
982         set(OPENCV_CUDA_ARCH_FEATURES "")        
983         
984         # Tell NVCC to add binaries for the specified GPUs
985         string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}")
986         foreach(ARCH IN LISTS ARCH_LIST)
987             if (ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
988                 # User explicitly specified PTX for the concrete BIN
989                 set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
990                 set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}")
991                 set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}")
992             else()
993                 # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN                
994                 set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=sm_${ARCH})
995                 set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}")
996                 set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
997             endif()
998         endforeach()
999         
1000         # Tell NVCC to add PTX intermediate code for the specified architectures
1001         string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}")
1002         foreach(ARCH IN LISTS ARCH_LIST)
1003             set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=compute_${ARCH})
1004             set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}")
1005             set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
1006         endforeach()
1007         
1008         # These vars will be processed in other scripts
1009         set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA})        
1010         set(OpenCV_CUDA_CC "${NVCC_FLAGS_EXTRA}")
1011         
1012         message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
1013     else()
1014         unset(CUDA_ARCH_BIN CACHE)
1015         unset(CUDA_ARCH_PTX CACHE)  
1016     endif() 
1017 endif()
1018
1019
1020 ############################### OpenNI ################################
1021 set(HAVE_OPENNI FALSE)
1022 set(HAVE_OPENNI_PRIME_SENSOR_MODULE FALSE)
1023
1024 if(WITH_OPENNI)
1025     include(OpenCVFindOpenNI.cmake)
1026 endif()
1027
1028 ############################## Eigen ##############################
1029
1030 if(WITH_EIGEN)
1031     find_path(EIGEN_INCLUDE_PATH "Eigen/Core"
1032             PATHS "/usr/local/include/eigen2" "/opt/include/eigen2" "/usr/include/eigen2"
1033             "/usr/local/include/eigen3" "/opt/include/eigen3" "/usr/include/eigen3"
1034             DOC "The path to Eigen2/Eigen3 headers")
1035     if(EIGEN_INCLUDE_PATH)
1036         include_directories(${EIGEN_INCLUDE_PATH})
1037         set(HAVE_EIGEN 1)
1038     endif()
1039 endif()
1040
1041
1042 ################## Extra HighGUI libs on Windows ###################
1043
1044 if(WIN32)
1045     set(WITH_VIDEOINPUT ON CACHE BOOL "Build HighGUI with DirectShow support")
1046     set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} comctl32 gdi32 ole32)
1047
1048     if(WITH_VIDEOINPUT)
1049         set(HAVE_VIDEOINPUT 1)
1050     endif()
1051     
1052     if (MSVC)
1053         set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32)
1054     endif()
1055
1056     if(MINGW)
1057         if(MINGW64)
1058             set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} msvfw32 avifil32 avicap32 winmm)
1059         else()
1060             set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32 winmm)
1061         endif()  
1062     endif()
1063 endif()
1064
1065 ############## Android source tree for native camera ###############
1066 if(ANDROID AND ANDROID_API_LEVEL GREATER 7)
1067     option(WITH_ANDROID_CAMERA "Build with native Android camera support" TRUE)
1068
1069     SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH 
1070 "Path to Android source tree.
1071 Set this variable to path to your Android sources to compile
1072 libnative_camera_rx.x.x.so for your Android")
1073     SET(BUILD_ANDROID_CAMERA_WRAPPER OFF)
1074     if (ANDROID_SOURCE_TREE)
1075         FILE(STRINGS "${ANDROID_SOURCE_TREE}/development/sdk/platform_source.properties" ANDROID_VERSION REGEX "Platform\\.Version=[0-9]+\\.[0-9]+\\.[0-9]+" )
1076         string(REGEX REPLACE "Platform\\.Version=([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" ANDROID_VERSION "${ANDROID_VERSION}")
1077         if(NOT "${ANDROID_VERSION}" STREQUAL "")
1078             SET(BUILD_ANDROID_CAMERA_WRAPPER ON)
1079         endif()
1080     endif()
1081     MARK_AS_ADVANCED(ANDROID_SOURCE_TREE)
1082 endif()
1083
1084 # ----------------------------------------------------------------------------
1085 #                   UPDATE CONFIG FILES & SCRIPTS:
1086 #
1087 #  CONFIGURE_FILE(InputFile OutputFile [COPYONLY] [ESCAPE_QUOTES] [@ONLY])
1088 #  If @ONLY is specified, only variables of the form @VAR@ will be
1089 #  replaces and ${VAR} will be ignored.
1090 #
1091 #  A directory will be created for each platform so the "cvconfig.h" file is
1092 #  not overwritten if cmake generates code in the same path.
1093 # ----------------------------------------------------------------------------
1094 add_definitions(-DHAVE_CVCONFIG_H)
1095
1096 set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h")
1097
1098 message(STATUS "Parsing 'cvconfig.h.cmake'")
1099 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cvconfig.h.cmake" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h")
1100
1101 # ---------------------------------------------------------------------------
1102 # The C+//0 include & link directories:
1103 # ---------------------------------------------------------------------------
1104 include_directories("."
1105     "${OPENCV_CONFIG_FILE_INCLUDE_DIR}"
1106     "${CMAKE_CURRENT_SOURCE_DIR}/include"
1107     "${CMAKE_CURRENT_SOURCE_DIR}/include/opencv"
1108     )
1109
1110 # ----------------------------------------------------------------------------
1111 #           Set the maximum level of warnings:
1112 # ----------------------------------------------------------------------------
1113 # Should be set to true for development
1114 set(OPENCV_WARNINGS_ARE_ERRORS OFF CACHE BOOL "Treat warnings as errors")
1115 if (WIN32 AND ${CMAKE_GENERATOR} MATCHES "(MinGW)|(MSYS)")
1116     set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "")
1117 endif()
1118
1119 set(EXTRA_C_FLAGS "")
1120 set(EXTRA_C_FLAGS_RELEASE "")
1121 set(EXTRA_C_FLAGS_DEBUG "")
1122 set(EXTRA_EXE_LINKER_FLAGS "")
1123 set(EXTRA_EXE_LINKER_FLAGS_RELEASE "")
1124 set(EXTRA_EXE_LINKER_FLAGS_DEBUG "")
1125
1126 if(MSVC)
1127     set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS")
1128     # 64-bit portability warnings, in MSVC8
1129     if(MSVC80)
1130         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /Wp64")
1131     endif()
1132     #if(MSVC90)
1133     #    set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /D _BIND_TO_CURRENT_CRT_VERSION=1 /D _BIND_TO_CURRENT_VCLIBS_VERSION=1")
1134     #endif()
1135
1136     if(BUILD_WITH_DEBUG_INFO)
1137         set(EXTRA_EXE_LINKER_FLAGS_RELEASE "${EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug")
1138     endif()
1139
1140     # Remove unreferenced functions: function level linking
1141     set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /Gy")
1142     if(BUILD_WITH_DEBUG_INFO)
1143        set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /Zi")
1144     endif()
1145 endif()
1146
1147 if(CMAKE_COMPILER_IS_GNUCXX)
1148     # High level of warnings.
1149     set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
1150
1151     # The -Wno-long-long is required in 64bit systems when including sytem headers.
1152     if(X86_64)
1153         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long")
1154     endif()
1155
1156     # We need pthread's
1157     if(UNIX AND NOT ANDROID)
1158         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -pthread")
1159     endif()
1160
1161     if(OPENCV_WARNINGS_ARE_ERRORS)
1162         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
1163     endif()
1164
1165     if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE)
1166         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -march=i686")
1167     endif()
1168
1169     # Other optimizations
1170     if(USE_OMIT_FRAME_POINTER)
1171         set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
1172     endif()
1173     if(USE_FAST_MATH)
1174         set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
1175     endif()
1176     if(ENABLE_POWERPC)
1177         set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
1178     endif()
1179     if(ENABLE_SSE)
1180         set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse")
1181     endif()
1182     if(ENABLE_SSE2)
1183         set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse2")
1184     endif()
1185     # SSE3 and further should be disabled under MingW because it generates compiler errors
1186     if(NOT MINGW)
1187         if(ENABLE_SSE3)
1188             set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse3")
1189         endif()
1190         
1191         if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402)
1192             set(HAVE_GCC43_OR_NEWER 1)
1193         endif()
1194         if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401)
1195             set(HAVE_GCC42_OR_NEWER 1)
1196         endif()
1197         
1198         if(HAVE_GCC42_OR_NEWER OR APPLE)
1199             if(ENABLE_SSSE3)
1200                 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mssse3")
1201             endif()
1202             if(HAVE_GCC43_OR_NEWER)
1203                 if(ENABLE_SSE41)
1204                     set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse4.1")
1205                 endif()
1206                 if(ENABLE_SSE42)
1207                     set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse4.2")
1208                 endif()
1209             endif()
1210         endif()
1211     endif()
1212
1213     if(X86 OR X86_64)
1214         if(NOT APPLE AND ${CMAKE_SIZEOF_VOID_P} EQUAL 4)
1215             set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mfpmath=387")
1216         endif()
1217     endif()
1218
1219     # Profiling?
1220     if(ENABLE_PROFILING)
1221         set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
1222     elseif(NOT APPLE)
1223         # Remove unreferenced functions: function level linking
1224         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
1225     endif()
1226
1227     set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -DNDEBUG")
1228     set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG")
1229     if(BUILD_WITH_DEBUG_INFO)
1230        set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -ggdb3")
1231     endif()
1232 endif()
1233
1234 if(MSVC)
1235     # 64-bit MSVC compiler uses SSE/SSE2 by default
1236     if(NOT MSVC64)
1237        if(ENABLE_SSE)
1238           set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE")
1239        endif()
1240        if(ENABLE_SSE2)
1241           set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE2")
1242        endif()
1243     endif()
1244     if(ENABLE_SSE3)
1245        set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE3")
1246     endif()
1247     if(ENABLE_SSE4_1)
1248        set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1")
1249     endif()
1250     if (ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1)
1251        set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /Oi")
1252     endif()
1253 endif()
1254
1255 # Extra link libs if the user selects building static libs:
1256 if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
1257     # Android does not need these settings because they are already set by toolchain file
1258     set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)
1259     set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}")
1260 endif()
1261
1262 # Add user supplied extra options (optimization, etc...)
1263 # ==========================================================
1264 set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS}" CACHE STRING "Extra compiler options")
1265 set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE}" CACHE STRING "Extra compiler options for Release build")
1266 set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG}" CACHE STRING "Extra compiler options for Debug build")
1267 set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}" CACHE STRING "Extra linker flags" FORCE)
1268 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Extra linker flags for Release build" FORCE)
1269 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "Extra linker flags for Debug build" FORCE)
1270
1271 #combine all "extra" options
1272 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
1273 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
1274 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}")
1275 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}")
1276 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}")
1277 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}")
1278 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_FLAGS}")
1279 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${EXTRA_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}")
1280 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${EXTRA_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}")
1281
1282 # In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release:
1283 if (${CMAKE_GENERATOR} MATCHES ".*Makefiles" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
1284     set(CMAKE_BUILD_TYPE Release)
1285 endif()
1286
1287 if (WIN32 AND MSVC)
1288     # avoid warnings from MSVC about overriding the /W* option
1289     # we replace /W3 with /W4 only for C++ files,
1290     # since all the 3rd-party libraries OpenCV uses are in C,
1291     # and we do not care about their warnings.
1292     string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1293     string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
1294     string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
1295
1296     # allow extern "C" functions throw exceptions
1297     string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1298     string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
1299     string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
1300     string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1301     string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
1302     string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
1303
1304     string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1305     string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1306 endif()
1307
1308 if("${CMAKE_CONFIGURE_LDFLAGS}")
1309     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CONFIGURE_LDFLAGS}")
1310 endif("${CMAKE_CONFIGURE_LDFLAGS}")
1311
1312 # --------------------------------------------------------------------------------------------
1313 #  Installation for CMake Module:  OpenCVConfig.cmake
1314 #  Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake              -> For use *without* "make install"
1315 #  Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use with "make install"
1316 #  Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake  -> For use within binary installers/packages
1317 # -------------------------------------------------------------------------------------------
1318
1319 # -------------------------------------------------------------------------------------------
1320 #  Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake              -> For use *without* "make install"
1321 # -------------------------------------------------------------------------------------------
1322 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"")
1323 set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "${CMAKE_CURRENT_SOURCE_DIR}")
1324 set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}")
1325 set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1326
1327 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)
1328 #support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
1329 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
1330 # --------------------------------------------------------------------------------------------
1331 #  Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
1332 # -------------------------------------------------------------------------------------------
1333 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"")
1334
1335 set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "")
1336 if(ANDROID)
1337     set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ARMEABI_NDK_NAME}\"")
1338     set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ARMEABI_NDK_NAME}\"")
1339 else()
1340     set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
1341     set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1342     if(OPENCV_MANGLED_INSTALL_PATHS)
1343       set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV-${OPENCV_VERSION}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1344     endif()
1345 endif()
1346
1347 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
1348 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
1349
1350 if(UNIX)
1351   #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference
1352   # For a command "find_package(<name> [major[.minor]] [EXACT] [REQUIRED|QUIET])"
1353   # cmake will look in the following dir on unix:
1354   #                <prefix>/(share|lib)/cmake/<name>*/                     (U)
1355   #                <prefix>/(share|lib)/<name>*/                           (U)
1356   #                <prefix>/(share|lib)/<name>*/(cmake|CMake)/             (U)
1357   if(OPENCV_MANGLED_INSTALL_PATHS)
1358     install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/)
1359     install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/)
1360   else()
1361     install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION share/OpenCV/)
1362     install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV/)
1363   endif()
1364 endif()
1365
1366 if(ANDROID)
1367     install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV)
1368 endif()
1369
1370 # --------------------------------------------------------------------------------------------
1371 #  Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake  -> For use within binary installers/packages
1372 # -------------------------------------------------------------------------------------------
1373 if(WIN32)
1374     set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
1375     set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "")
1376     set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
1377     set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1378
1379     exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
1380     configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
1381
1382     # Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory 
1383     install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/") 
1384 endif()
1385
1386 # --------------------------------------------------------------------------------------------
1387 #  Installation for Android ndk-build makefile:  OpenCV.mk
1388 #  Part 1/2: ${BIN_DIR}/OpenCV.mk              -> For use *without* "make install"
1389 #  Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install"
1390 # -------------------------------------------------------------------------------------------
1391 if(ANDROID)
1392     if(BUILD_SHARED_LIBS)
1393         SET(OPENCV_LIBTYPE_CONFIGMAKE "SHARED")
1394     else()
1395         SET(OPENCV_LIBTYPE_CONFIGMAKE "STATIC")
1396     endif()
1397     if(BUILD_ANDROID_CAMERA_WRAPPER)
1398         set(CMAKE_CAMERA_LIBS_CONFIGCMAKE "native_camera_r${ANDROID_VERSION}")
1399     elseif(WITH_ANDROID_CAMERA)
1400         SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "")
1401         file(GLOB CMAKE_CAMERA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lib/${ARMEABI_NDK_NAME}/libnative_camera_r*.so")
1402         foreach(cam_lib ${CMAKE_CAMERA_LIBS})
1403             get_filename_component(cam_lib "${cam_lib}" NAME)
1404             string(REGEX REPLACE "lib(native_camera_r[0-9]+\\.[0-9]+\\.[0-9]+)\\.so" "\\1" cam_lib "${cam_lib}")
1405             SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "${CMAKE_CAMERA_LIBS_CONFIGCMAKE} ${cam_lib}")
1406         endforeach()
1407     endif()
1408 endif(ANDROID)
1409
1410 # -------------------------------------------------------------------------------------------
1411 #  Part 1/2: ${BIN_DIR}/OpenCV.mk              -> For use *without* "make install"
1412 # -------------------------------------------------------------------------------------------
1413 if(ANDROID)
1414     set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"")
1415     set(CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE "\"${CMAKE_CURRENT_SOURCE_DIR}\"")
1416     set(CMAKE_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)")
1417
1418     configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY)
1419 endif(ANDROID)
1420
1421 # -------------------------------------------------------------------------------------------
1422 #  Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install"
1423 # -------------------------------------------------------------------------------------------
1424 if(ANDROID)
1425     set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include/opencv\" \"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include\"")
1426     set(CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE "")
1427     set(CMAKE_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../..")
1428
1429     configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY)
1430     install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION share/OpenCV/)
1431 endif(ANDROID)
1432
1433 # --------------------------------------------------------------------------------------------
1434 #according to man pkg-config
1435 #  The package name specified on the pkg-config command line is defined to
1436 #      be the name of the metadata file, minus the .pc extension. If a library
1437 #      can install multiple versions simultaneously, it must give each version
1438 #      its own name (for example, GTK 1.2 might have the package  name  "gtk+"
1439 #      while GTK 2.0 has "gtk+-2.0").
1440 #  Part 2/2: ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install"
1441 # prefix=/usr
1442 # exec_prefix=${prefix}
1443 # libdir=${exec_prefix}/lib
1444 # includedir=${prefix}/include/opencv
1445 # -------------------------------------------------------------------------------------------
1446 set(prefix      ${CMAKE_INSTALL_PREFIX})
1447 set(exec_prefix "\${prefix}")
1448 set(libdir      "\${exec_prefix}/lib")
1449 set(includedir  "\${prefix}/${OPENCV_INCLUDE_PREFIX}")
1450 set(VERSION     ${OPENCV_VERSION})
1451
1452 set(OPENCV_PC_FILE_NAME opencv.pc)
1453 #need to be explicit with naming the pc file and version number for side by side installs to work.
1454 if(OPENCV_MANGLED_INSTALL_PATHS)
1455   SET(OpenCV_LIB_COMPONENTS opencv_contrib opencv_legacy opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core )
1456   #be explicit about the library names.
1457   set(OpenCV_LIB_COMPONENTS_ )
1458   foreach( CVLib ${OpenCV_LIB_COMPONENTS})
1459     set(OpenCV_LIB_COMPONENTS_ "${OpenCV_LIB_COMPONENTS_} ${libdir}/lib${CVLib}.so.${OPENCV_VERSION}" )
1460   endforeach()
1461   set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_})
1462   set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc")
1463   configure_file("${CMAKE_CURRENT_SOURCE_DIR}/opencv-XXX.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE)
1464 else()
1465   configure_file("${CMAKE_CURRENT_SOURCE_DIR}/opencv.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE)
1466 endif()
1467
1468 if(UNIX AND NOT ANDROID)
1469   install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig)
1470 endif()
1471
1472 # ----------------------------------------------------------------------------
1473 #   Uninstall target, for "make uninstall"
1474 # ----------------------------------------------------------------------------
1475 CONFIGURE_FILE(
1476   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1477   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1478   IMMEDIATE @ONLY)
1479
1480 ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
1481
1482 #-----------------------------------
1483 # Source package:
1484 #-----------------------------------
1485 set(BUILD_PACKAGE ON CACHE BOOL "Enables 'make package_source' command")
1486
1487 if(BUILD_PACKAGE)
1488     set(TARBALL_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
1489     if (NOT WIN32)
1490         add_custom_target(package_source
1491         #TODO: maybe we should not remove dll's
1492         COMMAND tar --transform 's,^,${TARBALL_NAME}/,S' -cjpf ${CMAKE_CURRENT_BINARY_DIR}/${TARBALL_NAME}.tar.bz2 --exclude-vcs --exclude="*.pyc" --exclude="*.vcproj" --exclude="*/lib/*" --exclude="*.dll" ./
1493         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1494     else()
1495         add_custom_target(package_source
1496         COMMAND zip -9 -r ${CMAKE_CURRENT_BINARY_DIR}/${TARBALL_NAME}.zip . -x '*/.svn/*' '*.vcproj' '*.pyc'
1497         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1498     endif()
1499 endif()
1500
1501
1502 #-----------------------------------
1503 # Solution folders:
1504 #-----------------------------------
1505
1506 if(${CMAKE_VERSION} VERSION_GREATER "2.8.0")
1507     set(ENABLE_SOLUTION_FOLDERS OFF CACHE BOOL "Solution folder in Visual Studio or in other IDEs")
1508 endif()
1509
1510 if(ENABLE_SOLUTION_FOLDERS)
1511     set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1512     set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
1513 endif()
1514
1515 #-----------------------------------
1516 # Subdirectories:
1517 #-----------------------------------
1518 add_subdirectory(include)
1519 add_subdirectory(modules)
1520 add_subdirectory(doc)
1521 add_subdirectory(data)
1522 add_subdirectory(3rdparty)
1523
1524 if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES)
1525     add_subdirectory(samples)
1526 endif()
1527
1528 # ----------------------------------------------------------------------------
1529 #   Summary:
1530 # ----------------------------------------------------------------------------
1531 macro(status text)
1532     SET(status_cond)
1533     SET(status_then)
1534     SET(status_else)
1535     
1536     SET(status_current_name "cond")
1537     foreach(arg ${ARGN})
1538        if(arg STREQUAL "THEN")
1539            SET(status_current_name "then")
1540        elseif(arg STREQUAL "ELSE")
1541            SET(status_current_name "else")
1542        else()
1543            LIST(APPEND status_${status_current_name} ${arg})
1544        endif()
1545     endforeach()
1546
1547     if(DEFINED status_cond)
1548         SET(status_placeholder_length 32)
1549         string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
1550         string(LENGTH "${text}" status_text_length)
1551         if (status_text_length LESS status_placeholder_length)
1552             string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
1553         elseif (DEFINED status_then OR DEFINED status_else)
1554             message(STATUS "${text}")
1555             SET(status_text "${status_placeholder}")
1556         else()
1557             SET(status_text "${text}")
1558         endif()
1559
1560         if (DEFINED status_then OR DEFINED status_else)
1561             if(${status_cond})
1562                 string(REPLACE ";" " " status_then "${status_then}")
1563                 message(STATUS "${status_text}" "${status_then}")
1564             else()
1565                 string(REPLACE ";" " " status_else "${status_else}")
1566                 message(STATUS "${status_text}" "${status_else}")
1567             endif()
1568         else()
1569             string(REPLACE ";" " " status_cond "${status_cond}")
1570             message(STATUS "${status_text}" "${status_cond}")
1571         endif()
1572      else()
1573          message(STATUS "${text}")
1574      endif()
1575 endmacro()
1576
1577 status("")
1578 status("General configuration for opencv ${OPENCV_VERSION} =====================================")
1579 status("")
1580 status("    Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO)
1581 status("    Compiler:"               CMAKE_COMPILER THEN "${CMAKE_COMPILER}" ELSE "${CMAKE_CXX_COMPILER}")
1582 status("    C++ flags (Release):"    ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
1583 status("    C++ flags (Debug):"      ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
1584 if(WIN32)
1585     status("    Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
1586     status("    Linker flags (Debug):"   ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
1587 else()
1588     status("    Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
1589     status("    Linker flags (Debug):"   ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
1590 endif()
1591
1592 if(ANDROID)
1593     status("    Floating point type:" ${ARM_TARGET})
1594     status("    Native API level:" android-${ANDROID_API_LEVEL})
1595     status("    SDK target:" "${ANDROID_SDK_TARGET}")
1596 endif()
1597
1598 #YV
1599 status("")
1600 status("  GUI: ")
1601
1602 if (HAVE_QT)
1603     status("    QT 4.x:"            HAVE_QT        THEN YES ELSE NO)
1604     status("    QT OpenGL support:" HAVE_QT_OPENGL THEN YES ELSE NO)
1605 else()
1606     if(WIN32)
1607         status("    Win32 UI:" YES)
1608     else()
1609         if(APPLE)
1610             if(WITH_CARBON)
1611                 status("    Carbon:" YES)
1612             else()
1613                 status("    Cocoa:"  YES)
1614             endif()
1615         else()
1616             status("    GTK+ 2.x:" HAVE_GTK     THEN YES ELSE NO)
1617             status("    GThread:"  HAVE_GTHREAD THEN YES ELSE NO)
1618         endif()
1619     endif()
1620 endif()
1621
1622 # media
1623 status("")
1624 status("  Media I/O: ")
1625 status("    ZLib:"      ZLIB_FOUND                         THEN YES             ELSE build)
1626 status("    JPEG:"      NOT WITH_JPEG OR JPEG_FOUND        THEN ${JPEG_FOUND}   ELSE build)
1627 status("    PNG:"       NOT WITH_PNG OR PNG_FOUND          THEN ${PNG_FOUND}    ELSE build)
1628 status("    TIFF:"      NOT WITH_TIFF OR TIFF_FOUND        THEN ${TIFF_FOUND}   ELSE build)
1629 status("    JPEG 2000:" NOT WITH_JASPER OR JASPER_FOUND    THEN ${JASPER_FOUND} ELSE build)
1630 status("    OpenEXR:"   WITH_OPENEXR AND OPENEXR_FOUND     THEN YES             ELSE NO)
1631
1632 status("    OpenNI:"    HAVE_OPENNI AND HAVE_OPENNI_PRIME_SENSOR_MODULE THEN YES ELSE NO)
1633
1634 # video
1635 status("")
1636 if(UNIX AND NOT APPLE)
1637     status("  Video I/O:")
1638     status("    DC1394 1.x:"     HAVE_DC1394         THEN YES ELSE NO)
1639     status("    DC1394 2.x:"     HAVE_DC1394_2       THEN YES ELSE NO)
1640     status("    FFMPEG:"         HAVE_FFMPEG         THEN YES ELSE NO)
1641     status("      codec:"        HAVE_FFMPEG_CODEC   THEN YES ELSE NO)
1642     status("      format:"       HAVE_FFMPEG_FORMAT  THEN YES ELSE NO)
1643     status("      util:"         HAVE_FFMPEG_UTIL    THEN YES ELSE NO)
1644     status("      swscale:"      HAVE_FFMPEG_SWSCALE THEN YES ELSE NO)
1645     status("      gentoo-style:" HAVE_GENTOO_FFMPEG  THEN YES ELSE NO)
1646     status("    GStreamer:"      HAVE_GSTREAMER      THEN YES ELSE NO)
1647     status("    UniCap:"         HAVE_UNICAP         THEN YES ELSE NO)
1648     status("    PvAPI:"          HAVE_PVAPI          THEN YES ELSE NO)
1649     status("    V4L/V4L2:"       HAVE_LIBV4L         THEN Using libv4l ELSE ${HAVE_CAMV4L}/${HAVE_CAMV4L2})
1650     status("    Xine:"           HAVE_XINE           THEN YES ELSE NO)
1651
1652     if(ANDROID)
1653         if(WITH_ANDROID_CAMERA)
1654             status("    AndroidNativeCamera:" BUILD_ANDROID_CAMERA_WRAPPER THEN "build for Android ${ANDROID_VERSION}" ELSE "use prebuilt libraries")
1655         else()
1656             status("    AndroidNativeCamera:" "NO (native camera requires Android API level 8 or higher)")
1657         endif()
1658     endif()
1659 elseif(APPLE)
1660     status("  Video I/O:"        WITH_QUICKTIME      THEN QuickTime ELSE QTKit)
1661 elseif(WIN32)
1662     status("  Video I/O:"        HAVE_VIDEOINPUT     THEN DirectShow ELSE NO)
1663 endif()
1664
1665 # Other third-party libraries
1666 status("")
1667 status("  Other third-party libraries:")
1668
1669 if(WITH_IPP AND IPP_FOUND)
1670     status("    Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]")
1671     status("         at:" "${IPP_ROOT_DIR}")
1672 else()
1673     status("    Use IPP:"   WITH_IPP AND NOT IPP_FOUND THEN IPP not found ELSE NO)
1674 endif()
1675
1676 status("    Use TBB:" HAVE_TBB THEN YES ELSE NO)
1677
1678 if(UNIX)
1679     status("    Use ThreadingFramework:" HAVE_THREADING_FRAMEWORK THEN YES ELSE NO)
1680 endif()
1681
1682 status("    Use Cuda:"  HAVE_CUDA  THEN YES ELSE NO)
1683 status("    Use Eigen:" HAVE_EIGEN THEN YES ELSE NO)
1684
1685 # interfaces to other languages
1686 status("")
1687 status("  Interfaces:")
1688 status("    Python:"              BUILD_NEW_PYTHON_SUPPORT THEN YES ELSE NO)
1689 status("    Python interpreter:"  PYTHON_EXECUTABLE        THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO)
1690 status("    Python numpy:"        PYTHON_USE_NUMPY         THEN YES ELSE "NO (Python wrappers will not be generated)")
1691 if(ANDROID AND ANDROID_API_LEVEL LESS 8)
1692     status("    Java:" "NO (Java API requires Android API level 8 or higher)")
1693 else()
1694     status("    Java:" BUILD_JAVA_SUPPORT THEN YES ELSE NO)
1695 endif()
1696
1697 if(ANDROID)
1698     status("    android tool:"    ANDROID_EXECUTABLE       THEN "${ANDROID_EXECUTABLE} (${ANDROID_TOOLS_Pkg_Desc})" ELSE NO)
1699     status("    ant:"             ANT_EXECUTABLE           THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO)
1700 endif()
1701
1702 # documentation
1703 status("")
1704 status("  Documentation:")
1705 status("    Sphinx:"              HAVE_SPHINX              THEN "${SPHINX_BUILD} (ver ${SPHINX_VERSION})" ELSE NO)
1706 status("    PdfLaTeX compiler:"   PDFLATEX_COMPILER        THEN "${PDFLATEX_COMPILER}" ELSE NO)
1707 if (BUILD_DOCS AND HAVE_SPHINX)
1708     status("    Build Documentation:" PDFLATEX_COMPILER THEN YES ELSE "YES (only HTML without math formulas)")
1709 else()
1710     status("    Build Documentation:" NO)
1711 endif()
1712
1713 # samples and tests
1714 status("")
1715 status("  Tests and samples:")
1716 status("    Tests:"    BUILD_TESTS     THEN YES ELSE NO)
1717 status("    Examples:" BUILD_EXAMPLES  THEN YES ELSE NO)
1718
1719 if(ANDROID)
1720    status("    Android tests:" BUILD_TESTS AND CAN_BUILD_ANDROID_PROJECTS THEN YES ELSE NO)
1721    status("    Android examples:" BUILD_ANDROID_EXAMPLES THEN YES ELSE NO)
1722 endif()
1723
1724 # auxiliary
1725 status("")
1726 status("  Install path:" "${CMAKE_INSTALL_PREFIX}")
1727 status("")
1728 status("  cvconfig.h is in:" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}")
1729 status("-----------------------------------------------------------------")
1730 status("")
1731
1732 # warn in the case of in-source build
1733 if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
1734     message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree")
1735 endif()