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