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 # --------------------------------------------------------------
39 cmake_minimum_required(VERSION 2.4)
42 set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
43 if(DEFINED CMAKE_BUILD_TYPE)
44 set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} )
47 set(CMAKE_C_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
48 set(CMAKE_C_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
49 set(CMAKE_CXX_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
50 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
51 set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
52 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
53 set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
54 set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
55 set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE)
56 set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE)
57 set(CMAKE_VERBOSE OFF CACHE BOOL "Verbose mode")
59 set(CMAKE_VERBOSE_MAKEFILE 1)
62 # --------------------------------------------------------------
63 # Indicate CMake 2.7 and above that we don't want to mix relative
64 # and absolute paths in linker lib lists.
65 # Run "cmake --help-policy CMP0003" for more information.
66 # --------------------------------------------------------------
67 if(COMMAND cmake_policy)
68 cmake_policy(SET CMP0003 NEW)
71 # ----------------------------------------------------------------------------
72 # Build static or dynamic libs?
73 # Default: dynamic libraries
74 # ----------------------------------------------------------------------------
75 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)")
77 # ----------------------------------------------------------------------------
78 # Include debug info into debug libs?
80 # ----------------------------------------------------------------------------
81 set(BUILD_WITH_DEBUG_INFO ON CACHE BOOL "Include debug info into debug libs")
83 # ----------------------------------------------------------------------------
84 # Get actual OpenCV version number from sources
85 # ----------------------------------------------------------------------------
86 SET(OPENCV_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/modules/core/include/opencv2/core/version.hpp")
87 FILE(STRINGS "${OPENCV_VERSION_FILE}" OPENCV_VERSION_PARTS REGEX "#define CV_.+OR_VERSION[ ]+[0-9]+" )
88 string(REGEX REPLACE ".+CV_MAJOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MAJOR "${OPENCV_VERSION_PARTS}")
89 string(REGEX REPLACE ".+CV_MINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MINOR "${OPENCV_VERSION_PARTS}")
90 string(REGEX REPLACE ".+CV_SUBMINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_PATCH "${OPENCV_VERSION_PARTS}")
91 set(OPENCV_VERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
93 set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}")
95 # create a dependency on version file
96 # we will never use output of the following command but cmake will rerun if version file changes
97 configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY)
101 set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
102 set(OPENCV_DEBUG_POSTFIX d)
105 set(OPENCV_DLLVERSION "")
106 set(OPENCV_DEBUG_POSTFIX)
110 set(OPENCV_INCLUDE_PREFIX include)
111 if(UNIX AND NOT ANDROID AND BUILD_SHARED_LIBS)
112 option(OPENCV_MANGLED_INSTALL_PATHS "Enables mangled install paths, that help with side by side installs." False)
113 if(OPENCV_MANGLED_INSTALL_PATHS)
114 set(OPENCV_INCLUDE_PREFIX include/opencv-${OPENCV_VERSION})
119 # Save libs and executables in the same place
120 set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Output directory for libraries" )
121 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Output directory for applications" )
124 set(OPENCV_DOC_INSTALL_PATH doc)
125 elseif(OPENCV_MANGLED_INSTALL_PATHS)
126 set(OPENCV_DOC_INSTALL_PATH share/OpenCV-${OPENCV_VERSION}/doc)
128 set(OPENCV_DOC_INSTALL_PATH share/OpenCV/doc)
132 set(OPENCV_LIB_INSTALL_PATH libs/${ARMEABI_NDK_NAME})
134 set(OPENCV_LIB_INSTALL_PATH lib)
137 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}")
138 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
140 # search packages for host system instead of packages for target system
141 # in case of cross compilation thess macro should be defined by toolchain file
142 if(NOT COMMAND find_host_package)
143 macro(find_host_package)
144 find_package(${ARGN})
147 if(NOT COMMAND find_host_program)
148 macro(find_host_program)
149 find_program(${ARGN})
153 # ----------------------------------------------------------------------------
154 # Use statically or dynamically linked CRT?
156 # ----------------------------------------------------------------------------
157 if(WIN32 AND NOT BUILD_SHARED_LIBS)
158 option (BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT" ON)
162 if(BUILD_WITH_STATIC_CRT)
164 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
165 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
166 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
167 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
168 if(${flag_var} MATCHES "/MD")
169 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
171 if(${flag_var} MATCHES "/MDd")
172 string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
176 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib")
177 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib")
178 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib")
179 else(BUILD_WITH_STATIC_CRT)
181 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
182 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
183 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
184 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
185 if(${flag_var} MATCHES "/MT")
186 string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
188 if(${flag_var} MATCHES "/MTd")
189 string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}")
192 endif(BUILD_WITH_STATIC_CRT)
194 if(NOT BUILD_WITH_DEBUG_INFO)
195 string(REPLACE "/debug" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
196 string(REPLACE "/DEBUG" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
197 string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
198 string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
200 string(REPLACE "/debug" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
201 string(REPLACE "/DEBUG" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
202 string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
203 string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
205 string(REPLACE "/debug" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
206 string(REPLACE "/DEBUG" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
207 string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
208 string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
210 string(REPLACE "/Zi" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
211 string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
216 # ----------------------------------------------------------------------------
217 # Variables for cvconfig.h.cmake
218 # ----------------------------------------------------------------------------
219 set(PACKAGE "opencv")
220 set(PACKAGE_BUGREPORT "opencvlibrary-devel@lists.sourceforge.net")
221 set(PACKAGE_NAME "opencv")
222 set(PACKAGE_STRING "${PACKAGE} ${OPENCV_VERSION}")
223 set(PACKAGE_TARNAME "${PACKAGE}")
224 set(PACKAGE_VERSION "${OPENCV_VERSION}")
226 # ----------------------------------------------------------------------------
227 # Autodetect if we are in a SVN repository
228 # ----------------------------------------------------------------------------
229 find_host_program(SVNVERSION_PATH svnversion)
230 mark_as_advanced(force SVNVERSION_PATH)
232 message(STATUS "Extracting svn version, please wait...")
233 execute_process(COMMAND ${SVNVERSION_PATH} -n ${OpenCV_SOURCE_DIR} OUTPUT_VARIABLE SVNVERSION_RESULT)
235 if(SVNVERSION_RESULT MATCHES "exported")
236 # This is NOT a svn repository:
237 set(OPENCV_SVNVERSION "")
238 message(STATUS "SVNVERSION: exported")
240 set(OPENCV_SVNVERSION " svn:${SVNVERSION_RESULT}")
241 message(STATUS "SVNVERSION: ${OPENCV_SVNVERSION}")
244 # We don't have svnversion:
245 set(OPENCV_SVNVERSION "")
248 # ----------------------------------------------------------------------------
249 # Detect Microsoft compiler:
250 # ----------------------------------------------------------------------------
255 # ----------------------------------------------------------------------------
256 # Detect GNU version:
257 # ----------------------------------------------------------------------------
258 if(CMAKE_COMPILER_IS_GNUCXX)
259 execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
260 OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
261 OUTPUT_STRIP_TRAILING_WHITESPACE)
263 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
264 ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
265 OUTPUT_STRIP_TRAILING_WHITESPACE)
267 # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
268 # Look for the version number
269 string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
271 # Split the three parts:
272 string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
274 list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
275 list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
277 set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
278 math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
279 message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")
282 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
283 OUTPUT_VARIABLE CMAKE_OPENCV_GCC_TARGET_MACHINE
284 OUTPUT_STRIP_TRAILING_WHITESPACE)
285 if(CMAKE_OPENCV_GCC_TARGET_MACHINE MATCHES "64")
291 # ----------------------------------------------------------------------------
292 # Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
293 # see include/opencv/cxtypes.h file for related ICC & CV_ICC defines.
294 # NOTE: The system needs to determine if the '-fPIC' option needs to be added
295 # for the 3rdparty static libs being compiled. The CMakeLists.txt files
296 # in 3rdparty use the CV_ICC definition being set here to determine if
297 # the -fPIC flag should be used.
298 # ----------------------------------------------------------------------------
308 elseif(__INTEL_COMPILER)
309 set(CV_ICC __INTEL_COMPILER)
310 elseif(CMAKE_C_COMPILER MATCHES "icc")
311 set(CV_ICC icc_matches_c_compiler)
315 # ----------------------------------------------------------------------------
316 # CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC..
317 # ----------------------------------------------------------------------------
319 # Build/install (or not) some apps:
320 # ===================================================
321 set(BUILD_EXAMPLES OFF CACHE BOOL "Build all examples")
322 set(INSTALL_C_EXAMPLES OFF CACHE BOOL "Install C examples")
323 set(INSTALL_PYTHON_EXAMPLES OFF CACHE BOOL "Install Python examples")
325 set(INSTALL_ANDROID_EXAMPLES OFF CACHE BOOL "Install Android examples")
329 # ===================================================
330 set(BUILD_TESTS ON CACHE BOOL "Build tests")
332 # Build 3rdparty libraries under unix
333 # ===================================================
335 set(OPENCV_BUILD_3RDPARTY_LIBS TRUE CACHE BOOL "Build 3rd party libraries")
337 set(OPENCV_BUILD_3RDPARTY_LIBS FALSE CACHE BOOL "Build 3rd party libraries")
340 include(OpenCVPCHSupport.cmake REQUIRED)
341 include(OpenCVModule.cmake REQUIRED)
343 include(OpenCVAndroidProject.cmake REQUIRED)
347 SET(USE_PRECOMPILED_HEADERS ON CACHE BOOL "Use precompiled headers")
349 SET(USE_PRECOMPILED_HEADERS OFF CACHE BOOL "Use precompiled headers" FORCE)
353 include(OpenCVFindPkgConfig.cmake OPTIONAL)
354 include(CheckFunctionExists)
355 include(CheckIncludeFile)
358 if(CMAKE_COMPILER_IS_GNUCXX)
359 set(ENABLE_PROFILING OFF CACHE BOOL "Enable profiling in the GCC compiler (Add flags: -g -pg)")
360 set(USE_OMIT_FRAME_POINTER ON CACHE BOOL "Enable -fomit-frame-pointer for GCC")
362 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64.*|x86_64.*)
365 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686.*|i386.*|x86.*)
368 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES powerpc.*)
369 set(ENABLE_POWERPC ON CACHE BOOL "Enable PowerPC for GCC")
373 # enable everything, since the available set of instructions is checked at runtime
374 IF ("${CMAKE_GCC_REGEX_VERSION}" VERSION_GREATER 4.5)
375 SET(_USE_FAST_MATH OFF)
377 SET(_USE_FAST_MATH ON)
379 set(USE_FAST_MATH ${_USE_FAST_MATH} CACHE BOOL "Enable -ffast-math (not recommended for GCC 4.6.x)")
380 set(ENABLE_SSE ON CACHE BOOL "Enable SSE instructions")
381 set(ENABLE_SSE2 ON CACHE BOOL "Enable SSE2 instructions")
382 set(ENABLE_SSE3 OFF CACHE BOOL "Enable SSE3 instructions")
383 set(ENABLE_SSSE3 OFF CACHE BOOL "Enable SSSE3 instructions")
384 set(ENABLE_SSE41 OFF CACHE BOOL "Enable SSE4.1 instructions")
385 set(ENABLE_SSE42 OFF CACHE BOOL "Enable SSE4.2 instructions")
390 set(ENABLE_SSE ON CACHE BOOL "Enable SSE instructions for MSVC")
391 set(ENABLE_SSE2 ON CACHE BOOL "Enable SSE2 instructions for MSVC")
392 if(CMAKE_C_COMPILER MATCHES "icc")
393 set(ENABLE_SSE3 OFF CACHE BOOL "Enable SSE3 instructions for ICC")
394 set(ENABLE_SSE4_1 OFF CACHE BOOL "Enable SSE4.1 instructions for ICC")
398 # allow fine grained control over which libraries not to link, even if
399 # they are available on the system
400 # ====================================================================
401 set(WITH_PNG ON CACHE BOOL "Include PNG support")
402 set(WITH_JPEG ON CACHE BOOL "Include JPEG support")
403 set(WITH_JASPER ON CACHE BOOL "Include JPEG2K support")
404 set(WITH_TIFF ON CACHE BOOL "Include TIFF support")
405 set(WITH_OPENEXR ON CACHE BOOL "Include ILM support via OpenEXR")
408 set(WITH_FFMPEG ON CACHE BOOL "Include FFMPEG support")
410 set(WITH_UNICAP OFF CACHE BOOL "Include Unicap support (GPL)")
411 set(WITH_GTK ON CACHE BOOL "Include GTK support")
412 set(WITH_GSTREAMER ON CACHE BOOL "Include Gstreamer support")
413 set(WITH_V4L ON CACHE BOOL "Include Video 4 Linux support")
414 set(WITH_XINE OFF CACHE BOOL "Include Xine support (GPL)")
416 set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support")
417 set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support")
421 set(WITH_CARBON OFF CACHE BOOL "Use Carbon for UI instead of Cocoa")
422 set(WITH_QUICKTIME OFF CACHE BOOL "Use QuickTime for Video I/O insted of QTKit")
425 set(WITH_TBB OFF CACHE BOOL "Include Intel TBB support")
426 set(WITH_IPP OFF CACHE BOOL "Include Intel IPP support")
427 set(WITH_EIGEN ON CACHE BOOL "Include Eigen2/Eigen3 support")
428 set(WITH_CUDA ON CACHE BOOL "Include NVidia Cuda Runtime support")
430 set(WITH_OPENNI OFF CACHE BOOL "Include OpenNI support")
432 # ===================================================
433 # Macros that checks if module have been installed.
434 # After it adds module to build and define
435 # constants passed as second arg
436 # ===================================================
438 macro(CHECK_MODULE module_name define)
441 set(ALIAS ALIASOF_${module_name})
442 set(ALIAS_FOUND ${ALIAS}_FOUND)
443 set(ALIAS_INCLUDE_DIRS ${ALIAS}_INCLUDE_DIRS)
444 set(ALIAS_LIBRARY_DIRS ${ALIAS}_LIBRARY_DIRS)
445 set(ALIAS_LIBRARIES ${ALIAS}_LIBRARIES)
447 PKG_CHECK_MODULES(${ALIAS} ${module_name})
451 foreach(P "${ALIAS_INCLUDE_DIRS}")
453 list(APPEND HIGHGUI_INCLUDE_DIRS ${${P}})
457 foreach(P "${ALIAS_LIBRARY_DIRS}")
459 list(APPEND HIGHGUI_LIBRARY_DIRS ${${P}})
463 list(APPEND HIGHGUI_LIBRARIES ${${ALIAS_LIBRARIES}})
471 CHECK_MODULE(gtk+-2.0 HAVE_GTK)
472 CHECK_MODULE(gthread-2.0 HAVE_GTHREAD)
475 set(HAVE_GTHREAD FALSE)
478 CHECK_MODULE(gstreamer-base-0.10 HAVE_GSTREAMER)
479 CHECK_MODULE(gstreamer-app-0.10 HAVE_GSTREAMER)
480 CHECK_MODULE(gstreamer-video-0.10 HAVE_GSTREAMER)
482 set(HAVE_GSTREAMER FALSE)
487 CHECK_MODULE(libunicap HAVE_UNICAP_)
488 CHECK_MODULE(libucil HAVE_UNICAP_UCIL)
489 if(HAVE_UNICAP_ AND HAVE_UNICAP_UCIL)
493 set(HAVE_UNICAP FALSE)
497 find_path(PVAPI_INCLUDE_PATH "PvApi.h"
498 PATHS "/usr/local/include" "/usr/include"
499 DOC "The path to PvAPI header")
500 if(PVAPI_INCLUDE_PATH)
507 CHECK_MODULE(libavcodec HAVE_FFMPEG_CODEC)
508 CHECK_MODULE(libavformat HAVE_FFMPEG_FORMAT)
509 CHECK_MODULE(libavutil HAVE_FFMPEG_UTIL)
510 CHECK_MODULE(libswscale HAVE_FFMPEG_SWSCALE)
511 CHECK_INCLUDE_FILE(libavformat/avformat.h HAVE_GENTOO_FFMPEG)
512 CHECK_INCLUDE_FILE(ffmpeg/avformat.h HAVE_FFMPEG_FFMPEG)
513 if(NOT HAVE_GENTOO_FFMPEG AND NOT HAVE_FFMPEG_FFMPEG)
514 if(EXISTS /usr/include/ffmpeg/libavformat/avformat.h OR HAVE_FFMPEG_SWSCALE)
515 set(HAVE_GENTOO_FFMPEG 1)
518 if(HAVE_FFMPEG_CODEC AND HAVE_FFMPEG_FORMAT AND HAVE_FFMPEG_UTIL)
519 if(HAVE_FFMPEG_SWSCALE OR NOT HAVE_GENTOO_FFMPEG)
523 # Find the bzip2 library because it is required on some systems
524 FIND_LIBRARY(BZIP2_LIBRARIES NAMES bz2 bzip2)
525 if(NOT BZIP2_LIBRARIES)
527 FIND_FILE(BZIP2_LIBRARIES NAMES libbz2.so.1 PATHS /lib)
532 CHECK_MODULE(libdc1394-2 HAVE_DC1394_2)
533 if(NOT HAVE_DC1394_2)
534 CHECK_MODULE(libdc1394 HAVE_DC1394)
537 set(HAVE_DC1394_2 FALSE)
538 set(HAVE_DC1394 FALSE)
541 if(NOT OPENCV_BUILD_3RDPARTY_LIBS)
546 CHECK_INCLUDE_FILE(${PNG_PNG_INCLUDE_DIR}/png.h HAVE_PNG_H)
547 CHECK_INCLUDE_FILE(${PNG_PNG_INCLUDE_DIR}/libpng/png.h HAVE_LIBPNG_PNG_H)
555 set(TIFF_FOUND FALSE)
560 set(JASPER_FOUND FALSE)
565 set(JPEG_FOUND FALSE)
570 CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
571 CHECK_FUNCTION_EXISTS(alloca HAVE_ALLOCA)
572 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
573 CHECK_INCLUDE_FILE(pthread.h HAVE_LIBPTHREAD)
576 CHECK_MODULE(libxine HAVE_XINE)
581 CHECK_MODULE(libv4l1 HAVE_LIBV4L)
582 CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
583 CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
585 set(HAVE_LIBV4L FALSE)
586 set(HAVE_CAMV4L FALSE)
587 set(HAVE_CAMV4L2 FALSE)
591 set(OPENCV_LINKER_LIBS dl m log)
592 elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
593 set(OPENCV_LINKER_LIBS m pthread)
595 set(OPENCV_LINKER_LIBS dl m pthread rt)
598 add_definitions(-DHAVE_ALLOCA -DHAVE_ALLOCA_H -DHAVE_LIBPTHREAD -DHAVE_UNISTD_H)
602 if(WITH_PNG AND NOT PNG_FOUND)
603 set(PNG_LIBRARIES libpng)
606 if(WITH_JPEG AND NOT JPEG_FOUND)
607 set(JPEG_LIBRARIES libjpeg)
610 if(WITH_TIFF AND NOT TIFF_FOUND)
611 set(TIFF_LIBRARIES libtiff)
614 if(WITH_JASPER AND NOT JASPER_FOUND)
615 set(JASPER_LIBRARIES libjasper)
619 set(ZLIB_LIBRARY zlib)
622 #message(STATUS "Graphic libraries: ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${JASPER_LIBRARIES}")
625 include(OpenCVFindOpenEXR.cmake)
628 set(BUILD_DOCS ON CACHE BOOL "Build OpenCV Documentation")
631 include(OpenCVFindLATEX.cmake REQUIRED)
634 set(BUILD_NEW_PYTHON_SUPPORT ON CACHE BOOL "Build with Python support")
637 if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
638 set(BUILD_NEW_PYTHON_SUPPORT OFF)
643 set(BUILD_NEW_PYTHON_SUPPORT OFF)
646 # Always try to find python
647 # ===================================================
648 find_host_package(PythonInterp)
649 find_host_package(PythonLibs)
651 # cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND
652 if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH)
653 set(PYTHONLIBS_FOUND ON)
656 execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
657 ERROR_VARIABLE PYTHON_VERSION_FULL
658 OUTPUT_STRIP_TRAILING_WHITESPACE)
660 string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
662 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()"
663 RESULT_VARIABLE PYTHON_CVPY_PROCESS
664 OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH
665 OUTPUT_STRIP_TRAILING_WHITESPACE)
666 if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages")
667 set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages CACHE PATH "Where to install the python packages.")
668 else() #debian based assumed, install to the dist-packages.
669 set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages CACHE PATH "Where to install the python packages.")
673 get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE CACHE)
674 set(PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages")
677 IF ("${PYTHON_VERSION_MAJOR_MINOR}" VERSION_GREATER 2.4)
678 SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} -B)
681 # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
682 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]"
683 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
684 OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS
685 OUTPUT_STRIP_TRAILING_WHITESPACE)
687 if(PYTHON_NUMPY_PROCESS EQUAL 0)
688 set(PYTHON_USE_NUMPY 1)
689 add_definitions(-D PYTHON_USE_NUMPY=1)
690 include_directories(AFTER ${PYTHON_NUMPY_INCLUDE_DIRS})
691 message(STATUS " Use NumPy headers from: ${PYTHON_NUMPY_INCLUDE_DIRS}")
693 set(PYTHON_USE_NUMPY 0)
696 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sphinx; print sphinx.__version__"
697 RESULT_VARIABLE SPHINX_PROCESS
698 OUTPUT_VARIABLE SPHINX_VERSION
699 OUTPUT_STRIP_TRAILING_WHITESPACE)
702 if(SPHINX_PROCESS EQUAL 0)
703 find_host_program(SPHINX_BUILD sphinx-build)
706 message(STATUS " Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
711 # ===================================================
712 if (PYTHON_EXECUTABLE AND ANDROID AND ANDROID_API_LEVEL GREATER 7)
713 option(BUILD_JAVA_SUPPORT "Build with Java support" TRUE)
716 if (BUILD_JAVA_SUPPORT)
717 file(TO_CMAKE_PATH "$ENV{ANT_DIR}" ANT_DIR_ENV_PATH)
718 file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH)
721 file(TO_CMAKE_PATH "$ENV{ANDROID_SDK}" ANDROID_SDK_ENV_PATH)
724 find_host_program(ANDROID_EXECUTABLE
725 NAMES android.bat android
726 PATHS "${ANDROID_SDK_ENV_PATH}/tools/"
727 "${ProgramFiles_ENV_PATH}/Android/android-sdk/tools/"
728 "/opt/android-sdk/tools/"
729 "/opt/android-sdk-linux_x86/tools/"
730 "/opt/android-sdk-mac_x86/tools/"
731 "/opt/android-sdk-linux_86/tools/"
732 "/opt/android-sdk-mac_86/tools/"
734 if(ANDROID_EXECUTABLE)
735 message(STATUS " Found android tool: ${ANDROID_EXECUTABLE}")
737 get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH)
739 #read source.properties
740 if (EXISTS "${ANDROID_SDK_TOOLS_PATH}/source.properties")
741 file(STRINGS "${ANDROID_SDK_TOOLS_PATH}/source.properties" ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$")
742 foreach(line ${ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES})
743 string(REPLACE "\\:" ":" line ${line})
744 string(REPLACE "=" ";" line ${line})
745 list(GET line 0 line_name)
746 list(GET line 1 line_value)
747 string(REPLACE "." "_" line_name ${line_name})
748 SET(ANDROID_TOOLS_${line_name} "${line_value}")
749 MARK_AS_ADVANCED(ANDROID_TOOLS_${line_name})
752 if (NOT ANDROID_TOOLS_Pkg_Revision)
753 SET(ANDROID_TOOLS_Pkg_Revision "Unknown")
754 MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Revision)
756 if (NOT ANDROID_TOOLS_Pkg_Desc)
757 SET(ANDROID_TOOLS_Pkg_Desc "Android SDK Tools, revision ${ANDROID_TOOLS_Pkg_Revision}.")
758 if (NOT ANDROID_TOOLS_Pkg_Revision GREATER 11)
759 SET(ANDROID_TOOLS_Pkg_Desc "${ANDROID_TOOLS_Pkg_Desc} It is recommended to update your SDK tools to revision 12 or newer.")
761 MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Desc)
764 #get installed targets
765 execute_process(COMMAND ${ANDROID_EXECUTABLE} list target
766 RESULT_VARIABLE ANDROID_PROCESS
767 OUTPUT_VARIABLE ANDROID_SDK_TARGETS_FULL
768 ERROR_VARIABLE ANDROID_PROCESS_ERRORS
769 OUTPUT_STRIP_TRAILING_WHITESPACE)
770 string(REGEX MATCHALL "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" ANDROID_SDK_TARGETS_FULL "${ANDROID_SDK_TARGETS_FULL}")
772 SET(ANDROID_SDK_TARGETS)
773 if (ANDROID_PROCESS EQUAL 0)
774 foreach(line ${ANDROID_SDK_TARGETS_FULL})
775 string(REGEX REPLACE "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" "\\2" line "${line}")
776 list(APPEND ANDROID_SDK_TARGETS "${line}")
780 # detect ANDROID_SDK_TARGET if no target is provided by user
781 if (NOT ANDROID_SDK_TARGET)
782 set(desired_android_target_level ${ANDROID_API_LEVEL})
783 if (desired_android_target_level LESS 8)
784 set(desired_android_target_level 8)
786 if (ANDROID_PROCESS EQUAL 0)
787 math(EXPR desired_android_target_level_1 "${desired_android_target_level}-1")
789 foreach(target ${ANDROID_SDK_TARGETS})
790 string(REGEX MATCH "[0-9]+$" target_level "${target}")
791 if (target_level GREATER desired_android_target_level_1)
792 set(ANDROID_SDK_TARGET "${target}")
797 set(ANDROID_SDK_TARGET android-${desired_android_target_level})
798 message(WARNING "Could not retrieve list of installed Android targets. Will try to use \"${ANDROID_SDK_TARGET}\" target")
802 SET(ANDROID_SDK_TARGET ${ANDROID_SDK_TARGET} CACHE STRING "SDK target for Android tests and samples")
803 if (ANDROID_PROCESS EQUAL 0)
804 set_property( CACHE ANDROID_SDK_TARGET PROPERTY STRINGS ${ANDROID_SDK_TARGETS} )
806 string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}")
811 find_host_program(ANT_EXECUTABLE NAMES ant.bat ant
812 PATHS "${ANT_DIR_ENV_PATH}/bin"
813 "${ProgramFiles_ENV_PATH}/apache-ant/bin"
816 execute_process(COMMAND ${ANT_EXECUTABLE} -version
817 OUTPUT_VARIABLE ANT_VERSION_FULL
818 OUTPUT_STRIP_TRAILING_WHITESPACE)
819 string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" ANT_VERSION "${ANT_VERSION_FULL}")
821 message(STATUS " Found apache ant ${ANT_VERSION}: ${ANT_EXECUTABLE}")
824 if (ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_SDK_TARGET_LEVEL GREATER 7))
825 SET(CAN_BUILD_ANDROID_PROJECTS TRUE)
827 SET(CAN_BUILD_ANDROID_PROJECTS FALSE)
831 if(CAN_BUILD_ANDROID_PROJECTS)
832 SET(BUILD_ANDROID_EXAMPLES TRUE CACHE BOOL "Build examples for Android platform")
836 ############################### QT ################################
838 set(WITH_QT OFF CACHE BOOL "Build with Qt Backend support")
839 set(WITH_QT_OPENGL OFF CACHE BOOL "Add OpenGL extension to Qt")
842 set(HAVE_QT_OPENGL 0)
848 add_definitions(-DHAVE_QT)#We need to define te macro this way, using cvconfig.h.cmake does not work
849 find_package (OpenGL QUIET)
853 if (QT_QTOPENGL_FOUND AND OPENGL_FOUND)
854 set(HAVE_QT_OPENGL 1)
855 add_definitions(-DHAVE_QT_OPENGL)
856 #link_directories("${OPENGL_LIBRARIES}")
857 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES})
864 ############################### TBB ################################
867 if (UNIX AND NOT APPLE AND NOT ANDROID)
868 PKG_CHECK_MODULES(TBB tbb)
872 if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "")
873 include_directories(${TBB_INCLUDE_DIRS})
875 link_directories(${TBB_LIBRARY_DIRS})
876 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES})
881 set(TBB_DEFAULT_INCLUDE_DIRS "/opt/intel/tbb" "/usr/local/include" "/usr/include" "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB" "C:/Program Files (x86)/TBB" "${CMAKE_INSTALL_PREFIX}/include")
883 find_path(TBB_INCLUDE_DIR "tbb/tbb.h" PATHS ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers")
886 set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory")
887 link_directories("${TBB_LIB_DIR}")
890 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib)
892 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbbmalloc tbb)
893 add_definitions(-DTBB_USE_GCC_BUILTINS)
895 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
897 if (CMAKE_COMPILER_IS_GNUCXX)
898 set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory")
899 link_directories("${TBB_LIB_DIR}")
900 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
902 get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIR}/../lib" ABSOLUTE)
904 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*|x86_64* OR MSVC64)
905 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/intel64")
906 elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86*|i386*|i686*)
907 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/ia32")
911 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8")
913 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9")
915 set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10")
917 set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory")
918 link_directories("${TBB_LIB_DIR}")
923 if(NOT "${TBB_INCLUDE_DIR}" STREQUAL "")
924 include_directories("${TBB_INCLUDE_DIR}")
930 #Threading Framework -- temporary decision for ARM-s instead of TBB
932 file(GLOB THREADING_FRAMEWORK_HEADER "${OpenCV_SOURCE_DIR}/modules/core/include/opencv2/core/threading_framework.hpp")
933 file(GLOB THREADING_FRAMEWORK_SOURCE "${OpenCV_SOURCE_DIR}/modules/core/src/threading_framework.cpp")
934 if(THREADING_FRAMEWORK_HEADER AND THREADING_FRAMEWORK_SOURCE)
935 set(HAVE_THREADING_FRAMEWORK 1)
939 ############################ Intel IPP #############################
943 include(OpenCVFindIPP.cmake)
947 add_definitions(-DHAVE_IPP)
948 include_directories(${IPP_INCLUDE_DIRS})
949 link_directories(${IPP_LIBRARY_DIRS})
950 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_LIBRARIES})
954 ############################### CUDA ################################
957 find_package(CUDA 4.0)
961 message(STATUS "CUDA detected: " ${CUDA_VERSION})
963 set(CUDA_ARCH_BIN "1.1 1.2 1.3 2.0 2.1(2.0)" CACHE STRING "Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported")
964 set(CUDA_ARCH_PTX "2.0" CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for")
966 string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}")
967 string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}")
969 # Ckeck if user specified 1.0 compute capability: we don't support it
970 string(REGEX MATCH "1.0" HAS_ARCH_10 "${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}")
971 set(CUDA_ARCH_BIN_OR_PTX_10 0)
972 if(NOT ${HAS_ARCH_10} STREQUAL "")
973 set(CUDA_ARCH_BIN_OR_PTX_10 1)
976 # NVCC flags to be set
977 set(NVCC_FLAGS_EXTRA "")
979 # These vars will be passed into the templates
980 set(OPENCV_CUDA_ARCH_BIN "")
981 set(OPENCV_CUDA_ARCH_PTX "")
982 set(OPENCV_CUDA_ARCH_FEATURES "")
984 # Tell NVCC to add binaries for the specified GPUs
985 string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}")
986 foreach(ARCH IN LISTS ARCH_LIST)
987 if (ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
988 # User explicitly specified PTX for the concrete BIN
989 set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
990 set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}")
991 set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}")
993 # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
994 set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=sm_${ARCH})
995 set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}")
996 set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
1000 # Tell NVCC to add PTX intermediate code for the specified architectures
1001 string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}")
1002 foreach(ARCH IN LISTS ARCH_LIST)
1003 set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=compute_${ARCH})
1004 set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}")
1005 set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}")
1008 # These vars will be processed in other scripts
1009 set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA})
1010 set(OpenCV_CUDA_CC "${NVCC_FLAGS_EXTRA}")
1012 message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}")
1014 unset(CUDA_ARCH_BIN CACHE)
1015 unset(CUDA_ARCH_PTX CACHE)
1020 ############################### OpenNI ################################
1021 set(HAVE_OPENNI FALSE)
1022 set(HAVE_OPENNI_PRIME_SENSOR_MODULE FALSE)
1025 include(OpenCVFindOpenNI.cmake)
1028 ############################## Eigen ##############################
1031 find_path(EIGEN_INCLUDE_PATH "Eigen/Core"
1032 PATHS "/usr/local/include/eigen2" "/opt/include/eigen2" "/usr/include/eigen2"
1033 "/usr/local/include/eigen3" "/opt/include/eigen3" "/usr/include/eigen3"
1034 DOC "The path to Eigen2/Eigen3 headers")
1035 if(EIGEN_INCLUDE_PATH)
1036 include_directories(${EIGEN_INCLUDE_PATH})
1042 ################## Extra HighGUI libs on Windows ###################
1045 set(WITH_VIDEOINPUT ON CACHE BOOL "Build HighGUI with DirectShow support")
1046 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} comctl32 gdi32 ole32)
1049 set(HAVE_VIDEOINPUT 1)
1053 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32)
1058 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} msvfw32 avifil32 avicap32 winmm)
1060 set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32 winmm)
1065 ############## Android source tree for native camera ###############
1066 if(ANDROID AND ANDROID_API_LEVEL GREATER 7)
1067 option(WITH_ANDROID_CAMERA "Build with native Android camera support" TRUE)
1069 SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH
1070 "Path to Android source tree.
1071 Set this variable to path to your Android sources to compile
1072 libnative_camera_rx.x.x.so for your Android")
1073 SET(BUILD_ANDROID_CAMERA_WRAPPER OFF)
1074 if (ANDROID_SOURCE_TREE)
1075 FILE(STRINGS "${ANDROID_SOURCE_TREE}/development/sdk/platform_source.properties" ANDROID_VERSION REGEX "Platform\\.Version=[0-9]+\\.[0-9]+\\.[0-9]+" )
1076 string(REGEX REPLACE "Platform\\.Version=([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" ANDROID_VERSION "${ANDROID_VERSION}")
1077 if(NOT "${ANDROID_VERSION}" STREQUAL "")
1078 SET(BUILD_ANDROID_CAMERA_WRAPPER ON)
1081 MARK_AS_ADVANCED(ANDROID_SOURCE_TREE)
1084 # ----------------------------------------------------------------------------
1085 # UPDATE CONFIG FILES & SCRIPTS:
1087 # CONFIGURE_FILE(InputFile OutputFile [COPYONLY] [ESCAPE_QUOTES] [@ONLY])
1088 # If @ONLY is specified, only variables of the form @VAR@ will be
1089 # replaces and ${VAR} will be ignored.
1091 # A directory will be created for each platform so the "cvconfig.h" file is
1092 # not overwritten if cmake generates code in the same path.
1093 # ----------------------------------------------------------------------------
1094 add_definitions(-DHAVE_CVCONFIG_H)
1096 set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h")
1098 message(STATUS "Parsing 'cvconfig.h.cmake'")
1099 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cvconfig.h.cmake" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h")
1101 # ---------------------------------------------------------------------------
1102 # The C+//0 include & link directories:
1103 # ---------------------------------------------------------------------------
1104 include_directories("."
1105 "${OPENCV_CONFIG_FILE_INCLUDE_DIR}"
1106 "${CMAKE_CURRENT_SOURCE_DIR}/include"
1107 "${CMAKE_CURRENT_SOURCE_DIR}/include/opencv"
1110 # ----------------------------------------------------------------------------
1111 # Set the maximum level of warnings:
1112 # ----------------------------------------------------------------------------
1113 # Should be set to true for development
1114 set(OPENCV_WARNINGS_ARE_ERRORS OFF CACHE BOOL "Treat warnings as errors")
1115 if (WIN32 AND ${CMAKE_GENERATOR} MATCHES "(MinGW)|(MSYS)")
1116 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "")
1119 set(EXTRA_C_FLAGS "")
1120 set(EXTRA_C_FLAGS_RELEASE "")
1121 set(EXTRA_C_FLAGS_DEBUG "")
1122 set(EXTRA_EXE_LINKER_FLAGS "")
1123 set(EXTRA_EXE_LINKER_FLAGS_RELEASE "")
1124 set(EXTRA_EXE_LINKER_FLAGS_DEBUG "")
1127 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS")
1128 # 64-bit portability warnings, in MSVC8
1130 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /Wp64")
1133 # set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /D _BIND_TO_CURRENT_CRT_VERSION=1 /D _BIND_TO_CURRENT_VCLIBS_VERSION=1")
1136 if(BUILD_WITH_DEBUG_INFO)
1137 set(EXTRA_EXE_LINKER_FLAGS_RELEASE "${EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug")
1140 # Remove unreferenced functions: function level linking
1141 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /Gy")
1142 if(BUILD_WITH_DEBUG_INFO)
1143 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /Zi")
1147 if(CMAKE_COMPILER_IS_GNUCXX)
1148 # High level of warnings.
1149 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
1151 # The -Wno-long-long is required in 64bit systems when including sytem headers.
1153 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long")
1157 if(UNIX AND NOT ANDROID)
1158 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -pthread")
1161 if(OPENCV_WARNINGS_ARE_ERRORS)
1162 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
1165 if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE)
1166 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -march=i686")
1169 # Other optimizations
1170 if(USE_OMIT_FRAME_POINTER)
1171 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
1174 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
1177 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
1180 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse")
1183 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse2")
1185 # SSE3 and further should be disabled under MingW because it generates compiler errors
1188 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse3")
1191 if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402)
1192 set(HAVE_GCC43_OR_NEWER 1)
1194 if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401)
1195 set(HAVE_GCC42_OR_NEWER 1)
1198 if(HAVE_GCC42_OR_NEWER OR APPLE)
1200 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mssse3")
1202 if(HAVE_GCC43_OR_NEWER)
1204 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse4.1")
1207 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse4.2")
1214 if(NOT APPLE AND ${CMAKE_SIZEOF_VOID_P} EQUAL 4)
1215 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mfpmath=387")
1220 if(ENABLE_PROFILING)
1221 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
1223 # Remove unreferenced functions: function level linking
1224 set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
1227 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -DNDEBUG")
1228 set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG")
1229 if(BUILD_WITH_DEBUG_INFO)
1230 set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -ggdb3")
1235 # 64-bit MSVC compiler uses SSE/SSE2 by default
1238 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE")
1241 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE2")
1245 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE3")
1248 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1")
1250 if (ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1)
1251 set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} /Oi")
1255 # Extra link libs if the user selects building static libs:
1256 if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
1257 # Android does not need these settings because they are already set by toolchain file
1258 set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)
1259 set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}")
1262 # Add user supplied extra options (optimization, etc...)
1263 # ==========================================================
1264 set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS}" CACHE STRING "Extra compiler options")
1265 set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE}" CACHE STRING "Extra compiler options for Release build")
1266 set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG}" CACHE STRING "Extra compiler options for Debug build")
1267 set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}" CACHE STRING "Extra linker flags" FORCE)
1268 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Extra linker flags for Release build" FORCE)
1269 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "Extra linker flags for Debug build" FORCE)
1271 #combine all "extra" options
1272 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
1273 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
1274 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}")
1275 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}")
1276 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}")
1277 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}")
1278 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_FLAGS}")
1279 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${EXTRA_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}")
1280 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${EXTRA_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}")
1282 # In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release:
1283 if (${CMAKE_GENERATOR} MATCHES ".*Makefiles" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
1284 set(CMAKE_BUILD_TYPE Release)
1288 # avoid warnings from MSVC about overriding the /W* option
1289 # we replace /W3 with /W4 only for C++ files,
1290 # since all the 3rd-party libraries OpenCV uses are in C,
1291 # and we do not care about their warnings.
1292 string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1293 string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
1294 string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
1296 # allow extern "C" functions throw exceptions
1297 string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1298 string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
1299 string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
1300 string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1301 string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
1302 string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
1304 string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
1305 string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1308 if("${CMAKE_CONFIGURE_LDFLAGS}")
1309 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CONFIGURE_LDFLAGS}")
1310 endif("${CMAKE_CONFIGURE_LDFLAGS}")
1312 # --------------------------------------------------------------------------------------------
1313 # Installation for CMake Module: OpenCVConfig.cmake
1314 # Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install"
1315 # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use with "make install"
1316 # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
1317 # -------------------------------------------------------------------------------------------
1319 # -------------------------------------------------------------------------------------------
1320 # Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install"
1321 # -------------------------------------------------------------------------------------------
1322 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"")
1323 set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "${CMAKE_CURRENT_SOURCE_DIR}")
1324 set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}")
1325 set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1327 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)
1328 #support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
1329 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
1330 # --------------------------------------------------------------------------------------------
1331 # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
1332 # -------------------------------------------------------------------------------------------
1333 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"")
1335 set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "")
1337 set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ARMEABI_NDK_NAME}\"")
1338 set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ARMEABI_NDK_NAME}\"")
1340 set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
1341 set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1342 if(OPENCV_MANGLED_INSTALL_PATHS)
1343 set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV-${OPENCV_VERSION}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1347 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
1348 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
1351 #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference
1352 # For a command "find_package(<name> [major[.minor]] [EXACT] [REQUIRED|QUIET])"
1353 # cmake will look in the following dir on unix:
1354 # <prefix>/(share|lib)/cmake/<name>*/ (U)
1355 # <prefix>/(share|lib)/<name>*/ (U)
1356 # <prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)
1357 if(OPENCV_MANGLED_INSTALL_PATHS)
1358 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/)
1359 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/)
1361 install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION share/OpenCV/)
1362 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV/)
1367 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV)
1370 # --------------------------------------------------------------------------------------------
1371 # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
1372 # -------------------------------------------------------------------------------------------
1374 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
1375 set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "")
1376 set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
1377 set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
1379 exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
1380 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
1382 # Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory
1383 install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/")
1386 # --------------------------------------------------------------------------------------------
1387 # Installation for Android ndk-build makefile: OpenCV.mk
1388 # Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install"
1389 # Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install"
1390 # -------------------------------------------------------------------------------------------
1392 if(BUILD_SHARED_LIBS)
1393 SET(OPENCV_LIBTYPE_CONFIGMAKE "SHARED")
1395 SET(OPENCV_LIBTYPE_CONFIGMAKE "STATIC")
1397 if(BUILD_ANDROID_CAMERA_WRAPPER)
1398 set(CMAKE_CAMERA_LIBS_CONFIGCMAKE "native_camera_r${ANDROID_VERSION}")
1399 elseif(WITH_ANDROID_CAMERA)
1400 SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "")
1401 file(GLOB CMAKE_CAMERA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lib/${ARMEABI_NDK_NAME}/libnative_camera_r*.so")
1402 foreach(cam_lib ${CMAKE_CAMERA_LIBS})
1403 get_filename_component(cam_lib "${cam_lib}" NAME)
1404 string(REGEX REPLACE "lib(native_camera_r[0-9]+\\.[0-9]+\\.[0-9]+)\\.so" "\\1" cam_lib "${cam_lib}")
1405 SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "${CMAKE_CAMERA_LIBS_CONFIGCMAKE} ${cam_lib}")
1410 # -------------------------------------------------------------------------------------------
1411 # Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install"
1412 # -------------------------------------------------------------------------------------------
1414 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"")
1415 set(CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE "\"${CMAKE_CURRENT_SOURCE_DIR}\"")
1416 set(CMAKE_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)")
1418 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY)
1421 # -------------------------------------------------------------------------------------------
1422 # Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install"
1423 # -------------------------------------------------------------------------------------------
1425 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include/opencv\" \"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include\"")
1426 set(CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE "")
1427 set(CMAKE_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../..")
1429 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY)
1430 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION share/OpenCV/)
1433 # --------------------------------------------------------------------------------------------
1434 #according to man pkg-config
1435 # The package name specified on the pkg-config command line is defined to
1436 # be the name of the metadata file, minus the .pc extension. If a library
1437 # can install multiple versions simultaneously, it must give each version
1438 # its own name (for example, GTK 1.2 might have the package name "gtk+"
1439 # while GTK 2.0 has "gtk+-2.0").
1440 # Part 2/2: ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install"
1442 # exec_prefix=${prefix}
1443 # libdir=${exec_prefix}/lib
1444 # includedir=${prefix}/include/opencv
1445 # -------------------------------------------------------------------------------------------
1446 set(prefix ${CMAKE_INSTALL_PREFIX})
1447 set(exec_prefix "\${prefix}")
1448 set(libdir "\${exec_prefix}/lib")
1449 set(includedir "\${prefix}/${OPENCV_INCLUDE_PREFIX}")
1450 set(VERSION ${OPENCV_VERSION})
1452 set(OPENCV_PC_FILE_NAME opencv.pc)
1453 #need to be explicit with naming the pc file and version number for side by side installs to work.
1454 if(OPENCV_MANGLED_INSTALL_PATHS)
1455 SET(OpenCV_LIB_COMPONENTS opencv_contrib opencv_legacy opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core )
1456 #be explicit about the library names.
1457 set(OpenCV_LIB_COMPONENTS_ )
1458 foreach( CVLib ${OpenCV_LIB_COMPONENTS})
1459 set(OpenCV_LIB_COMPONENTS_ "${OpenCV_LIB_COMPONENTS_} ${libdir}/lib${CVLib}.so.${OPENCV_VERSION}" )
1461 set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_})
1462 set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc")
1463 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/opencv-XXX.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE)
1465 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/opencv.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE)
1468 if(UNIX AND NOT ANDROID)
1469 install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig)
1472 # ----------------------------------------------------------------------------
1473 # Uninstall target, for "make uninstall"
1474 # ----------------------------------------------------------------------------
1476 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1477 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1480 ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
1482 #-----------------------------------
1484 #-----------------------------------
1485 set(BUILD_PACKAGE ON CACHE BOOL "Enables 'make package_source' command")
1488 set(TARBALL_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
1490 add_custom_target(package_source
1491 #TODO: maybe we should not remove dll's
1492 COMMAND tar --transform 's,^,${TARBALL_NAME}/,S' -cjpf ${CMAKE_CURRENT_BINARY_DIR}/${TARBALL_NAME}.tar.bz2 --exclude-vcs --exclude="*.pyc" --exclude="*.vcproj" --exclude="*/lib/*" --exclude="*.dll" ./
1493 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1495 add_custom_target(package_source
1496 COMMAND zip -9 -r ${CMAKE_CURRENT_BINARY_DIR}/${TARBALL_NAME}.zip . -x '*/.svn/*' '*.vcproj' '*.pyc'
1497 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1502 #-----------------------------------
1504 #-----------------------------------
1506 if(${CMAKE_VERSION} VERSION_GREATER "2.8.0")
1507 set(ENABLE_SOLUTION_FOLDERS OFF CACHE BOOL "Solution folder in Visual Studio or in other IDEs")
1510 if(ENABLE_SOLUTION_FOLDERS)
1511 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1512 set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
1515 #-----------------------------------
1517 #-----------------------------------
1518 add_subdirectory(include)
1519 add_subdirectory(modules)
1520 add_subdirectory(doc)
1521 add_subdirectory(data)
1522 add_subdirectory(3rdparty)
1524 if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES)
1525 add_subdirectory(samples)
1528 # ----------------------------------------------------------------------------
1530 # ----------------------------------------------------------------------------
1536 SET(status_current_name "cond")
1537 foreach(arg ${ARGN})
1538 if(arg STREQUAL "THEN")
1539 SET(status_current_name "then")
1540 elseif(arg STREQUAL "ELSE")
1541 SET(status_current_name "else")
1543 LIST(APPEND status_${status_current_name} ${arg})
1547 if(DEFINED status_cond)
1548 SET(status_placeholder_length 32)
1549 string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
1550 string(LENGTH "${text}" status_text_length)
1551 if (status_text_length LESS status_placeholder_length)
1552 string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
1553 elseif (DEFINED status_then OR DEFINED status_else)
1554 message(STATUS "${text}")
1555 SET(status_text "${status_placeholder}")
1557 SET(status_text "${text}")
1560 if (DEFINED status_then OR DEFINED status_else)
1562 string(REPLACE ";" " " status_then "${status_then}")
1563 message(STATUS "${status_text}" "${status_then}")
1565 string(REPLACE ";" " " status_else "${status_else}")
1566 message(STATUS "${status_text}" "${status_else}")
1569 string(REPLACE ";" " " status_cond "${status_cond}")
1570 message(STATUS "${status_text}" "${status_cond}")
1573 message(STATUS "${text}")
1578 status("General configuration for opencv ${OPENCV_VERSION} =====================================")
1580 status(" Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO)
1581 status(" Compiler:" CMAKE_COMPILER THEN "${CMAKE_COMPILER}" ELSE "${CMAKE_CXX_COMPILER}")
1582 status(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
1583 status(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
1585 status(" Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
1586 status(" Linker flags (Debug):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
1588 status(" Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
1589 status(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
1593 status(" Floating point type:" ${ARM_TARGET})
1594 status(" Native API level:" android-${ANDROID_API_LEVEL})
1595 status(" SDK target:" "${ANDROID_SDK_TARGET}")
1603 status(" QT 4.x:" HAVE_QT THEN YES ELSE NO)
1604 status(" QT OpenGL support:" HAVE_QT_OPENGL THEN YES ELSE NO)
1607 status(" Win32 UI:" YES)
1611 status(" Carbon:" YES)
1613 status(" Cocoa:" YES)
1616 status(" GTK+ 2.x:" HAVE_GTK THEN YES ELSE NO)
1617 status(" GThread:" HAVE_GTHREAD THEN YES ELSE NO)
1624 status(" Media I/O: ")
1625 status(" ZLib:" ZLIB_FOUND THEN YES ELSE build)
1626 status(" JPEG:" NOT WITH_JPEG OR JPEG_FOUND THEN ${JPEG_FOUND} ELSE build)
1627 status(" PNG:" NOT WITH_PNG OR PNG_FOUND THEN ${PNG_FOUND} ELSE build)
1628 status(" TIFF:" NOT WITH_TIFF OR TIFF_FOUND THEN ${TIFF_FOUND} ELSE build)
1629 status(" JPEG 2000:" NOT WITH_JASPER OR JASPER_FOUND THEN ${JASPER_FOUND} ELSE build)
1630 status(" OpenEXR:" WITH_OPENEXR AND OPENEXR_FOUND THEN YES ELSE NO)
1632 status(" OpenNI:" HAVE_OPENNI AND HAVE_OPENNI_PRIME_SENSOR_MODULE THEN YES ELSE NO)
1636 if(UNIX AND NOT APPLE)
1637 status(" Video I/O:")
1638 status(" DC1394 1.x:" HAVE_DC1394 THEN YES ELSE NO)
1639 status(" DC1394 2.x:" HAVE_DC1394_2 THEN YES ELSE NO)
1640 status(" FFMPEG:" HAVE_FFMPEG THEN YES ELSE NO)
1641 status(" codec:" HAVE_FFMPEG_CODEC THEN YES ELSE NO)
1642 status(" format:" HAVE_FFMPEG_FORMAT THEN YES ELSE NO)
1643 status(" util:" HAVE_FFMPEG_UTIL THEN YES ELSE NO)
1644 status(" swscale:" HAVE_FFMPEG_SWSCALE THEN YES ELSE NO)
1645 status(" gentoo-style:" HAVE_GENTOO_FFMPEG THEN YES ELSE NO)
1646 status(" GStreamer:" HAVE_GSTREAMER THEN YES ELSE NO)
1647 status(" UniCap:" HAVE_UNICAP THEN YES ELSE NO)
1648 status(" PvAPI:" HAVE_PVAPI THEN YES ELSE NO)
1649 status(" V4L/V4L2:" HAVE_LIBV4L THEN Using libv4l ELSE ${HAVE_CAMV4L}/${HAVE_CAMV4L2})
1650 status(" Xine:" HAVE_XINE THEN YES ELSE NO)
1653 if(WITH_ANDROID_CAMERA)
1654 status(" AndroidNativeCamera:" BUILD_ANDROID_CAMERA_WRAPPER THEN "build for Android ${ANDROID_VERSION}" ELSE "use prebuilt libraries")
1656 status(" AndroidNativeCamera:" "NO (native camera requires Android API level 8 or higher)")
1660 status(" Video I/O:" WITH_QUICKTIME THEN QuickTime ELSE QTKit)
1662 status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO)
1665 # Other third-party libraries
1667 status(" Other third-party libraries:")
1669 if(WITH_IPP AND IPP_FOUND)
1670 status(" Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]")
1671 status(" at:" "${IPP_ROOT_DIR}")
1673 status(" Use IPP:" WITH_IPP AND NOT IPP_FOUND THEN IPP not found ELSE NO)
1676 status(" Use TBB:" HAVE_TBB THEN YES ELSE NO)
1679 status(" Use ThreadingFramework:" HAVE_THREADING_FRAMEWORK THEN YES ELSE NO)
1682 status(" Use Cuda:" HAVE_CUDA THEN YES ELSE NO)
1683 status(" Use Eigen:" HAVE_EIGEN THEN YES ELSE NO)
1685 # interfaces to other languages
1687 status(" Interfaces:")
1688 status(" Python:" BUILD_NEW_PYTHON_SUPPORT THEN YES ELSE NO)
1689 status(" Python interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO)
1690 status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python wrappers will not be generated)")
1691 if(ANDROID AND ANDROID_API_LEVEL LESS 8)
1692 status(" Java:" "NO (Java API requires Android API level 8 or higher)")
1694 status(" Java:" BUILD_JAVA_SUPPORT THEN YES ELSE NO)
1698 status(" android tool:" ANDROID_EXECUTABLE THEN "${ANDROID_EXECUTABLE} (${ANDROID_TOOLS_Pkg_Desc})" ELSE NO)
1699 status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO)
1704 status(" Documentation:")
1705 status(" Sphinx:" HAVE_SPHINX THEN "${SPHINX_BUILD} (ver ${SPHINX_VERSION})" ELSE NO)
1706 status(" PdfLaTeX compiler:" PDFLATEX_COMPILER THEN "${PDFLATEX_COMPILER}" ELSE NO)
1707 if (BUILD_DOCS AND HAVE_SPHINX)
1708 status(" Build Documentation:" PDFLATEX_COMPILER THEN YES ELSE "YES (only HTML without math formulas)")
1710 status(" Build Documentation:" NO)
1715 status(" Tests and samples:")
1716 status(" Tests:" BUILD_TESTS THEN YES ELSE NO)
1717 status(" Examples:" BUILD_EXAMPLES THEN YES ELSE NO)
1720 status(" Android tests:" BUILD_TESTS AND CAN_BUILD_ANDROID_PROJECTS THEN YES ELSE NO)
1721 status(" Android examples:" BUILD_ANDROID_EXAMPLES THEN YES ELSE NO)
1726 status(" Install path:" "${CMAKE_INSTALL_PREFIX}")
1728 status(" cvconfig.h is in:" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}")
1729 status("-----------------------------------------------------------------")
1732 # warn in the case of in-source build
1733 if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
1734 message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree")