1 # ----------------------------------------------------------------------------
2 # Root CMake file for OpenCV
4 # From the off-tree build directory, invoke:
5 # $ cmake <PATH_TO_OPENCV_ROOT>
8 # - OCT-2008: Initial version <joseluisblancoc@gmail.com>
10 # ----------------------------------------------------------------------------
12 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
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
21 set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib)
24 # it _must_ go before PROJECT(OpenCV) in order to work
26 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
28 set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory")
32 set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)
34 endif(NOT CMAKE_TOOLCHAIN_FILE)
36 # --------------------------------------------------------------
37 # Top level OpenCV project
38 # --------------------------------------------------------------
40 cmake_minimum_required(VERSION 2.6.3)
42 cmake_minimum_required(VERSION 2.8)
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} )
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")
63 set(CMAKE_VERBOSE_MAKEFILE 1)
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)
75 # ----------------------------------------------------------------------------
76 # Build static or dynamic libs?
77 # Default: dynamic libraries
78 # ----------------------------------------------------------------------------
80 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)")
82 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)")
84 # ----------------------------------------------------------------------------
85 # Include debug info into debug libs?
87 # ----------------------------------------------------------------------------
88 set(BUILD_WITH_DEBUG_INFO ON CACHE BOOL "Include debug info into debug libs")
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}")
100 set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}")
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)
108 set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
109 set(OPENCV_DEBUG_POSTFIX d)
112 set(OPENCV_DLLVERSION "")
113 set(OPENCV_DEBUG_POSTFIX)
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})
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" )
131 set(OPENCV_DOC_INSTALL_PATH doc)
132 elseif(OPENCV_MANGLED_INSTALL_PATHS)
133 set(OPENCV_DOC_INSTALL_PATH share/OpenCV-${OPENCV_VERSION}/doc)
135 set(OPENCV_DOC_INSTALL_PATH share/OpenCV/doc)
139 set(OPENCV_LIB_INSTALL_PATH libs/${ARMEABI_NDK_NAME})
141 set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX})
144 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}")
145 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
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})
154 if(NOT COMMAND find_host_program)
155 macro(find_host_program)
156 find_program(${ARGN})
160 # ----------------------------------------------------------------------------
161 # Use statically or dynamically linked CRT?
163 # ----------------------------------------------------------------------------
164 if(WIN32 AND NOT BUILD_SHARED_LIBS)
165 option (BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT" ON)
169 if(BUILD_WITH_STATIC_CRT)
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}}")
178 if(${flag_var} MATCHES "/MDd")
179 string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
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)
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}}")
195 if(${flag_var} MATCHES "/MTd")
196 string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}")
199 endif(BUILD_WITH_STATIC_CRT)
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}")
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}")
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}")
217 string(REPLACE "/Zi" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
218 string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
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}")
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)
239 message(STATUS "Extracting svn version, please wait...")
240 execute_process(COMMAND ${SVNVERSION_PATH} -n ${OpenCV_SOURCE_DIR} OUTPUT_VARIABLE SVNVERSION_RESULT)
242 if(SVNVERSION_RESULT MATCHES "exported")
243 # This is NOT a svn repository:
244 set(OPENCV_SVNVERSION "")
245 message(STATUS "SVNVERSION: exported")
247 set(OPENCV_SVNVERSION " svn:${SVNVERSION_RESULT}")
248 message(STATUS "SVNVERSION: ${OPENCV_SVNVERSION}")
251 # We don't have svnversion:
252 set(OPENCV_SVNVERSION "")
255 # ----------------------------------------------------------------------------
256 # Detect Microsoft compiler:
257 # ----------------------------------------------------------------------------
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)
270 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
271 ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
272 OUTPUT_STRIP_TRAILING_WHITESPACE)
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}")
278 # Split the three parts:
279 string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
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)
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})")
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")
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 # ----------------------------------------------------------------------------
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)
322 # ----------------------------------------------------------------------------
323 # CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC..
324 # ----------------------------------------------------------------------------
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")
332 set(INSTALL_ANDROID_EXAMPLES OFF CACHE BOOL "Install Android examples")
336 # ===================================================
338 set(BUILD_TESTS ON CACHE BOOL "Build tests")
340 set(BUILD_TESTS OFF CACHE BOOL "Build tests")
342 set(BUILD_PERF_TESTS ON CACHE BOOL "Build performance tests")
344 # Build 3rdparty libraries under unix
345 # ===================================================
347 set(OPENCV_BUILD_3RDPARTY_LIBS TRUE CACHE INTERNAL "Build 3rd party libraries")
349 set(OPENCV_BUILD_3RDPARTY_LIBS FALSE CACHE BOOL "Build 3rd party libraries")
353 include(OpenCVPCHSupport.cmake REQUIRED)
356 include(OpenCVModule.cmake REQUIRED)
358 include(OpenCVAndroidProject.cmake REQUIRED)
362 SET(USE_PRECOMPILED_HEADERS ON CACHE BOOL "Use precompiled headers")
364 SET(USE_PRECOMPILED_HEADERS OFF CACHE BOOL "Use precompiled headers" FORCE)
368 include(OpenCVFindPkgConfig.cmake OPTIONAL)
369 include(CheckFunctionExists)
370 include(CheckIncludeFile)
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")
377 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64.*|x86_64.*)
380 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686.*|i386.*|x86.*)
383 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES powerpc.*)
384 set(ENABLE_POWERPC ON CACHE BOOL "Enable PowerPC for GCC")
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)
392 # SET(_USE_FAST_MATH ON)
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")
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")
413 # allow fine grained control over which libraries not to link, even if
414 # they are available on the system
415 # ====================================================================
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")
425 set(WITH_FFMPEG ON CACHE BOOL "Include FFMPEG support")
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)")
433 set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support")
434 set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support")
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")
445 set(WITH_AVFOUNDATION ON CACHE BOOL "Use AVFoundation for Video I/O")
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")
453 if( CMAKE_VERSION VERSION_GREATER "2.8")
454 set(WITH_CUDA ON CACHE BOOL "Include NVidia Cuda Runtime support")
456 set(WITH_CUDA OFF CACHE BOOL "Include NVidia Cuda Runtime support")
459 set(WITH_OPENNI OFF CACHE BOOL "Include OpenNI support")
460 set(WITH_XIMEA OFF CACHE BOOL "Include XIMEA cameras support")
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 # ===================================================
468 macro(CHECK_MODULE module_name define)
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)
477 PKG_CHECK_MODULES(${ALIAS} ${module_name})
481 foreach(P "${ALIAS_INCLUDE_DIRS}")
483 list(APPEND HIGHGUI_INCLUDE_DIRS ${${P}})
487 foreach(P "${ALIAS_LIBRARY_DIRS}")
489 list(APPEND HIGHGUI_LIBRARY_DIRS ${${P}})
493 list(APPEND HIGHGUI_LIBRARIES ${${ALIAS_LIBRARIES}})
501 CHECK_MODULE(gtk+-2.0 HAVE_GTK)
502 CHECK_MODULE(gthread-2.0 HAVE_GTHREAD)
505 set(HAVE_GTHREAD FALSE)
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)
512 set(HAVE_GSTREAMER FALSE)
517 CHECK_MODULE(libunicap HAVE_UNICAP_)
518 CHECK_MODULE(libucil HAVE_UNICAP_UCIL)
519 if(HAVE_UNICAP_ AND HAVE_UNICAP_UCIL)
523 set(HAVE_UNICAP FALSE)
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)
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)
548 if(HAVE_FFMPEG_CODEC AND HAVE_FFMPEG_FORMAT AND HAVE_FFMPEG_UTIL)
549 if(HAVE_FFMPEG_SWSCALE OR NOT HAVE_GENTOO_FFMPEG)
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)
557 FIND_FILE(BZIP2_LIBRARIES NAMES libbz2.so.1 PATHS /lib)
562 CHECK_MODULE(libdc1394-2 HAVE_DC1394_2)
563 if(NOT HAVE_DC1394_2)
564 CHECK_MODULE(libdc1394 HAVE_DC1394)
567 set(HAVE_DC1394_2 FALSE)
568 set(HAVE_DC1394 FALSE)
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)
578 CHECK_MODULE(libxine HAVE_XINE)
583 CHECK_MODULE(libv4l1 HAVE_LIBV4L)
584 CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
585 CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
587 set(HAVE_LIBV4L FALSE)
588 set(HAVE_CAMV4L FALSE)
589 set(HAVE_CAMV4L2 FALSE)
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)
597 set(OPENCV_LINKER_LIBS dl m pthread rt)
600 add_definitions(-DHAVE_ALLOCA -DHAVE_ALLOCA_H -DHAVE_LIBPTHREAD -DHAVE_UNISTD_H)
604 if(NOT OPENCV_BUILD_3RDPARTY_LIBS)
605 message(STATUS "NOT OPENCV_BUILD_3RDPARTY_LIBS **************************************************")
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)
619 set(TIFF_FOUND FALSE)
624 set(JASPER_FOUND FALSE)
629 set(JPEG_FOUND FALSE)
634 if(WITH_PNG AND NOT PNG_FOUND)
635 set(PNG_LIBRARIES libpng)
638 if(WITH_JPEG AND NOT JPEG_FOUND)
639 set(JPEG_LIBRARIES libjpeg)
642 if(WITH_TIFF AND NOT TIFF_FOUND)
643 set(TIFF_LIBRARIES libtiff)
646 if(WITH_JASPER AND NOT JASPER_FOUND)
647 set(JASPER_LIBRARIES libjasper)
651 set(ZLIB_LIBRARY zlib)
654 #message(STATUS "Graphic libraries: ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${JASPER_LIBRARIES}")
657 include(OpenCVFindOpenEXR.cmake)
660 set(BUILD_DOCS ON CACHE BOOL "Build OpenCV Documentation")
663 include(OpenCVFindLATEX.cmake REQUIRED)
666 set(BUILD_NEW_PYTHON_SUPPORT ON CACHE BOOL "Build with Python support")
669 if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
670 set(BUILD_NEW_PYTHON_SUPPORT OFF)
675 set(BUILD_NEW_PYTHON_SUPPORT OFF)
678 # Always try to find python
679 # ===================================================
680 find_host_package(PythonInterp)
681 find_host_package(PythonLibs)
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)
688 execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
689 ERROR_VARIABLE PYTHON_VERSION_FULL
690 OUTPUT_STRIP_TRAILING_WHITESPACE)
692 string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
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.")
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")
709 IF ("${PYTHON_VERSION_MAJOR_MINOR}" VERSION_GREATER 2.4)
710 SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} -B)
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)
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}")
725 set(PYTHON_USE_NUMPY 0)
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)
734 if(SPHINX_PROCESS EQUAL 0)
735 find_host_program(SPHINX_BUILD sphinx-build)
738 message(STATUS " Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
743 # ===================================================
744 if (PYTHON_EXECUTABLE AND ANDROID AND ANDROID_API_LEVEL GREATER 7)
745 option(BUILD_JAVA_SUPPORT "Build with Java support" TRUE)
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)
753 file(TO_CMAKE_PATH "$ENV{ANDROID_SDK}" ANDROID_SDK_ENV_PATH)
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/"
766 if(ANDROID_EXECUTABLE)
767 message(STATUS " Found android tool: ${ANDROID_EXECUTABLE}")
769 get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH)
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})
784 if (NOT ANDROID_TOOLS_Pkg_Revision)
785 SET(ANDROID_TOOLS_Pkg_Revision "Unknown")
786 MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Revision)
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.")
793 MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Desc)
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}")
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}")
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)
818 if (ANDROID_PROCESS EQUAL 0)
819 math(EXPR desired_android_target_level_1 "${desired_android_target_level}-1")
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}")
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")
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} )
838 string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}")
843 find_host_program(ANT_EXECUTABLE NAMES ant.bat ant
844 PATHS "${ANT_DIR_ENV_PATH}/bin"
845 "${ProgramFiles_ENV_PATH}/apache-ant/bin"
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}")
853 message(STATUS " Found apache ant ${ANT_VERSION}: ${ANT_EXECUTABLE}")
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)
859 SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
863 if(CAN_BUILD_ANDROID_PROJECTS)
864 SET(BUILD_ANDROID_EXAMPLES TRUE CACHE BOOL "Build examples for Android platform")
868 ############################### QT ################################
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")
874 set(HAVE_QT_OPENGL 0)
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)
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})
896 ############################### TBB ################################
899 if (UNIX AND NOT APPLE AND NOT ANDROID)
900 PKG_CHECK_MODULES(TBB tbb)
904 if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "")
905 include_directories(${TBB_INCLUDE_DIRS})
907 link_directories(${TBB_LIBRARY_DIRS})
908 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES})
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")
915 find_path(TBB_INCLUDE_DIR "tbb/tbb.h" PATHS ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers")
918 set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory")
919 link_directories("${TBB_LIB_DIR}")
922 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib)
924 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbbmalloc tbb)
925 add_definitions(-DTBB_USE_GCC_BUILTINS)
927 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
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)
934 get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIR}/../lib" ABSOLUTE)
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")
943 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8")
945 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9")
947 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10")
949 set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory")
950 link_directories("${TBB_LIB_DIR}")
955 if(NOT "${TBB_INCLUDE_DIR}" STREQUAL "")
956 include_directories("${TBB_INCLUDE_DIR}")
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")
968 if(THREADING_FRAMEWORK_HEADER AND THREADING_FRAMEWORK_SOURCE)
969 set(HAVE_THREADING_FRAMEWORK 1)
972 set(HAVE_THREADING_FRAMEWORK 1)
976 ############################ Intel IPP #############################
980 include(OpenCVFindIPP.cmake)
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})
991 ############################### CUDA ################################
994 find_package(CUDA 4.0)
998 message(STATUS "CUDA detected: " ${CUDA_VERSION})
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")
1003 string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}")
1004 string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}")
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)
1013 # NVCC flags to be set
1014 set(NVCC_FLAGS_EXTRA "")
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 "")
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}")
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}")
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}")
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}")
1049 message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
1051 unset(CUDA_ARCH_BIN CACHE)
1052 unset(CUDA_ARCH_PTX CACHE)
1057 ############################### OpenNI ################################
1058 set(HAVE_OPENNI FALSE)
1059 set(HAVE_OPENNI_PRIME_SENSOR_MODULE FALSE)
1062 include(OpenCVFindOpenNI.cmake)
1065 ############################### XIMEA ################################
1066 set(HAVE_XIMEA FALSE)
1069 include(OpenCVFindXimea.cmake)
1073 set(HAVE_XIMEA TRUE)
1076 ############################## 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})
1090 ################## Extra HighGUI libs on Windows ###################
1093 set(WITH_VIDEOINPUT ON CACHE BOOL "Build HighGUI with DirectShow support")
1094 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} comctl32 gdi32 ole32)
1097 set(HAVE_VIDEOINPUT 1)
1101 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32)
1106 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} msvfw32 avifil32 avicap32 winmm)
1108 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32 winmm)
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)
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")
1128 if(NOT "${ANDROID_VERSION}" STREQUAL "")
1129 SET(BUILD_ANDROID_CAMERA_WRAPPER ON)
1132 MARK_AS_ADVANCED(ANDROID_SOURCE_TREE)
1135 # ----------------------------------------------------------------------------
1136 # UPDATE CONFIG FILES & SCRIPTS:
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.
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)
1147 set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h")
1149 message(STATUS "Parsing 'cvconfig.h.cmake'")
1150 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cvconfig.h.cmake" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h")
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"
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 "")
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 "")
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
1181 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /Wp64")
1184 # set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /D _BIND_TO_CURRENT_CRT_VERSION=1 /D _BIND_TO_CURRENT_VCLIBS_VERSION=1")
1187 if(BUILD_WITH_DEBUG_INFO)
1188 set(EXTRA_EXE_LINKER_FLAGS_RELEASE "${EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug")
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")
1198 if(CMAKE_COMPILER_IS_GNUCXX)
1199 # High level of warnings.
1200 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
1202 # The -Wno-long-long is required in 64bit systems when including sytem headers.
1204 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long")
1208 if(UNIX AND NOT ANDROID)
1209 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -pthread")
1212 if(OPENCV_WARNINGS_ARE_ERRORS)
1213 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
1216 if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE)
1217 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -march=i686")
1220 # Other optimizations
1221 if(USE_OMIT_FRAME_POINTER)
1222 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
1225 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
1228 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
1231 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse")
1234 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse2")
1236 # SSE3 and further should be disabled under MingW because it generates compiler errors
1239 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse3")
1242 if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402)
1243 set(HAVE_GCC43_OR_NEWER 1)
1245 if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401)
1246 set(HAVE_GCC42_OR_NEWER 1)
1249 if(HAVE_GCC42_OR_NEWER OR APPLE)
1251 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mssse3")
1253 if(HAVE_GCC43_OR_NEWER)
1255 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse4.1")
1258 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse4.2")
1265 if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4)
1266 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mfpmath=387")
1271 if(ENABLE_PROFILING)
1272 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
1274 # Remove unreferenced functions: function level linking
1275 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
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")
1286 # 64-bit MSVC compiler uses SSE/SSE2 by default
1289 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE")
1292 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE2")
1296 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE3")
1299 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1")
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")
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}")
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)
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}")
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)
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}")
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}")
1355 string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1356 string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1359 if("${CMAKE_CONFIGURE_LDFLAGS}")
1360 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CONFIGURE_LDFLAGS}")
1361 endif("${CMAKE_CONFIGURE_LDFLAGS}")
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 # -------------------------------------------------------------------------------------------
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}\"")
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}\"")
1386 set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "")
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}\"")
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}\"")
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)
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}/)
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/)
1418 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV)
1421 # --------------------------------------------------------------------------------------------
1422 # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
1423 # -------------------------------------------------------------------------------------------
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}\"")
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)
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}/")
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 # -------------------------------------------------------------------------------------------
1443 if(BUILD_SHARED_LIBS)
1444 SET(OPENCV_LIBTYPE_CONFIGMAKE "SHARED")
1446 SET(OPENCV_LIBTYPE_CONFIGMAKE "STATIC")
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}")
1461 # -------------------------------------------------------------------------------------------
1462 # Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install"
1463 # -------------------------------------------------------------------------------------------
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)")
1469 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY)
1472 # -------------------------------------------------------------------------------------------
1473 # Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install"
1474 # -------------------------------------------------------------------------------------------
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)/../..")
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/)
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"
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})
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}" )
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)
1516 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/opencv.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE)
1519 if(UNIX AND NOT ANDROID)
1520 install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig)
1523 # ----------------------------------------------------------------------------
1524 # Uninstall target, for "make uninstall"
1525 # ----------------------------------------------------------------------------
1527 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1528 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1531 ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
1533 #-----------------------------------
1535 #-----------------------------------
1536 set(BUILD_PACKAGE ON CACHE BOOL "Enables 'make package_source' command")
1539 set(TARBALL_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
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})
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})
1559 #-----------------------------------
1561 #-----------------------------------
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")
1567 if(ENABLE_SOLUTION_FOLDERS)
1568 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1569 set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
1572 #-----------------------------------
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"
1583 #-----------------------------------
1585 #-----------------------------------
1586 add_subdirectory(include)
1587 add_subdirectory(modules)
1588 add_subdirectory(doc)
1589 add_subdirectory(data)
1590 add_subdirectory(3rdparty)
1592 if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES)
1593 add_subdirectory(samples)
1596 # ----------------------------------------------------------------------------
1598 # ----------------------------------------------------------------------------
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")
1611 LIST(APPEND status_${status_current_name} ${arg})
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}")
1625 SET(status_text "${text}")
1628 if (DEFINED status_then OR DEFINED status_else)
1630 string(REPLACE ";" " " status_then "${status_then}")
1631 message(STATUS "${status_text}" "${status_then}")
1633 string(REPLACE ";" " " status_else "${status_else}")
1634 message(STATUS "${status_text}" "${status_else}")
1637 string(REPLACE ";" " " status_cond "${status_cond}")
1638 message(STATUS "${status_text}" "${status_cond}")
1641 message(STATUS "${text}")
1646 status("General configuration for opencv ${OPENCV_VERSION} =====================================")
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})
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})
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})
1661 status(" Floating point type:" ${ARM_TARGET})
1662 status(" Native API level:" android-${ANDROID_API_LEVEL})
1663 status(" SDK target:" "${ANDROID_SDK_TARGET}")
1671 status(" QT 4.x:" HAVE_QT THEN YES ELSE NO)
1672 status(" QT OpenGL support:" HAVE_QT_OPENGL THEN YES ELSE NO)
1675 status(" Win32 UI:" YES)
1679 status(" Carbon:" YES)
1681 status(" Cocoa:" YES)
1684 status(" GTK+ 2.x:" HAVE_GTK THEN YES ELSE NO)
1685 status(" GThread:" HAVE_GTHREAD THEN YES ELSE NO)
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)
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)
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)
1724 if(WITH_ANDROID_CAMERA)
1725 status(" AndroidNativeCamera:" BUILD_ANDROID_CAMERA_WRAPPER THEN "build for Android ${ANDROID_VERSION}" ELSE "use prebuilt libraries")
1727 status(" AndroidNativeCamera:" "NO (native camera requires Android API level 8 or higher)")
1732 status(" Video I/O:" WITH_QUICKTIME THEN QuickTime ELSE QTKit)
1734 status(" Video I/O: AVFoundation")
1737 status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO)
1740 # Other third-party libraries
1742 status(" Other third-party libraries:")
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}")
1748 status(" Use IPP:" WITH_IPP AND NOT IPP_FOUND THEN IPP not found ELSE NO)
1751 status(" Use TBB:" HAVE_TBB THEN YES ELSE NO)
1754 status(" Use ThreadingFramework:" HAVE_THREADING_FRAMEWORK THEN YES ELSE NO)
1757 status(" Use Cuda:" HAVE_CUDA THEN YES ELSE NO)
1758 status(" Use Eigen:" HAVE_EIGEN THEN YES ELSE NO)
1760 # interfaces to other languages
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)")
1769 status(" Java:" BUILD_JAVA_SUPPORT THEN YES ELSE NO)
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)
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)")
1785 status(" Build Documentation:" NO)
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)
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)
1802 status(" Install path:" "${CMAKE_INSTALL_PREFIX}")
1804 status(" cvconfig.h is in:" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}")
1805 status("-----------------------------------------------------------------")
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")