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