diff --git a/CMakeLists.txt b/CMakeLists.txt index 22c1f00a57..ba47b0adc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,44 +17,45 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) # Run "cmake --help-policy CMP0003" for more information. # -------------------------------------------------------------- if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) + cmake_policy(SET CMP0003 NEW) endif() # Following block can broke build in case of cross-compilng # but CMAKE_CROSSCOMPILING variable will be set only on project(OpenCV) command # so we will try to detect crosscompiling by presense of CMAKE_TOOLCHAIN_FILE if(NOT CMAKE_TOOLCHAIN_FILE) - # Add these standard paths to the search paths for FIND_LIBRARY - # to find libraries from these locations first - if(UNIX) - set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib) - endif() + # Add these standard paths to the search paths for FIND_LIBRARY + # to find libraries from these locations first + if(UNIX) + set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib) + endif() - # it _must_ go before PROJECT(OpenCV) in order to work - if(WIN32) - set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") - else() - set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory") - endif() + # it _must_ go before project(OpenCV) in order to work + if(WIN32) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") + else() + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory") + endif() - if(MSVC) - set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) - endif() + if(MSVC) + set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) + endif() endif(NOT CMAKE_TOOLCHAIN_FILE) # -------------------------------------------------------------- # Top level OpenCV project # -------------------------------------------------------------- if(NOT IOS) - cmake_minimum_required(VERSION 2.6.3) + cmake_minimum_required(VERSION 2.6.3) else() - cmake_minimum_required(VERSION 2.8) + cmake_minimum_required(VERSION 2.8) endif() + project(OpenCV) set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE) if(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8") - set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} ) endif() set(CMAKE_C_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE) @@ -67,6 +68,7 @@ set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE) set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "" CACHE INTERNAL "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "" CACHE INTERNAL "" FORCE) + set(CMAKE_VERBOSE OFF CACHE BOOL "Verbose mode") if(CMAKE_VERBOSE) set(CMAKE_VERBOSE_MAKEFILE 1) @@ -75,81 +77,14 @@ endif() include(cmake/OpenCVUtils.cmake REQUIRED) # ---------------------------------------------------------------------------- -# Detect Microsoft compiler: -# ---------------------------------------------------------------------------- -if(CMAKE_CL_64) - set(MSVC64 1) -endif() - +# Detect compiler and target platform architecture # ---------------------------------------------------------------------------- -# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ): -# see include/opencv/cxtypes.h file for related ICC & CV_ICC defines. -# NOTE: The system needs to determine if the '-fPIC' option needs to be added -# for the 3rdparty static libs being compiled. The CMakeLists.txt files -# in 3rdparty use the CV_ICC definition being set here to determine if -# the -fPIC flag should be used. -# ---------------------------------------------------------------------------- -if(UNIX) - if (__ICL) - set(CV_ICC __ICL) - elseif(__ICC) - set(CV_ICC __ICC) - elseif(__ECL) - set(CV_ICC __ECL) - elseif(__ECC) - set(CV_ICC __ECC) - elseif(__INTEL_COMPILER) - set(CV_ICC __INTEL_COMPILER) - elseif(CMAKE_C_COMPILER MATCHES "icc") - set(CV_ICC icc_matches_c_compiler) - endif() -endif() +include(cmake/OpenCVDetectCXXCompiler.cmake REQUIRED) -if(MSVC AND CMAKE_C_COMPILER MATCHES "icc") - set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS) -endif() # ---------------------------------------------------------------------------- -# Detect GNU version: +# OpenCV cmake options # ---------------------------------------------------------------------------- -if(CMAKE_COMPILER_IS_GNUCXX) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version - OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v - ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL - OUTPUT_STRIP_TRAILING_WHITESPACE) - - # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)" - # Look for the version number - string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}") - - # Split the three parts: - string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}") - - list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR) - list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR) - - set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR}) - math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}") - message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})") - - if(WIN32) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine - OUTPUT_VARIABLE CMAKE_OPENCV_GCC_TARGET_MACHINE - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(CMAKE_OPENCV_GCC_TARGET_MACHINE MATCHES "64") - set(MINGW64 1) - endif() - endif() -endif() - -if(CMAKE_SYSTEM_PROCESSOR MATCHES amd64.*|x86_64.*) - set(X86_64 1) -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES i686.*|i386.*|x86.*) - set(X86 1) -endif() # Optional 3rd party components # =================================================== @@ -212,7 +147,7 @@ endif() OCV_OPTION(INSTALL_C_EXAMPLES "Install C examples" OFF ) OCV_OPTION(INSTALL_PYTHON_EXAMPLES "Install Python examples" OFF ) OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples" OFF IF ANDROID ) -OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT IOS) ) +OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT IOS AND BUILD_SHARED_LIBS) ) # OpenCV build options # =================================================== @@ -230,49 +165,24 @@ OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF ) + # ---------------------------------------------------------------------------- # Get actual OpenCV version number from sources # ---------------------------------------------------------------------------- -SET(OPENCV_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/modules/core/include/opencv2/core/version.hpp") -FILE(STRINGS "${OPENCV_VERSION_FILE}" OPENCV_VERSION_PARTS REGEX "#define CV_.+OR_VERSION[ ]+[0-9]+" ) -string(REGEX REPLACE ".+CV_MAJOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MAJOR "${OPENCV_VERSION_PARTS}") -string(REGEX REPLACE ".+CV_MINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MINOR "${OPENCV_VERSION_PARTS}") -string(REGEX REPLACE ".+CV_SUBMINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_PATCH "${OPENCV_VERSION_PARTS}") -set(OPENCV_VERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}") +include(cmake/OpenCVVersion.cmake REQUIRED) -set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}") - -# create a dependency on version file -# we never use output of the following command but cmake will rerun if version file changes -configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY) - -if(WIN32) - # Postfix of DLLs: - set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}") - set(OPENCV_DEBUG_POSTFIX d) -else() - # Postfix of so's: - set(OPENCV_DLLVERSION "") - set(OPENCV_DEBUG_POSTFIX) -endif() -#name mangling -set(OPENCV_INCLUDE_PREFIX include) -if(INSTALL_TO_MANGLED_PATHS AND BUILD_SHARED_LIBS) - SET(OPENCV_MANGLED_INSTALL_PATHS ${INSTALL_TO_MANGLED_PATHS} ) - if(OPENCV_MANGLED_INSTALL_PATHS) - set(OPENCV_INCLUDE_PREFIX include/opencv-${OPENCV_VERSION}) - endif() -endif() +# ---------------------------------------------------------------------------- +# Build & install layouts +# ---------------------------------------------------------------------------- -# SUBDIRECTORIES: # Save libs and executables in the same place set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Output directory for libraries" ) set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Output directory for applications" ) if(ANDROID OR WIN32) set(OPENCV_DOC_INSTALL_PATH doc) -elseif(OPENCV_MANGLED_INSTALL_PATHS) +elseif(INSTALL_TO_MANGLED_PATHS) set(OPENCV_DOC_INSTALL_PATH share/OpenCV-${OPENCV_VERSION}/doc) else() set(OPENCV_DOC_INSTALL_PATH share/OpenCV/doc) @@ -287,83 +197,23 @@ endif() set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +# ---------------------------------------------------------------------------- +# Path for build/platform -specific headers +# ---------------------------------------------------------------------------- +set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h") +add_definitions(-DHAVE_CVCONFIG_H) +include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR}) + + # ---------------------------------------------------------------------------- # Use statically or dynamically linked CRT? # Default: dynamic # ---------------------------------------------------------------------------- if(MSVC) - if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT) - foreach(flag_var - CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif() - if(${flag_var} MATCHES "/MDd") - string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}") - endif() - endforeach(flag_var) - - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib") - set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib") - else() - foreach(flag_var - CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MT") - string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}") - endif() - if(${flag_var} MATCHES "/MTd") - string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}") - endif() - endforeach(flag_var) - endif() - - if(NOT ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8 AND NOT ${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} LESS 8.6) - include(ProcessorCount) - ProcessorCount(N) - if(NOT N EQUAL 0) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${N} ") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${N} ") - endif() - endif() - - if(NOT BUILD_WITH_DEBUG_INFO) - string(REPLACE "/debug" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - string(REPLACE "/DEBUG" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - - string(REPLACE "/debug" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") - string(REPLACE "/DEBUG" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") - string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") - string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") - - string(REPLACE "/debug" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") - string(REPLACE "/DEBUG" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") - string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") - string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") - - string(REPLACE "/Zi" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - endif() - + include(cmake/OpenCVCRTLinkage.cmake REQUIRED) endif(MSVC) -# ---------------------------------------------------------------------------- -# Variables for cvconfig.h.cmake -# ---------------------------------------------------------------------------- -set(PACKAGE "opencv") -set(PACKAGE_BUGREPORT "opencvlibrary-devel@lists.sourceforge.net") -set(PACKAGE_NAME "opencv") -set(PACKAGE_STRING "${PACKAGE} ${OPENCV_VERSION}") -set(PACKAGE_TARNAME "${PACKAGE}") -set(PACKAGE_VERSION "${OPENCV_VERSION}") # ---------------------------------------------------------------------------- # Autodetect if we are in a SVN repository @@ -387,25 +237,30 @@ else() set(OPENCV_SVNVERSION "") endif() + # ---------------------------------------------------------------------------- # CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC.. # ---------------------------------------------------------------------------- +if(UNIX) + include(cmake/OpenCVFindPkgConfig.cmake OPTIONAL) + include(CheckFunctionExists) + include(CheckIncludeFile) +endif() include(cmake/OpenCVPCHSupport.cmake REQUIRED) include(cmake/OpenCVModule.cmake REQUIRED) if(ANDROID) - include(cmake/OpenCVAndroidProject.cmake REQUIRED) + include(cmake/OpenCVAndroidProject.cmake REQUIRED) endif() -if(UNIX) - include(cmake/OpenCVFindPkgConfig.cmake OPTIONAL) - include(CheckFunctionExists) - include(CheckIncludeFile) -endif() -set(HAVE_OPENGL 0) +# ---------------------------------------------------------------------------- +# Detect 3rd-party tools and libraries +# ---------------------------------------------------------------------------- +#Graphic libraries +set(HAVE_OPENGL 0) if(UNIX) if(NOT APPLE) if(WITH_GTK) @@ -576,918 +431,211 @@ endif() #message(STATUS "Graphic libraries: ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${JASPER_LIBRARIES}") if(WITH_OPENEXR) - include(cmake/OpenCVFindOpenEXR.cmake) + include(cmake/OpenCVFindOpenEXR.cmake) endif() +#################### LATEX for dpf documentation ################## if(BUILD_DOCS) include(cmake/OpenCVFindLATEX.cmake REQUIRED) endif() -# Always try to find python -# =================================================== -find_host_package(PythonInterp) -find_host_package(PythonLibs) +########################## Python Support ######################### +include(cmake/OpenCVDetectPython.cmake REQUIRED) -# cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND -if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH) - set(PYTHONLIBS_FOUND ON) -endif() - -execute_process(COMMAND ${PYTHON_EXECUTABLE} --version - ERROR_VARIABLE PYTHON_VERSION_FULL - OUTPUT_STRIP_TRAILING_WHITESPACE) - -string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}") -if(CMAKE_HOST_UNIX) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()" - RESULT_VARIABLE PYTHON_CVPY_PROCESS - OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE) - if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages") - set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages CACHE PATH "Where to install the python packages.") - else() #debian based assumed, install to the dist-packages. - set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages CACHE PATH "Where to install the python packages.") - endif() -endif() -if(CMAKE_HOST_WIN32) - get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE CACHE) - set(PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages") -endif() - -# Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy -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]" - RESULT_VARIABLE PYTHON_NUMPY_PROCESS - OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS - OUTPUT_STRIP_TRAILING_WHITESPACE) - -if(PYTHON_NUMPY_PROCESS EQUAL 0) - set(PYTHON_USE_NUMPY 1) - add_definitions(-DPYTHON_USE_NUMPY=1) - include_directories(AFTER ${PYTHON_NUMPY_INCLUDE_DIRS}) - message(STATUS " Use NumPy headers from: ${PYTHON_NUMPY_INCLUDE_DIRS}") -else() - set(PYTHON_USE_NUMPY 0) -endif() - -execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sphinx; print sphinx.__version__" - RESULT_VARIABLE SPHINX_PROCESS - OUTPUT_VARIABLE SPHINX_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - -set(HAVE_SPHINX 0) -if(SPHINX_PROCESS EQUAL 0) - find_host_program(SPHINX_BUILD sphinx-build) - if(SPHINX_BUILD) - set(HAVE_SPHINX 1) - message(STATUS " Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}") - endif() -endif() - -# Java support -# =================================================== -if (BUILD_JAVA_SUPPORT AND PYTHON_EXECUTABLE) - file(TO_CMAKE_PATH "$ENV{ANT_DIR}" ANT_DIR_ENV_PATH) - file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH) - - if(ANDROID) - file(TO_CMAKE_PATH "$ENV{ANDROID_SDK}" ANDROID_SDK_ENV_PATH) - - #find android SDK - find_host_program(ANDROID_EXECUTABLE - NAMES android.bat android - PATHS "${ANDROID_SDK_ENV_PATH}/tools/" - "${ProgramFiles_ENV_PATH}/Android/android-sdk/tools/" - "/opt/android-sdk/tools/" - "/opt/android-sdk-linux_x86/tools/" - "/opt/android-sdk-mac_x86/tools/" - "/opt/android-sdk-linux_86/tools/" - "/opt/android-sdk-mac_86/tools/" - ) - if(ANDROID_EXECUTABLE) - message(STATUS " Found android tool: ${ANDROID_EXECUTABLE}") - get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH) - #read source.properties - if (EXISTS "${ANDROID_SDK_TOOLS_PATH}/source.properties") - file(STRINGS "${ANDROID_SDK_TOOLS_PATH}/source.properties" ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$") - foreach(line ${ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES}) - string(REPLACE "\\:" ":" line ${line}) - string(REPLACE "=" ";" line ${line}) - list(GET line 0 line_name) - list(GET line 1 line_value) - string(REPLACE "." "_" line_name ${line_name}) - SET(ANDROID_TOOLS_${line_name} "${line_value}") - MARK_AS_ADVANCED(ANDROID_TOOLS_${line_name}) - endforeach() - endif() - if (NOT ANDROID_TOOLS_Pkg_Revision) - SET(ANDROID_TOOLS_Pkg_Revision "Unknown") - MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Revision) - endif() - if (NOT ANDROID_TOOLS_Pkg_Desc) - SET(ANDROID_TOOLS_Pkg_Desc "Android SDK Tools, revision ${ANDROID_TOOLS_Pkg_Revision}.") - if (NOT ANDROID_TOOLS_Pkg_Revision GREATER 11) - SET(ANDROID_TOOLS_Pkg_Desc "${ANDROID_TOOLS_Pkg_Desc} It is recommended to update your SDK tools to revision 12 or newer.") - endif() - MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Desc) - endif() - - #get installed targets - execute_process(COMMAND ${ANDROID_EXECUTABLE} list target - RESULT_VARIABLE ANDROID_PROCESS - OUTPUT_VARIABLE ANDROID_SDK_TARGETS_FULL - ERROR_VARIABLE ANDROID_PROCESS_ERRORS - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX MATCHALL "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" ANDROID_SDK_TARGETS_FULL "${ANDROID_SDK_TARGETS_FULL}") - - SET(ANDROID_SDK_TARGETS) - if (ANDROID_PROCESS EQUAL 0) - foreach(line ${ANDROID_SDK_TARGETS_FULL}) - string(REGEX REPLACE "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" "\\2" line "${line}") - list(APPEND ANDROID_SDK_TARGETS "${line}") - endforeach() - endif() - - # detect ANDROID_SDK_TARGET if no target is provided by user - if (NOT ANDROID_SDK_TARGET) - set(desired_android_target_level ${ANDROID_NATIVE_API_LEVEL}) - if (desired_android_target_level LESS 8) - set(desired_android_target_level 8) - endif() - if (ANDROID_PROCESS EQUAL 0) - math(EXPR desired_android_target_level_1 "${desired_android_target_level}-1") - - foreach(target ${ANDROID_SDK_TARGETS}) - string(REGEX MATCH "[0-9]+$" target_level "${target}") - if (target_level GREATER desired_android_target_level_1) - set(ANDROID_SDK_TARGET "${target}") - break() - endif() - endforeach() - else() - set(ANDROID_SDK_TARGET android-${desired_android_target_level}) - message(WARNING "Could not retrieve list of installed Android targets. Will try to use \"${ANDROID_SDK_TARGET}\" target") - endif() - endif() - - SET(ANDROID_SDK_TARGET ${ANDROID_SDK_TARGET} CACHE STRING "SDK target for Android tests and samples") - if (ANDROID_PROCESS EQUAL 0 AND CMAKE_VERSION VERSION_GREATER "2.8") - set_property( CACHE ANDROID_SDK_TARGET PROPERTY STRINGS ${ANDROID_SDK_TARGETS} ) - endif() - string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}") - endif() - endif() - - #find apache ant - find_host_program(ANT_EXECUTABLE NAMES ant.bat ant - PATHS "${ANT_DIR_ENV_PATH}/bin" - "${ProgramFiles_ENV_PATH}/apache-ant/bin" - ) - if(ANT_EXECUTABLE) - execute_process(COMMAND ${ANT_EXECUTABLE} -version - OUTPUT_VARIABLE ANT_VERSION_FULL - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" ANT_VERSION "${ANT_VERSION_FULL}") - - message(STATUS " Found apache ant ${ANT_VERSION}: ${ANT_EXECUTABLE}") - endif() +########################### Java Support ########################## +# current implementation of Java wrappers generator requires python at build time +if(BUILD_JAVA_SUPPORT AND PYTHON_EXECUTABLE) + if(ANDROID) + include(cmake/OpenCVDetectAndroidSDK.cmake REQUIRED) + endif() + include(cmake/OpenCVDetectApacheAnt.cmake REQUIRED) - if (ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_SDK_TARGET_LEVEL GREATER 7)) - SET(CAN_BUILD_ANDROID_PROJECTS TRUE) - else() - SET(CAN_BUILD_ANDROID_PROJECTS FALSE) - endif() + if(ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_SDK_TARGET_LEVEL GREATER 7)) + SET(CAN_BUILD_ANDROID_PROJECTS TRUE) + else() + SET(CAN_BUILD_ANDROID_PROJECTS FALSE) + endif() endif() if(NOT CAN_BUILD_ANDROID_PROJECTS) - UNSET(BUILD_ANDROID_EXAMPLES CACHE) + UNSET(BUILD_ANDROID_EXAMPLES CACHE) endif() -#YV ############################### QT ################################ - set(HAVE_QT 0) set(HAVE_QT_OPENGL 0) -if (WITH_QT) - find_package(Qt4) - if (QT4_FOUND) - set(HAVE_QT 1) - add_definitions(-DHAVE_QT) #We need to define te macro this way, using cvconfig.h.cmake does not work - - if (WITH_OPENGL) - find_package (OpenGL QUIET) - if (QT_QTOPENGL_FOUND AND OPENGL_FOUND) - set(HAVE_OPENGL 1) - set(HAVE_QT_OPENGL 1) - add_definitions(-DHAVE_QT_OPENGL) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES}) - endif() - endif() +if(WITH_QT) + find_package(Qt4) + if(QT4_FOUND) + set(HAVE_QT 1) + add_definitions(-DHAVE_QT) #We need to define te macro this way, using cvconfig.h.cmake does not work + + if(WITH_OPENGL) + find_package (OpenGL QUIET) + if(QT_QTOPENGL_FOUND AND OPENGL_FOUND) + set(HAVE_OPENGL 1) + set(HAVE_QT_OPENGL 1) + add_definitions(-DHAVE_QT_OPENGL) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES}) + endif() endif() + endif() endif() ############################### TBB ################################ - -if (WITH_TBB) - if (UNIX AND NOT APPLE AND NOT ANDROID) - PKG_CHECK_MODULES(TBB tbb) - - if (TBB_FOUND) - set(HAVE_TBB 1) - if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "") - include_directories(${TBB_INCLUDE_DIRS}) - endif() - link_directories(${TBB_LIBRARY_DIRS}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES}) - endif() - endif() - - if (NOT HAVE_TBB) - 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") - - find_path(TBB_INCLUDE_DIR "tbb/tbb.h" PATHS ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers") - if (TBB_INCLUDE_DIR) - if (UNIX) - set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory") - link_directories("${TBB_LIB_DIR}") - endif() - if (APPLE) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib) - elseif (ANDROID) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - add_definitions(-DTBB_USE_GCC_BUILTINS) - elseif (UNIX) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - elseif (WIN32) - if (CMAKE_COMPILER_IS_GNUCXX) - set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory") - link_directories("${TBB_LIB_DIR}") - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) - else() - get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIR}/../lib" ABSOLUTE) - - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*|x86_64* OR MSVC64) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/intel64") - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86*|i386*|i686*) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/ia32") - endif() - - if (MSVC80) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8") - elseif(MSVC90) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9") - elseif(MSVC10) - set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10") - endif() - set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory") - link_directories("${TBB_LIB_DIR}") - endif() - endif() - - set(HAVE_TBB 1) - if(NOT "${TBB_INCLUDE_DIR}" STREQUAL "") - include_directories("${TBB_INCLUDE_DIR}") - endif() - endif() - endif() -endif(WITH_TBB) +if(WITH_TBB) + include(cmake/OpenCVDetectTBB.cmake REQUIRED) +endif() ############################ Intel IPP ############################# set(IPP_FOUND) if(WITH_IPP) - include(cmake/OpenCVFindIPP.cmake) + include(cmake/OpenCVFindIPP.cmake) endif() if(IPP_FOUND) - add_definitions(-DHAVE_IPP) - include_directories(${IPP_INCLUDE_DIRS}) - link_directories(${IPP_LIBRARY_DIRS}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_LIBRARIES}) + add_definitions(-DHAVE_IPP) + include_directories(${IPP_INCLUDE_DIRS}) + link_directories(${IPP_LIBRARY_DIRS}) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_LIBRARIES}) endif() - ############################### CUDA ################################ - if(WITH_CUDA) - find_package(CUDA 4.0) - - if(CUDA_FOUND) - set(HAVE_CUDA 1) - - if(WITH_CUFFT) - set(HAVE_CUFFT 1) - endif() - - if(WITH_CUBLAS) - set(HAVE_CUBLAS 1) - endif() - - message(STATUS "CUDA detected: " ${CUDA_VERSION}) - - 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") - set(CUDA_ARCH_PTX "2.0" CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for") - - string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}") - string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}") - - # Ckeck if user specified 1.0 compute capability: we don't support it - string(REGEX MATCH "1.0" HAS_ARCH_10 "${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}") - set(CUDA_ARCH_BIN_OR_PTX_10 0) - if(NOT ${HAS_ARCH_10} STREQUAL "") - set(CUDA_ARCH_BIN_OR_PTX_10 1) - endif() - - # NVCC flags to be set - set(NVCC_FLAGS_EXTRA "") - - # These vars will be passed into the templates - set(OPENCV_CUDA_ARCH_BIN "") - set(OPENCV_CUDA_ARCH_PTX "") - set(OPENCV_CUDA_ARCH_FEATURES "") - - # Tell NVCC to add binaries for the specified GPUs - string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}") - foreach(ARCH IN LISTS ARCH_LIST) - if (ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)") - # User explicitly specified PTX for the concrete BIN - set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1}) - set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}") - set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}") - else() - # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN - set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=sm_${ARCH}) - set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}") - set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}") - endif() - endforeach() - - # Tell NVCC to add PTX intermediate code for the specified architectures - string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}") - foreach(ARCH IN LISTS ARCH_LIST) - set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=compute_${ARCH}) - set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}") - set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}") - endforeach() - - # These vars will be processed in other scripts - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA}) - set(OpenCV_CUDA_CC "${NVCC_FLAGS_EXTRA}") - - message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}") - else() - unset(CUDA_ARCH_BIN CACHE) - unset(CUDA_ARCH_PTX CACHE) - endif() + include(cmake/OpenCVDetectCUDA.cmake REQUIRED) endif() - ############################### OpenNI ################################ set(HAVE_OPENNI FALSE) set(HAVE_OPENNI_PRIME_SENSOR_MODULE FALSE) if(WITH_OPENNI) - include(cmake/OpenCVFindOpenNI.cmake) + include(cmake/OpenCVFindOpenNI.cmake) endif() ############################### XIMEA ################################ set(HAVE_XIMEA FALSE) if(WITH_XIMEA) - include(cmake/OpenCVFindXimea.cmake) + include(cmake/OpenCVFindXimea.cmake) endif() if(XIMEA_FOUND) - set(HAVE_XIMEA TRUE) + set(HAVE_XIMEA TRUE) endif() ############################## Eigen ############################## - if(WITH_EIGEN) - find_path(EIGEN_INCLUDE_PATH "Eigen/Core" + find_path(EIGEN_INCLUDE_PATH "Eigen/Core" PATHS "/usr/local/include/eigen2" "/opt/include/eigen2" "/usr/include/eigen2" - "/usr/local/include/eigen3" "/opt/include/eigen3" "/usr/include/eigen3" + "/usr/local/include/eigen3" "/opt/include/eigen3" "/usr/include/eigen3" DOC "The path to Eigen2/Eigen3 headers") - if(EIGEN_INCLUDE_PATH) - include_directories(${EIGEN_INCLUDE_PATH}) - set(HAVE_EIGEN 1) - endif() + if(EIGEN_INCLUDE_PATH) + include_directories(${EIGEN_INCLUDE_PATH}) + set(HAVE_EIGEN 1) + endif() endif() - ################## Extra HighGUI libs on Windows ################### - if(WIN32) - set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} comctl32 gdi32 ole32) + set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} comctl32 gdi32 ole32) - if(WITH_VIDEOINPUT) - set(HAVE_VIDEOINPUT 1) - endif() + if(WITH_VIDEOINPUT) + set(HAVE_VIDEOINPUT 1) + endif() - if (MSVC) - set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32) - endif() + if(MSVC) + set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32) + endif() - if(MINGW) - if(MINGW64) - set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} msvfw32 avifil32 avicap32 winmm) - else() - set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32 winmm) - endif() + if(MINGW) + if(MINGW64) + set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} msvfw32 avifil32 avicap32 winmm) + else() + set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} vfw32 winmm) endif() + endif() - if(WITH_OPENGL AND NOT HAVE_QT_OPENGL) - find_package(OpenGL QUIET) + if(WITH_OPENGL AND NOT HAVE_QT_OPENGL) + find_package(OpenGL QUIET) - if(OPENGL_FOUND) - set(HAVE_OPENGL 1) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES}) - include_directories(${OPENGL_INCLUDE_DIR}) - endif() - endif() -endif() - -############## Android source tree for native camera ############### -if(ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7) - SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH -"Path to Android source tree. -Set this variable to path to your Android sources to compile -libnative_camera_rx.x.x.so for your Android") - SET(BUILD_ANDROID_CAMERA_WRAPPER OFF) - if (ANDROID_SOURCE_TREE) - FILE(STRINGS "${ANDROID_SOURCE_TREE}/development/sdk/platform_source.properties" ANDROID_VERSION REGEX "Platform\\.Version=[0-9]+\\.[0-9]+(\\.[0-9]+)?" ) - string(REGEX REPLACE "Platform\\.Version=([0-9]+\\.[0-9]+(\\.[0-9]+)?)" "\\1" ANDROID_VERSION "${ANDROID_VERSION}") - if (ANDROID_VERSION MATCHES "^[0-9]+\\.[0-9]+$") - SET(ANDROID_VERSION "${ANDROID_VERSION}.0") - endif() - if(NOT "${ANDROID_VERSION}" STREQUAL "") - SET(BUILD_ANDROID_CAMERA_WRAPPER ON) - endif() + if(OPENGL_FOUND) + set(HAVE_OPENGL 1) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES}) + include_directories(${OPENGL_INCLUDE_DIR}) endif() - MARK_AS_ADVANCED(ANDROID_SOURCE_TREE) + endif() endif() # ---------------------------------------------------------------------------- -# UPDATE CONFIG FILES & SCRIPTS: -# -# CONFIGURE_FILE(InputFile OutputFile [COPYONLY] [ESCAPE_QUOTES] [@ONLY]) -# If @ONLY is specified, only variables of the form @VAR@ will be -# replaces and ${VAR} will be ignored. -# -# A directory will be created for each platform so the "cvconfig.h" file is -# not overwritten if cmake generates code in the same path. +# OpenCV compiler and linker options # ---------------------------------------------------------------------------- -add_definitions(-DHAVE_CVCONFIG_H) - -set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h") - -message(STATUS "Parsing 'cvconfig.h.cmake'") -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cvconfig.h.cmake" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h") - -# --------------------------------------------------------------------------- -# The C+//0 include & link directories: -# --------------------------------------------------------------------------- -include_directories("." - "${OPENCV_CONFIG_FILE_INCLUDE_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/include/opencv" - ) - -if (WIN32 AND ${CMAKE_GENERATOR} MATCHES "(MinGW)|(MSYS)") - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "") -endif() - -set(OPENCV_EXTRA_C_FLAGS "") -set(OPENCV_EXTRA_C_FLAGS_RELEASE "") -set(OPENCV_EXTRA_C_FLAGS_DEBUG "") -set(OPENCV_EXTRA_EXE_LINKER_FLAGS "") -set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "") -set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "") - -if(MSVC) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS") - # 64-bit portability warnings, in MSVC8 - if(MSVC80) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Wp64") - endif() - #if(MSVC90) - # set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _BIND_TO_CURRENT_CRT_VERSION=1 /D _BIND_TO_CURRENT_VCLIBS_VERSION=1") - #endif() - - if(BUILD_WITH_DEBUG_INFO) - set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug") - endif() - - # Remove unreferenced functions: function level linking - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Gy") - if(BUILD_WITH_DEBUG_INFO) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Zi") - endif() -endif() - -if(CMAKE_COMPILER_IS_GNUCXX) - # High level of warnings. - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall") - - # The -Wno-long-long is required in 64bit systems when including sytem headers. - if(X86_64) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wno-long-long") - endif() - - # We need pthread's - if(UNIX AND NOT ANDROID) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -pthread") - endif() - - if(OPENCV_WARNINGS_ARE_ERRORS) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Werror") - endif() - - if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -march=i686") - endif() - - # Other optimizations - if(ENABLE_OMIT_FRAME_POINTER) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer") - else() - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fno-omit-frame-pointer") - endif() - if(ENABLE_FAST_MATH) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -ffast-math") - endif() - if(ENABLE_POWERPC) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5") - endif() - if(ENABLE_SSE) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse") - endif() - if(ENABLE_SSE2) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse2") - endif() - # SSE3 and further should be disabled under MingW because it generates compiler errors - if(NOT MINGW) - if(ENABLE_SSE3) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse3") - endif() - - if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402) - set(HAVE_GCC43_OR_NEWER 1) - endif() - if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401) - set(HAVE_GCC42_OR_NEWER 1) - endif() - - if(HAVE_GCC42_OR_NEWER OR APPLE) - if(ENABLE_SSSE3) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mssse3") - endif() - if(HAVE_GCC43_OR_NEWER) - if(ENABLE_SSE41) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.1") - endif() - if(ENABLE_SSE42) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.2") - endif() - endif() - endif() - endif() - - if(X86 OR X86_64) - if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mfpmath=387") - endif() - endif() - - # Profiling? - if(ENABLE_PROFILING) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g") - elseif(NOT APPLE) - # Remove unreferenced functions: function level linking - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections") - endif() - - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -DNDEBUG") - set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG") - if(BUILD_WITH_DEBUG_INFO) - set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -ggdb3") - endif() -endif() - -if(MSVC) - # 64-bit MSVC compiler uses SSE/SSE2 by default - if(NOT MSVC64) - if(ENABLE_SSE) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE") - endif() - if(ENABLE_SSE2) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE2") - endif() - endif() - if(ENABLE_SSE3) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE3") - endif() - if(ENABLE_SSE4_1) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1") - endif() - if (ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Oi") - endif() -endif() - -# Extra link libs if the user selects building static libs: -if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID) - # Android does not need these settings because they are already set by toolchain file - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++) - set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}") -endif() - -# Add user supplied extra options (optimization, etc...) -# ========================================================== -set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS}" CACHE INTERNAL "Extra compiler options") -set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE}" CACHE INTERNAL "Extra compiler options for Release build") -set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG}" CACHE INTERNAL "Extra compiler options for Debug build") -set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}" CACHE INTERNAL "Extra linker flags") -set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}" CACHE INTERNAL "Extra linker flags for Release build") -set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}" CACHE INTERNAL "Extra linker flags for Debug build") - -#combine all "extra" options -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_C_FLAGS}") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}") -set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}") +include(cmake/OpenCVCompilerOptions.cmake REQUIRED) # In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release: -if (CMAKE_GENERATOR MATCHES ".*Makefiles" AND "${CMAKE_BUILD_TYPE}" STREQUAL "") - set(CMAKE_BUILD_TYPE Release) -endif() - -if (WIN32 AND MSVC) - # avoid warnings from MSVC about overriding the /W* option - # we replace /W3 with /W4 only for C++ files, - # since all the 3rd-party libraries OpenCV uses are in C, - # and we do not care about their warnings. - string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - - # allow extern "C" functions throw exceptions - string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - - string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -endif() - -if("${CMAKE_CONFIGURE_LDFLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CONFIGURE_LDFLAGS}") -endif("${CMAKE_CONFIGURE_LDFLAGS}") - -# -------------------------------------------------------------------------------------------- -# Installation for CMake Module: OpenCVConfig.cmake -# Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install" -# Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use with "make install" -# Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages -# ------------------------------------------------------------------------------------------- - -# ------------------------------------------------------------------------------------------- -# Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install" -# ------------------------------------------------------------------------------------------- -set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"") -set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "${CMAKE_CURRENT_SOURCE_DIR}") -set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}") -set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY) -#support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work. -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) -# -------------------------------------------------------------------------------------------- -# Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install" -# ------------------------------------------------------------------------------------------- -set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"") - -set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "") -if(ANDROID) - set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ANDROID_NDK_ABI_NAME}\"") - set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ANDROID_NDK_ABI_NAME}\"") -else() - set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"") - set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") - if(OPENCV_MANGLED_INSTALL_PATHS) - set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV-${OPENCV_VERSION}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") - endif() +if(CMAKE_GENERATOR MATCHES "Makefiles" AND "${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CMAKE_BUILD_TYPE Release) endif() -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) - -if(UNIX) - #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference - # For a command "find_package( [major[.minor]] [EXACT] [REQUIRED|QUIET])" - # cmake will look in the following dir on unix: - # /(share|lib)/cmake/*/ (U) - # /(share|lib)/*/ (U) - # /(share|lib)/*/(cmake|CMake)/ (U) - if(OPENCV_MANGLED_INSTALL_PATHS) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/) - else() - install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION share/OpenCV/) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV/) - endif() +# ---------------------------------------------------------------------------- +# Solution folders: +# ---------------------------------------------------------------------------- +if(ENABLE_SOLUTION_FOLDERS) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets") endif() -if(ANDROID) - install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV) -endif() +# Extra OpenCV targets: uninstall, package_source, perf, etc. +include(cmake/OpenCVExtraTargets.cmake REQUIRED) -# -------------------------------------------------------------------------------------------- -# Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages -# ------------------------------------------------------------------------------------------- -if(WIN32) - set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"") - set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "") - set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/${OPENCV_LIB_INSTALL_PATH}\"") - set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") +# ---------------------------------------------------------------------------- +# Process subdirectories +# ---------------------------------------------------------------------------- - exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) +# opencv.hpp and legacy headers +add_subdirectory(include) - # Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/") -endif() +# OpenCV modules +add_subdirectory(modules) -# -------------------------------------------------------------------------------------------- -# Installation for Android ndk-build makefile: OpenCV.mk -# Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install" -# Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install" -# ------------------------------------------------------------------------------------------- -if(ANDROID) - if(BUILD_SHARED_LIBS) - SET(OPENCV_LIBTYPE_CONFIGMAKE "SHARED") - else() - SET(OPENCV_LIBTYPE_CONFIGMAKE "STATIC") - endif() - if(BUILD_ANDROID_CAMERA_WRAPPER) - set(CMAKE_CAMERA_LIBS_CONFIGCMAKE "native_camera_r${ANDROID_VERSION}") - elseif(WITH_ANDROID_CAMERA) - SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "") - file(GLOB CMAKE_CAMERA_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lib/${ANDROID_NDK_ABI_NAME}/libnative_camera_r*.so") - foreach(cam_lib ${CMAKE_CAMERA_LIBS}) - get_filename_component(cam_lib "${cam_lib}" NAME) - string(REGEX REPLACE "lib(native_camera_r[0-9]+\\.[0-9]+\\.[0-9]+)\\.so" "\\1" cam_lib "${cam_lib}") - SET(CMAKE_CAMERA_LIBS_CONFIGCMAKE "${CMAKE_CAMERA_LIBS_CONFIGCMAKE} ${cam_lib}") - endforeach() - endif() -endif(ANDROID) +# Generate targets for documentation +add_subdirectory(doc) -# ------------------------------------------------------------------------------------------- -# Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install" -# ------------------------------------------------------------------------------------------- -if(ANDROID) - set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"") - set(CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE "\"${CMAKE_CURRENT_SOURCE_DIR}\"") - set(CMAKE_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)") +# various data that is used by cv libraries and/or demo applications. +add_subdirectory(data) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY) -endif(ANDROID) +# 3rdparty libraries on-board +add_subdirectory(3rdparty) -# ------------------------------------------------------------------------------------------- -# Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install" -# ------------------------------------------------------------------------------------------- -if(ANDROID) - set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include/opencv\" \"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include\"") - set(CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE "") - set(CMAKE_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../..") - - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION share/OpenCV/) -endif(ANDROID) - -# -------------------------------------------------------------------------------------------- -#according to man pkg-config -# The package name specified on the pkg-config command line is defined to -# be the name of the metadata file, minus the .pc extension. If a library -# can install multiple versions simultaneously, it must give each version -# its own name (for example, GTK 1.2 might have the package name "gtk+" -# while GTK 2.0 has "gtk+-2.0"). -# Part 2/2: ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install" -# prefix=/usr -# exec_prefix=${prefix} -# libdir=${exec_prefix}/lib -# includedir=${prefix}/include/opencv -# ------------------------------------------------------------------------------------------- -set(prefix ${CMAKE_INSTALL_PREFIX}) -set(exec_prefix "\${prefix}") -set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}") -set(includedir "\${prefix}/${OPENCV_INCLUDE_PREFIX}") -set(VERSION ${OPENCV_VERSION}) - -set(OPENCV_PC_FILE_NAME opencv.pc) -#need to be explicit with naming the pc file and version number for side by side installs to work. -if(OPENCV_MANGLED_INSTALL_PATHS) - 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 ) - #be explicit about the library names. - set(OpenCV_LIB_COMPONENTS_ ) - foreach( CVLib ${OpenCV_LIB_COMPONENTS}) - set(OpenCV_LIB_COMPONENTS_ "${OpenCV_LIB_COMPONENTS_} ${libdir}/lib${CVLib}.so.${OPENCV_VERSION}" ) - endforeach() - set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_}) - set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE) -else() - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE) -endif() +# extra applications +add_subdirectory(apps) -if(UNIX AND NOT ANDROID) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig) +# examples +if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES) + add_subdirectory(samples) endif() # ---------------------------------------------------------------------------- -# Uninstall target, for "make uninstall" +# Finalization: generate configuration-based files # ---------------------------------------------------------------------------- -CONFIGURE_FILE( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY) - -ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") - -#----------------------------------- -# Source package: -#----------------------------------- -if(BUILD_PACKAGE) - set(TARBALL_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}") - if (NOT WIN32) - if(APPLE) - set(TAR_CMD gnutar) - else() - set(TAR_CMD tar) - endif() - set(TAR_TRANSFORM "\"s,^,${TARBALL_NAME}/,\"") - add_custom_target(package_source - #TODO: maybe we should not remove dll's - 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" ./ - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - else() - add_custom_target(package_source - COMMAND zip -9 -r ${CMAKE_CURRENT_BINARY_DIR}/${TARBALL_NAME}.zip . -x '*/.svn/*' '*.vcproj' '*.pyc' - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - endif() -endif() +ocv_track_build_dependencies() +# Generate platform-dependent and configuration-dependent headers +include(cmake/OpenCVGenHeaders.cmake REQUIRED) -#----------------------------------- -# Solution folders: -#----------------------------------- -if(ENABLE_SOLUTION_FOLDERS) - set_property(GLOBAL PROPERTY USE_FOLDERS ON) - set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets") -endif() +# Generate opencv.pc for pkg-config command +include(cmake/OpenCVGenPkgconfig.cmake REQUIRED) -#----------------------------------- -# performance tests -#----------------------------------- -if(BUILD_PERF_TESTS AND PYTHON_EXECUTABLE) - if(CMAKE_VERSION VERSION_GREATER "2.8.2") - add_custom_target(perf - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/modules/ts/misc/run.py" --configuration $ "${CMAKE_BINARY_DIR}" - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/modules/ts/misc/run.py" - ) - else() - add_custom_target(perf - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/modules/ts/misc/run.py" "${CMAKE_BINARY_DIR}" - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/modules/ts/misc/run.py" - ) - endif() -endif() +# Generate OpenCV.mk for ndk-build (Android build tool) +include(cmake/OpenCVGenAndroidMK.cmake REQUIRED) -#----------------------------------- -# Subdirectories: -#----------------------------------- -add_subdirectory(include) -add_subdirectory(modules) -add_subdirectory(doc) -add_subdirectory(data) -add_subdirectory(3rdparty) - -if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES) - add_subdirectory(samples) -endif() +# Generate OpenCVŠ”onfig.cmake and OpenCVConfig-version.cmake for cmake projects +include(cmake/OpenCVGenConfig.cmake REQUIRED) # ---------------------------------------------------------------------------- -# Summary: +# Summary: # ---------------------------------------------------------------------------- status("") status("General configuration for opencv ${OPENCV_VERSION} =====================================") @@ -1504,6 +652,18 @@ else() status(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}) endif() +status("") +status(" OpenCV modules:") +string(REPLACE "opencv_" "" OPENCV_MODULES_BUILD_ST "${OPENCV_MODULES_BUILD}") +string(REPLACE "opencv_" "" OPENCV_MODULES_DISABLED_USER_ST "${OPENCV_MODULES_DISABLED_USER}") +string(REPLACE "opencv_" "" OPENCV_MODULES_DISABLED_AUTO_ST "${OPENCV_MODULES_DISABLED_AUTO}") +string(REPLACE "opencv_" "" OPENCV_MODULES_DISABLED_FORCE_ST "${OPENCV_MODULES_DISABLED_FORCE}") +status(" To be built:" OPENCV_MODULES_BUILD THEN ${OPENCV_MODULES_BUILD_ST} ELSE "-") +status(" Disabled by user:" OPENCV_MODULES_DISABLED_USER THEN ${OPENCV_MODULES_DISABLED_USER_ST} ELSE "-") +status(" Disabled by dependency:" OPENCV_MODULES_DISABLED_AUTO THEN ${OPENCV_MODULES_DISABLED_AUTO_ST} ELSE "-") +status(" Unavailable:" OPENCV_MODULES_DISABLED_FORCE THEN ${OPENCV_MODULES_DISABLED_FORCE_ST} ELSE "-") + + if(ANDROID) status("") status(" Android: ") @@ -1655,7 +815,9 @@ status(" cvconfig.h is in:" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}") status("-----------------------------------------------------------------") status("") -# warn in the case of in-source build +# ---------------------------------------------------------------------------- +# Warn in the case of in-source build +# ---------------------------------------------------------------------------- if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree") endif() diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index 395333fe85..621fc2e9f0 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -155,6 +155,7 @@ # [+] added special check for cygwin # [+] filtered out hidden files (starting with .) while globbing inside NDK # [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6 +# [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags # ------------------------------------------------------------------------------ # this one is important @@ -890,6 +891,18 @@ macro( find_host_program ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) endmacro() +macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR ) + if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" ) + set( ${VAR} "armeabi" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" ) + set( ${VAR} "armeabi-v7a" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" ) + set( ${VAR} "x86" ) + else() + set( ${VAR} "unknown" ) + endif() +endmacro() + set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) if( ANDROID_SET_OBSOLETE_VARIABLES ) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt new file mode 100644 index 0000000000..217490b2de --- /dev/null +++ b/apps/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(haartraining) +add_subdirectory(traincascade) diff --git a/modules/haartraining/CMakeLists.txt b/apps/haartraining/CMakeLists.txt similarity index 53% rename from modules/haartraining/CMakeLists.txt rename to apps/haartraining/CMakeLists.txt index ba7054de1c..6cccd43631 100644 --- a/modules/haartraining/CMakeLists.txt +++ b/apps/haartraining/CMakeLists.txt @@ -1,61 +1,53 @@ -if(IOS) - return() +if(IOS OR ANDROID) + return() +endif() + +SET(OPENCV_HAARTRAINING_DEPS opencv_core opencv_imgproc opencv_highgui opencv_objdetect opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy) +ocv_check_dependencies(${OPENCV_HAARTRAINING_DEPS}) + +if(NOT OCV_DEPENDENCIES_FOUND) + return() endif() project(haartraining) -include_directories( - "${CMAKE_CURRENT_SOURCE_DIR}" - "${OpenCV_SOURCE_DIR}/modules/core/include" - "${OpenCV_SOURCE_DIR}/modules/imgproc/include" - "${OpenCV_SOURCE_DIR}/modules/objdetect/include" - "${OpenCV_SOURCE_DIR}/modules/ml/include" - "${OpenCV_SOURCE_DIR}/modules/highgui/include" - "${OpenCV_SOURCE_DIR}/modules/video/include" - "${OpenCV_SOURCE_DIR}/modules/features2d/include" - "${OpenCV_SOURCE_DIR}/modules/flann/include" - "${OpenCV_SOURCE_DIR}/modules/calib3d/include" - "${OpenCV_SOURCE_DIR}/modules/legacy/include" - ) +include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") +ocv_include_modules(${OPENCV_HAARTRAINING_DEPS}) if(WIN32) - link_directories(${OpenCV_SOURCE_DIR}/lib ${OpenCV_SOURCE_DIR}/bin ${CMAKE_CURRENT_BINARY_DIR}) + link_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() -set(haartraining_libs opencv_core opencv_imgproc opencv_highgui opencv_objdetect opencv_calib3d opencv_haartraining_engine) - -link_libraries(${haartraining_libs}) +link_libraries(${OPENCV_HAARTRAINING_DEPS} opencv_haartraining_engine) # ----------------------------------------------------------- # Library # ----------------------------------------------------------- set(cvhaartraining_lib_src - _cvcommon.h - cvclassifier.h - _cvhaartraining.h - cvhaartraining.h - cvboost.cpp - cvcommon.cpp - cvhaarclassifier.cpp - cvhaartraining.cpp - cvsamples.cpp - ) + _cvcommon.h + cvclassifier.h + _cvhaartraining.h + cvhaartraining.h + cvboost.cpp + cvcommon.cpp + cvhaarclassifier.cpp + cvhaartraining.cpp + cvsamples.cpp + ) add_library(opencv_haartraining_engine STATIC ${cvhaartraining_lib_src}) set_target_properties(opencv_haartraining_engine PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - INSTALL_NAME_DIR lib - ) + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} + RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + INSTALL_NAME_DIR lib + ) -if(NOT ANDROID) # ----------------------------------------------------------- # haartraining # ----------------------------------------------------------- add_executable(opencv_haartraining cvhaartraining.h haartraining.cpp) -add_dependencies(opencv_haartraining ${haartraining_libs}) set_target_properties(opencv_haartraining PROPERTIES DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" OUTPUT_NAME "opencv_haartraining") @@ -65,7 +57,6 @@ set_target_properties(opencv_haartraining PROPERTIES # ----------------------------------------------------------- add_executable(opencv_createsamples cvhaartraining.h createsamples.cpp) -add_dependencies(opencv_createsamples ${haartraining_libs}) set_target_properties(opencv_createsamples PROPERTIES DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" OUTPUT_NAME "opencv_createsamples") @@ -74,7 +65,6 @@ set_target_properties(opencv_createsamples PROPERTIES # performance # ----------------------------------------------------------- add_executable(opencv_performance performance.cpp) -add_dependencies(opencv_performance ${haartraining_libs}) set_target_properties(opencv_performance PROPERTIES DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" OUTPUT_NAME "opencv_performance") @@ -87,12 +77,10 @@ install(TARGETS opencv_haartraining RUNTIME DESTINATION bin COMPONENT main) install(TARGETS opencv_createsamples RUNTIME DESTINATION bin COMPONENT main) install(TARGETS opencv_performance RUNTIME DESTINATION bin COMPONENT main) - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(opencv_performance PROPERTIES FOLDER "applications") - set_target_properties(opencv_createsamples PROPERTIES FOLDER "applications") - set_target_properties(opencv_haartraining PROPERTIES FOLDER "applications") - set_target_properties(opencv_haartraining_engine PROPERTIES FOLDER "applications") -endif() - + set_target_properties(opencv_performance PROPERTIES FOLDER "applications") + set_target_properties(opencv_createsamples PROPERTIES FOLDER "applications") + set_target_properties(opencv_haartraining PROPERTIES FOLDER "applications") + set_target_properties(opencv_haartraining_engine PROPERTIES FOLDER "applications") endif() + diff --git a/modules/haartraining/_cvcommon.h b/apps/haartraining/_cvcommon.h similarity index 100% rename from modules/haartraining/_cvcommon.h rename to apps/haartraining/_cvcommon.h diff --git a/modules/haartraining/_cvhaartraining.h b/apps/haartraining/_cvhaartraining.h similarity index 100% rename from modules/haartraining/_cvhaartraining.h rename to apps/haartraining/_cvhaartraining.h diff --git a/modules/haartraining/createsamples.cpp b/apps/haartraining/createsamples.cpp similarity index 100% rename from modules/haartraining/createsamples.cpp rename to apps/haartraining/createsamples.cpp diff --git a/modules/haartraining/cvboost.cpp b/apps/haartraining/cvboost.cpp similarity index 100% rename from modules/haartraining/cvboost.cpp rename to apps/haartraining/cvboost.cpp diff --git a/modules/haartraining/cvclassifier.h b/apps/haartraining/cvclassifier.h similarity index 100% rename from modules/haartraining/cvclassifier.h rename to apps/haartraining/cvclassifier.h diff --git a/modules/haartraining/cvcommon.cpp b/apps/haartraining/cvcommon.cpp similarity index 100% rename from modules/haartraining/cvcommon.cpp rename to apps/haartraining/cvcommon.cpp diff --git a/modules/haartraining/cvhaarclassifier.cpp b/apps/haartraining/cvhaarclassifier.cpp similarity index 100% rename from modules/haartraining/cvhaarclassifier.cpp rename to apps/haartraining/cvhaarclassifier.cpp diff --git a/modules/haartraining/cvhaartraining.cpp b/apps/haartraining/cvhaartraining.cpp similarity index 100% rename from modules/haartraining/cvhaartraining.cpp rename to apps/haartraining/cvhaartraining.cpp diff --git a/modules/haartraining/cvhaartraining.h b/apps/haartraining/cvhaartraining.h similarity index 100% rename from modules/haartraining/cvhaartraining.h rename to apps/haartraining/cvhaartraining.h diff --git a/modules/haartraining/cvsamples.cpp b/apps/haartraining/cvsamples.cpp similarity index 100% rename from modules/haartraining/cvsamples.cpp rename to apps/haartraining/cvsamples.cpp diff --git a/modules/haartraining/haartraining.cpp b/apps/haartraining/haartraining.cpp similarity index 100% rename from modules/haartraining/haartraining.cpp rename to apps/haartraining/haartraining.cpp diff --git a/modules/haartraining/performance.cpp b/apps/haartraining/performance.cpp similarity index 100% rename from modules/haartraining/performance.cpp rename to apps/haartraining/performance.cpp diff --git a/apps/traincascade/CMakeLists.txt b/apps/traincascade/CMakeLists.txt new file mode 100644 index 0000000000..526d362748 --- /dev/null +++ b/apps/traincascade/CMakeLists.txt @@ -0,0 +1,41 @@ +if(IOS OR ANDROID) + return() +endif() + +SET(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_ml opencv_imgproc opencv_objdetect opencv_highgui opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy) +ocv_check_dependencies(${OPENCV_TRAINCASCADE_DEPS}) + +if(NOT OCV_DEPENDENCIES_FOUND) + return() +endif() + +project(traincascade) + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") +ocv_include_modules(${OPENCV_TRAINCASCADE_DEPS}) + +set(traincascade_files traincascade.cpp + cascadeclassifier.cpp cascadeclassifier.h + boost.cpp boost.h features.cpp traincascade_features.h + haarfeatures.cpp haarfeatures.h + lbpfeatures.cpp lbpfeatures.h + HOGfeatures.cpp HOGfeatures.h + imagestorage.cpp imagestorage.h) + +set(the_target opencv_traincascade) +add_executable(${the_target} ${traincascade_files}) +target_link_libraries(${the_target} ${OPENCV_TRAINCASCADE_DEPS} opencv_haartraining_engine) + +set_target_properties(${the_target} PROPERTIES + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} + RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + INSTALL_NAME_DIR lib + OUTPUT_NAME "opencv_traincascade") + +if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "applications") +endif() + +install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main) + diff --git a/modules/traincascade/HOGfeatures.cpp b/apps/traincascade/HOGfeatures.cpp similarity index 100% rename from modules/traincascade/HOGfeatures.cpp rename to apps/traincascade/HOGfeatures.cpp diff --git a/modules/traincascade/HOGfeatures.h b/apps/traincascade/HOGfeatures.h similarity index 100% rename from modules/traincascade/HOGfeatures.h rename to apps/traincascade/HOGfeatures.h diff --git a/modules/traincascade/boost.cpp b/apps/traincascade/boost.cpp similarity index 100% rename from modules/traincascade/boost.cpp rename to apps/traincascade/boost.cpp diff --git a/modules/traincascade/boost.h b/apps/traincascade/boost.h similarity index 100% rename from modules/traincascade/boost.h rename to apps/traincascade/boost.h diff --git a/modules/traincascade/cascadeclassifier.cpp b/apps/traincascade/cascadeclassifier.cpp similarity index 100% rename from modules/traincascade/cascadeclassifier.cpp rename to apps/traincascade/cascadeclassifier.cpp diff --git a/modules/traincascade/cascadeclassifier.h b/apps/traincascade/cascadeclassifier.h similarity index 100% rename from modules/traincascade/cascadeclassifier.h rename to apps/traincascade/cascadeclassifier.h diff --git a/modules/traincascade/features.cpp b/apps/traincascade/features.cpp similarity index 100% rename from modules/traincascade/features.cpp rename to apps/traincascade/features.cpp diff --git a/modules/traincascade/haarfeatures.cpp b/apps/traincascade/haarfeatures.cpp similarity index 100% rename from modules/traincascade/haarfeatures.cpp rename to apps/traincascade/haarfeatures.cpp diff --git a/modules/traincascade/haarfeatures.h b/apps/traincascade/haarfeatures.h similarity index 100% rename from modules/traincascade/haarfeatures.h rename to apps/traincascade/haarfeatures.h diff --git a/modules/traincascade/imagestorage.cpp b/apps/traincascade/imagestorage.cpp similarity index 100% rename from modules/traincascade/imagestorage.cpp rename to apps/traincascade/imagestorage.cpp diff --git a/modules/traincascade/imagestorage.h b/apps/traincascade/imagestorage.h similarity index 100% rename from modules/traincascade/imagestorage.h rename to apps/traincascade/imagestorage.h diff --git a/modules/traincascade/lbpfeatures.cpp b/apps/traincascade/lbpfeatures.cpp similarity index 100% rename from modules/traincascade/lbpfeatures.cpp rename to apps/traincascade/lbpfeatures.cpp diff --git a/modules/traincascade/lbpfeatures.h b/apps/traincascade/lbpfeatures.h similarity index 100% rename from modules/traincascade/lbpfeatures.h rename to apps/traincascade/lbpfeatures.h diff --git a/modules/traincascade/traincascade.cpp b/apps/traincascade/traincascade.cpp similarity index 100% rename from modules/traincascade/traincascade.cpp rename to apps/traincascade/traincascade.cpp diff --git a/modules/traincascade/traincascade_features.h b/apps/traincascade/traincascade_features.h similarity index 100% rename from modules/traincascade/traincascade_features.h rename to apps/traincascade/traincascade_features.h diff --git a/cmake/OpenCVCRTLinkage.cmake b/cmake/OpenCVCRTLinkage.cmake new file mode 100644 index 0000000000..49eccb8655 --- /dev/null +++ b/cmake/OpenCVCRTLinkage.cmake @@ -0,0 +1,65 @@ +if(NOT MSVC) + message(FATAL_ERROR "CRT options are available only for MSVC" +endif() + +if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT) + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if(${flag_var} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + endif() + if(${flag_var} MATCHES "/MDd") + string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}") + endif() + endforeach(flag_var) + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib") + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib") +else() + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if(${flag_var} MATCHES "/MT") + string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}") + endif() + if(${flag_var} MATCHES "/MTd") + string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}") + endif() + endforeach(flag_var) +endif() + +if(NOT ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8 AND NOT ${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} LESS 8.6) + include(ProcessorCount) + ProcessorCount(N) + if(NOT N EQUAL 0) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${N} ") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${N} ") + endif() +endif() + +if(NOT BUILD_WITH_DEBUG_INFO) + string(REPLACE "/debug" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") + string(REPLACE "/DEBUG" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") + string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") + string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") + + string(REPLACE "/debug" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") + string(REPLACE "/DEBUG" "" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") + string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") + string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}") + + string(REPLACE "/debug" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") + string(REPLACE "/DEBUG" "" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") + string(REPLACE "/INCREMENTAL:YES" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") + string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") + + string(REPLACE "/Zi" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") +endif() + diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake new file mode 100644 index 0000000000..6836a20450 --- /dev/null +++ b/cmake/OpenCVCompilerOptions.cmake @@ -0,0 +1,190 @@ +if (WIN32 AND CMAKE_GENERATOR MATCHES "(MinGW)|(MSYS)") + set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "") +endif() + +set(OPENCV_EXTRA_C_FLAGS "") +set(OPENCV_EXTRA_C_FLAGS_RELEASE "") +set(OPENCV_EXTRA_C_FLAGS_DEBUG "") +set(OPENCV_EXTRA_EXE_LINKER_FLAGS "") +set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "") +set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "") + +if(MSVC) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS") + # 64-bit portability warnings, in MSVC8 + if(MSVC80) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Wp64") + endif() + #if(MSVC90) + # set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _BIND_TO_CURRENT_CRT_VERSION=1 /D _BIND_TO_CURRENT_VCLIBS_VERSION=1") + #endif() + + if(BUILD_WITH_DEBUG_INFO) + set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug") + endif() + + # Remove unreferenced functions: function level linking + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Gy") + if(BUILD_WITH_DEBUG_INFO) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Zi") + endif() +endif() + +if(CMAKE_COMPILER_IS_GNUCXX) + # High level of warnings. + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall") + + # The -Wno-long-long is required in 64bit systems when including sytem headers. + if(X86_64) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wno-long-long") + endif() + + # We need pthread's + if(UNIX AND NOT ANDROID) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -pthread") + endif() + + if(OPENCV_WARNINGS_ARE_ERRORS) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Werror") + endif() + + if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -march=i686") + endif() + + # Other optimizations + if(ENABLE_OMIT_FRAME_POINTER) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer") + else() + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fno-omit-frame-pointer") + endif() + if(ENABLE_FAST_MATH) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -ffast-math") + endif() + if(ENABLE_POWERPC) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5") + endif() + if(ENABLE_SSE) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse") + endif() + if(ENABLE_SSE2) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse2") + endif() + + # SSE3 and further should be disabled under MingW because it generates compiler errors + if(NOT MINGW) + if(ENABLE_SSE3) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse3") + endif() + + if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402) + set(HAVE_GCC43_OR_NEWER 1) + endif() + if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401) + set(HAVE_GCC42_OR_NEWER 1) + endif() + + if(HAVE_GCC42_OR_NEWER OR APPLE) + if(ENABLE_SSSE3) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mssse3") + endif() + if(HAVE_GCC43_OR_NEWER) + if(ENABLE_SSE41) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.1") + endif() + if(ENABLE_SSE42) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.2") + endif() + endif() + endif() + endif(NOT MINGW) + + if(X86 OR X86_64) + if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mfpmath=387") + endif() + endif() + + # Profiling? + if(ENABLE_PROFILING) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g") + elseif(NOT APPLE) + # Remove unreferenced functions: function level linking + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections") + endif() + + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -DNDEBUG") + set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG") + if(BUILD_WITH_DEBUG_INFO) + set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -ggdb3") + endif() +endif() + +if(MSVC) + # 64-bit MSVC compiler uses SSE/SSE2 by default + if(NOT MSVC64) + if(ENABLE_SSE) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE") + endif() + if(ENABLE_SSE2) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE2") + endif() + endif() + if(ENABLE_SSE3) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE3") + endif() + if(ENABLE_SSE4_1) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1") + endif() + if (ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Oi") + endif() +endif() + +# Extra link libs if the user selects building static libs: +if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID) + # Android does not need these settings because they are already set by toolchain file + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++) + set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}") +endif() + +# Add user supplied extra options (optimization, etc...) +# ========================================================== +set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS}" CACHE INTERNAL "Extra compiler options") +set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE}" CACHE INTERNAL "Extra compiler options for Release build") +set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG}" CACHE INTERNAL "Extra compiler options for Debug build") +set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}" CACHE INTERNAL "Extra linker flags") +set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}" CACHE INTERNAL "Extra linker flags for Release build") +set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}" CACHE INTERNAL "Extra linker flags for Debug build") + +#combine all "extra" options +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_C_FLAGS}") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}") + +if (WIN32 AND MSVC) + # avoid warnings from MSVC about overriding the /W* option + # we replace /W3 with /W4 only for C++ files, + # since all the 3rd-party libraries OpenCV uses are in C, + # and we do not care about their warnings. + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + + # allow extern "C" functions throw exceptions + string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + + string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +endif() diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake new file mode 100644 index 0000000000..c388b11dce --- /dev/null +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -0,0 +1,91 @@ +file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH) +file(TO_CMAKE_PATH "$ENV{ANDROID_SDK}" ANDROID_SDK_ENV_PATH) + +#find android SDK +find_host_program(ANDROID_EXECUTABLE + NAMES android.bat android + PATHS "${ANDROID_SDK_ENV_PATH}/tools/" + "${ProgramFiles_ENV_PATH}/Android/android-sdk/tools/" + "/opt/android-sdk/tools/" + "/opt/android-sdk-linux_x86/tools/" + "/opt/android-sdk-mac_x86/tools/" + "/opt/android-sdk-linux_86/tools/" + "/opt/android-sdk-mac_86/tools/" + ) + +if(ANDROID_EXECUTABLE) + message(STATUS " Found android tool: ${ANDROID_EXECUTABLE}") + get_filename_component(ANDROID_SDK_TOOLS_PATH "${ANDROID_EXECUTABLE}" PATH) + + #read source.properties + if(EXISTS "${ANDROID_SDK_TOOLS_PATH}/source.properties") + file(STRINGS "${ANDROID_SDK_TOOLS_PATH}/source.properties" ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$") + foreach(line ${ANDROID_SDK_TOOLS_SOURCE_PROPERTIES_LINES}) + string(REPLACE "\\:" ":" line ${line}) + string(REPLACE "=" ";" line ${line}) + list(GET line 0 line_name) + list(GET line 1 line_value) + string(REPLACE "." "_" line_name ${line_name}) + SET(ANDROID_TOOLS_${line_name} "${line_value}") + MARK_AS_ADVANCED(ANDROID_TOOLS_${line_name}) + endforeach() + endif() + + if(NOT ANDROID_TOOLS_Pkg_Revision) + SET(ANDROID_TOOLS_Pkg_Revision "Unknown") + MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Revision) + endif() + + if(NOT ANDROID_TOOLS_Pkg_Desc) + SET(ANDROID_TOOLS_Pkg_Desc "Android SDK Tools, revision ${ANDROID_TOOLS_Pkg_Revision}.") + if(NOT ANDROID_TOOLS_Pkg_Revision GREATER 11) + SET(ANDROID_TOOLS_Pkg_Desc "${ANDROID_TOOLS_Pkg_Desc} It is recommended to update your SDK tools to revision 12 or newer.") + endif() + MARK_AS_ADVANCED(ANDROID_TOOLS_Pkg_Desc) + endif() + + #get installed targets + execute_process(COMMAND ${ANDROID_EXECUTABLE} list target + RESULT_VARIABLE ANDROID_PROCESS + OUTPUT_VARIABLE ANDROID_SDK_TARGETS_FULL + ERROR_VARIABLE ANDROID_PROCESS_ERRORS + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX MATCHALL "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" ANDROID_SDK_TARGETS_FULL "${ANDROID_SDK_TARGETS_FULL}") + + SET(ANDROID_SDK_TARGETS "") + if(ANDROID_PROCESS EQUAL 0) + foreach(line ${ANDROID_SDK_TARGETS_FULL}) + string(REGEX REPLACE "(^|\n)id: [0-9]+ or \"([^\n]+[0-9+])\"(\n|$)" "\\2" line "${line}") + list(APPEND ANDROID_SDK_TARGETS "${line}") + endforeach() + endif() + + # detect ANDROID_SDK_TARGET if no target is provided by user + if(NOT ANDROID_SDK_TARGET) + set(desired_android_target_level ${ANDROID_NATIVE_API_LEVEL}) + if(desired_android_target_level LESS 8) + set(desired_android_target_level 8) + endif() + if(ANDROID_PROCESS EQUAL 0) + math(EXPR desired_android_target_level_1 "${desired_android_target_level}-1") + + foreach(target ${ANDROID_SDK_TARGETS}) + string(REGEX MATCH "[0-9]+$" target_level "${target}") + if(target_level GREATER desired_android_target_level_1) + set(ANDROID_SDK_TARGET "${target}") + break() + endif() + endforeach() + else() + set(ANDROID_SDK_TARGET android-${desired_android_target_level}) + message(WARNING "Could not retrieve list of installed Android targets. Will try to use \"${ANDROID_SDK_TARGET}\" target") + endif() + endif(NOT ANDROID_SDK_TARGET) + + SET(ANDROID_SDK_TARGET "${ANDROID_SDK_TARGET}" CACHE STRING "SDK target for Android tests and samples") + if(ANDROID_PROCESS EQUAL 0 AND CMAKE_VERSION VERSION_GREATER "2.8") + set_property( CACHE ANDROID_SDK_TARGET PROPERTY STRINGS ${ANDROID_SDK_TARGETS} ) + endif() + string(REGEX MATCH "[0-9]+$" ANDROID_SDK_TARGET_LEVEL "${ANDROID_SDK_TARGET}") +endif(ANDROID_EXECUTABLE) diff --git a/cmake/OpenCVDetectApacheAnt.cmake b/cmake/OpenCVDetectApacheAnt.cmake new file mode 100644 index 0000000000..0572d199f2 --- /dev/null +++ b/cmake/OpenCVDetectApacheAnt.cmake @@ -0,0 +1,16 @@ +file(TO_CMAKE_PATH "$ENV{ANT_DIR}" ANT_DIR_ENV_PATH) +file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH) + +find_host_program(ANT_EXECUTABLE NAMES ant.bat ant + PATHS "${ANT_DIR_ENV_PATH}/bin" + "${ProgramFiles_ENV_PATH}/apache-ant/bin" + ) + +if(ANT_EXECUTABLE) + execute_process(COMMAND ${ANT_EXECUTABLE} -version + OUTPUT_VARIABLE ANT_VERSION_FULL + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" ANT_VERSION "${ANT_VERSION_FULL}") + + message(STATUS " Found apache ant ${ANT_VERSION}: ${ANT_EXECUTABLE}") +endif() diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake new file mode 100644 index 0000000000..55b76f952f --- /dev/null +++ b/cmake/OpenCVDetectCUDA.cmake @@ -0,0 +1,88 @@ +find_package(CUDA 4.0) + +if(CUDA_FOUND) + set(HAVE_CUDA 1) + + if(WITH_CUFFT) + set(HAVE_CUFFT 1) + endif() + + if(WITH_CUBLAS) + set(HAVE_CUBLAS 1) + endif() + + message(STATUS "CUDA detected: " ${CUDA_VERSION}) + + 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") + set(CUDA_ARCH_PTX "2.0" CACHE STRING "Specify 'virtual' PTX architectures to build PTX intermediate code for") + + string(REGEX REPLACE "\\." "" ARCH_BIN_NO_POINTS "${CUDA_ARCH_BIN}") + string(REGEX REPLACE "\\." "" ARCH_PTX_NO_POINTS "${CUDA_ARCH_PTX}") + + # Ckeck if user specified 1.0 compute capability: we don't support it + string(REGEX MATCH "1.0" HAS_ARCH_10 "${CUDA_ARCH_BIN} ${CUDA_ARCH_PTX}") + set(CUDA_ARCH_BIN_OR_PTX_10 0) + if(NOT ${HAS_ARCH_10} STREQUAL "") + set(CUDA_ARCH_BIN_OR_PTX_10 1) + endif() + + # NVCC flags to be set + set(NVCC_FLAGS_EXTRA "") + + # These vars will be passed into the templates + set(OPENCV_CUDA_ARCH_BIN "") + set(OPENCV_CUDA_ARCH_PTX "") + set(OPENCV_CUDA_ARCH_FEATURES "") + + # Tell NVCC to add binaries for the specified GPUs + string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_NO_POINTS}") + foreach(ARCH IN LISTS ARCH_LIST) + if(ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)") + # User explicitly specified PTX for the concrete BIN + set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1}) + set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${CMAKE_MATCH_1}") + set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${CMAKE_MATCH_2}") + else() + # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN + set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=sm_${ARCH}) + set(OPENCV_CUDA_ARCH_BIN "${OPENCV_CUDA_ARCH_BIN} ${ARCH}") + set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}") + endif() + endforeach() + + # Tell NVCC to add PTX intermediate code for the specified architectures + string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_NO_POINTS}") + foreach(ARCH IN LISTS ARCH_LIST) + set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_EXTRA} -gencode arch=compute_${ARCH},code=compute_${ARCH}) + set(OPENCV_CUDA_ARCH_PTX "${OPENCV_CUDA_ARCH_PTX} ${ARCH}") + set(OPENCV_CUDA_ARCH_FEATURES "${OPENCV_CUDA_ARCH_FEATURES} ${ARCH}") + endforeach() + + # These vars will be processed in other scripts + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA}) + set(OpenCV_CUDA_CC "${NVCC_FLAGS_EXTRA}") + + message(STATUS "CUDA NVCC target flags: ${CUDA_NVCC_FLAGS}") + + macro(OCV_CUDA_COMPILE VAR) + if (BUILD_SHARED_LIBS) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -DCVAPI_EXPORTS) + endif() + + if(UNIX OR APPLE) + set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fPIC) + endif() + if(APPLE) + set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fno-finite-math-only) + endif() + + # we remove -ggdb3 flag as it leads to preprocessor errors when compiling CUDA files (CUDA 4.1) + set(CMAKE_CXX_FLAGS_DEBUG_ ${CMAKE_CXX_FLAGS_DEBUG}) + string(REPLACE "-ggdb3" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) + CUDA_COMPILE(${VAR} ${ARGN}) + set(CMAKE_CXX_DEBUG_FLAGS ${CMAKE_CXX_FLAGS_DEBUG_}) + endmacro() +else() + unset(CUDA_ARCH_BIN CACHE) + unset(CUDA_ARCH_PTX CACHE) +endif() diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake new file mode 100644 index 0000000000..3054fbe000 --- /dev/null +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -0,0 +1,76 @@ +# ---------------------------------------------------------------------------- +# Detect Microsoft compiler: +# ---------------------------------------------------------------------------- +if(CMAKE_CL_64) + set(MSVC64 1) +endif() + +# ---------------------------------------------------------------------------- +# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ): +# see include/opencv/cxtypes.h file for related ICC & CV_ICC defines. +# NOTE: The system needs to determine if the '-fPIC' option needs to be added +# for the 3rdparty static libs being compiled. The CMakeLists.txt files +# in 3rdparty use the CV_ICC definition being set here to determine if +# the -fPIC flag should be used. +# ---------------------------------------------------------------------------- +if(UNIX) + if (__ICL) + set(CV_ICC __ICL) + elseif(__ICC) + set(CV_ICC __ICC) + elseif(__ECL) + set(CV_ICC __ECL) + elseif(__ECC) + set(CV_ICC __ECC) + elseif(__INTEL_COMPILER) + set(CV_ICC __INTEL_COMPILER) + elseif(CMAKE_C_COMPILER MATCHES "icc") + set(CV_ICC icc_matches_c_compiler) + endif() +endif() + +if(MSVC AND CMAKE_C_COMPILER MATCHES "icc") + set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS) +endif() + +# ---------------------------------------------------------------------------- +# Detect GNU version: +# ---------------------------------------------------------------------------- +if(CMAKE_COMPILER_IS_GNUCXX) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version + OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v + ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)" + # Look for the version number + string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}") + + # Split the three parts: + string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}") + + list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR) + list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR) + + set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR}) + math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}") + message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})") + + if(WIN32) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine + OUTPUT_VARIABLE CMAKE_OPENCV_GCC_TARGET_MACHINE + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(CMAKE_OPENCV_GCC_TARGET_MACHINE MATCHES "64") + set(MINGW64 1) + endif() + endif() +endif() + +if(CMAKE_SYSTEM_PROCESSOR MATCHES amd64.*|x86_64.*) + set(X86_64 1) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES i686.*|i386.*|x86.*) + set(X86 1) +endif() diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake new file mode 100644 index 0000000000..ccf5e7f639 --- /dev/null +++ b/cmake/OpenCVDetectPython.cmake @@ -0,0 +1,59 @@ +find_host_package(PythonInterp) +find_host_package(PythonLibs) + +# cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND +if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH) + set(PYTHONLIBS_FOUND ON) +endif() + +execute_process(COMMAND ${PYTHON_EXECUTABLE} --version + ERROR_VARIABLE PYTHON_VERSION_FULL + OUTPUT_STRIP_TRAILING_WHITESPACE) + +string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}") +if(CMAKE_HOST_UNIX) + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()" + RESULT_VARIABLE PYTHON_CVPY_PROCESS + OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) + if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages") + set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages CACHE PATH "Where to install the python packages.") + else() #debian based assumed, install to the dist-packages. + set(PYTHON_PACKAGES_PATH lib/python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages CACHE PATH "Where to install the python packages.") + endif() +endif() + +if(CMAKE_HOST_WIN32) + get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE CACHE) + set(PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages") +endif() + +# Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy +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]" + RESULT_VARIABLE PYTHON_NUMPY_PROCESS + OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if(PYTHON_NUMPY_PROCESS EQUAL 0) + set(PYTHON_USE_NUMPY 1) + add_definitions(-DPYTHON_USE_NUMPY=1) + include_directories(AFTER ${PYTHON_NUMPY_INCLUDE_DIRS}) + message(STATUS " Use NumPy headers from: ${PYTHON_NUMPY_INCLUDE_DIRS}") +else() + set(PYTHON_USE_NUMPY 0) +endif() + +# look for Sphinx +execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sphinx; print sphinx.__version__" + RESULT_VARIABLE SPHINX_PROCESS + OUTPUT_VARIABLE SPHINX_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(HAVE_SPHINX 0) +if(SPHINX_PROCESS EQUAL 0) + find_host_program(SPHINX_BUILD sphinx-build) + if(SPHINX_BUILD) + set(HAVE_SPHINX 1) + message(STATUS " Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}") + endif() +endif() diff --git a/cmake/OpenCVDetectTBB.cmake b/cmake/OpenCVDetectTBB.cmake new file mode 100644 index 0000000000..13bd947877 --- /dev/null +++ b/cmake/OpenCVDetectTBB.cmake @@ -0,0 +1,63 @@ +if(UNIX AND NOT APPLE AND NOT ANDROID) + PKG_CHECK_MODULES(TBB tbb) + + if(TBB_FOUND) + set(HAVE_TBB 1) + if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "") + include_directories(${TBB_INCLUDE_DIRS}) + endif() + link_directories(${TBB_LIBRARY_DIRS}) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES}) + endif() +endif() + +if(NOT HAVE_TBB) + 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") + + find_path(TBB_INCLUDE_DIR "tbb/tbb.h" PATHS ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers") + if(TBB_INCLUDE_DIR) + if(UNIX) + set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory") + link_directories("${TBB_LIB_DIR}") + endif() + if(APPLE) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib) + elseif(ANDROID) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) + add_definitions(-DTBB_USE_GCC_BUILTINS) + elseif (UNIX) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) + elseif (WIN32) + if(CMAKE_COMPILER_IS_GNUCXX) + set(TBB_LIB_DIR "${TBB_INCLUDE_DIR}/../lib" CACHE PATH "Full path of TBB library directory") + link_directories("${TBB_LIB_DIR}") + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) + else() + get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIR}/../lib" ABSOLUTE) + + if(CMAKE_SYSTEM_PROCESSOR MATCHES amd64*|x86_64* OR MSVC64) + set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/intel64") + elseif() + set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/ia32") + endif() + + if(MSVC80) + set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8") + elseif(MSVC90) + set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9") + elseif(MSVC10) + set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10") + elseif(MSVC11) + set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc11") + endif() + set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory") + link_directories("${TBB_LIB_DIR}") + endif() + endif() + + set(HAVE_TBB 1) + if(NOT "${TBB_INCLUDE_DIR}" STREQUAL "") + include_directories("${TBB_INCLUDE_DIR}") + endif() + endif(TBB_INCLUDE_DIR) +endif(NOT HAVE_TBB) diff --git a/cmake/OpenCVExtraTargets.cmake b/cmake/OpenCVExtraTargets.cmake new file mode 100644 index 0000000000..c421eb7724 --- /dev/null +++ b/cmake/OpenCVExtraTargets.cmake @@ -0,0 +1,53 @@ +# ---------------------------------------------------------------------------- +# Uninstall target, for "make uninstall" +# ---------------------------------------------------------------------------- +CONFIGURE_FILE( + "${OpenCV_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") + + +# ---------------------------------------------------------------------------- +# Source package, for "make package_source" +# ---------------------------------------------------------------------------- +if(BUILD_PACKAGE) + set(TARBALL_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}") + if (NOT WIN32) + if(APPLE) + set(TAR_CMD gnutar) + else() + set(TAR_CMD tar) + endif() + set(TAR_TRANSFORM "\"s,^,${TARBALL_NAME}/,\"") + add_custom_target(package_source + #TODO: maybe we should not remove dll's + 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" ./ + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + else() + add_custom_target(package_source + COMMAND zip -9 -r ${CMAKE_CURRENT_BINARY_DIR}/${TARBALL_NAME}.zip . -x '*/.svn/*' '*.vcproj' '*.pyc' + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endif() +endif() + + +#----------------------------------- +# performance tests, for "make perf" +#----------------------------------- +if(BUILD_PERF_TESTS AND PYTHON_EXECUTABLE) + if(CMAKE_VERSION VERSION_GREATER "2.8.2") + add_custom_target(perf + ${PYTHON_EXECUTABLE} "${OpenCV_SOURCE_DIR}/modules/ts/misc/run.py" --configuration $ "${CMAKE_BINARY_DIR}" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + DEPENDS "${OpenCV_SOURCE_DIR}/modules/ts/misc/run.py" + ) + else() + add_custom_target(perf + ${PYTHON_EXECUTABLE} "${OpenCV_SOURCE_DIR}/modules/ts/misc/run.py" "${CMAKE_BINARY_DIR}" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + DEPENDS "${OpenCV_SOURCE_DIR}/modules/ts/misc/run.py" + ) + endif() +endif() diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake new file mode 100644 index 0000000000..5f1002a51e --- /dev/null +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -0,0 +1,83 @@ +if(ANDROID) + # -------------------------------------------------------------------------------------------- + # Installation for Android ndk-build makefile: OpenCV.mk + # Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install" + # Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install" + # ------------------------------------------------------------------------------------------- + + # build type + if(BUILD_SHARED_LIBS) + set(OPENCV_LIBTYPE_CONFIGMAKE "SHARED") + else() + set(OPENCV_LIBTYPE_CONFIGMAKE "STATIC") + endif() + + # setup lists of camera libs + foreach(abi ARMEABI ARMEABI_V7A X86) + ANDROID_GET_ABI_RAWNAME(${abi} ndkabi) + if(BUILD_ANDROID_CAMERA_WRAPPER) + if(ndkabi STREQUAL ANDROID_NDK_ABI_NAME) + set(OPENCV_CAMERA_LIBS_${abi}_CONFIGCMAKE "native_camera_r${ANDROID_VERSION}") + else() + set(OPENCV_CAMERA_LIBS_${abi}_CONFIGCMAKE "") + endif() + elseif(HAVE_opencv_androidcamera) + set(OPENCV_CAMERA_LIBS_${abi}_CONFIGCMAKE "") + file(GLOB OPENCV_CAMERA_LIBS "${OpenCV_SOURCE_DIR}/3rdparty/lib/${ndkabi}/libnative_camera_r*.so") + if(OPENCV_CAMERA_LIBS) + list(SORT OPENCV_CAMERA_LIBS) + endif() + foreach(cam_lib ${OPENCV_CAMERA_LIBS}) + get_filename_component(cam_lib "${cam_lib}" NAME) + string(REGEX REPLACE "lib(native_camera_r[0-9]+\\.[0-9]+\\.[0-9]+)\\.so" "\\1" cam_lib "${cam_lib}") + set(OPENCV_CAMERA_LIBS_${abi}_CONFIGCMAKE "${OPENCV_CAMERA_LIBS_${abi}_CONFIGCMAKE} ${cam_lib}") + endforeach() + endif() + endforeach() + + # build the list of opencv libs and dependencies for all modules + set(OPENCV_MODULES_CONFIGMAKE "") + set(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "") + set(OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE "") + foreach(m ${OPENCV_MODULES_PUBLIC}) + list(INSERT OPENCV_MODULES_CONFIGMAKE 0 ${${m}_MODULE_DEPS_${ocv_optkind}} ${m}) + if(${m}_EXTRA_DEPS_${ocv_optkind}) + list(INSERT OPENCV_EXTRA_COMPONENTS_CONFIGMAKE 0 ${${m}_EXTRA_DEPS_${ocv_optkind}}) + endif() + endforeach() + + # split 3rdparty libs and modules + foreach(mod ${OPENCV_MODULES_CONFIGMAKE}) + if(NOT mod MATCHES "^opencv_.+$") + list(INSERT OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE 0 ${mod}) + endif() + endforeach() + list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) + + # convert CMake lists to makefile literals + foreach(lst OPENCV_MODULES_CONFIGMAKE OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE OPENCV_EXTRA_COMPONENTS_CONFIGMAKE) + ocv_list_unique(${lst}) + ocv_list_reverse(${lst}) + string(REPLACE ";" " " ${lst} "${${lst}}") + endforeach() + string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") + + # ------------------------------------------------------------------------------------------- + # Part 1/2: ${BIN_DIR}/OpenCV.mk -> For use *without* "make install" + # ------------------------------------------------------------------------------------------- + set(OPENCV_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\" \"${OpenCV_SOURCE_DIR}/include/opencv\"") + set(OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE "\"${OpenCV_SOURCE_DIR}\"") + set(OPENCV_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)") + + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY) + + # ------------------------------------------------------------------------------------------- + # Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install" + # ------------------------------------------------------------------------------------------- + set(OPENCV_INCLUDE_DIRS_CONFIGCMAKE "\"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include/opencv\" \"\$(LOCAL_PATH)/\$(OPENCV_THIS_DIR)/../../include\"") + set(OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE "") + set(OPENCV_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../..") + + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION share/OpenCV/) +endif(ANDROID) diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake new file mode 100644 index 0000000000..01c7d926f3 --- /dev/null +++ b/cmake/OpenCVGenConfig.cmake @@ -0,0 +1,130 @@ +# -------------------------------------------------------------------------------------------- +# Installation for CMake Module: OpenCVConfig.cmake +# Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install" +# Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use with "make install" +# Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages +# ------------------------------------------------------------------------------------------- + +if(INSTALL_TO_MANGLED_PATHS) + set(OpenCV_USE_MANGLED_PATHS TRUE) +else() + set(OpenCV_USE_MANGLED_PATHS FALSE) +endif() + +if(NOT OpenCV_CUDA_CC) + set(OpenCV_CUDA_CC_CONFIGMAKE "\"\"") +else() + set(OpenCV_CUDA_CC_CONFIGMAKE "${OpenCV_CUDA_CC}") +endif() + +if(NOT ANDROID_NATIVE_API_LEVEL) + set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGMAKE 0) +else() + set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGMAKE "${ANDROID_NATIVE_API_LEVEL}") +endif() + + +#build list of modules available for the OpenCV user +set(OpenCV_LIB_COMPONENTS "") +foreach(m ${OPENCV_MODULES_PUBLIC}) + list(INSERT OpenCV_LIB_COMPONENTS 0 ${${m}_MODULE_DEPS_OPT} ${m}) +endforeach() +ocv_list_unique(OpenCV_LIB_COMPONENTS) +set(OPENCV_MODULES_CONFIGMAKE ${OpenCV_LIB_COMPONENTS}) +ocv_list_filterout(OpenCV_LIB_COMPONENTS "^opencv_") +if(OpenCV_LIB_COMPONENTS) + list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE ${OpenCV_LIB_COMPONENTS}) +endif() + +macro(ocv_generate_dependencies_map_configmake suffix) + set(OPENCV_DEPENDENCIES_MAP_${suffix} "") + set(OPENCV_PROCESSED_LIBS "") + set(OPENCV_LIBS_TO_PROCESS ${OPENCV_MODULES_CONFIGMAKE}) + while(OPENCV_LIBS_TO_PROCESS) + list(GET OPENCV_LIBS_TO_PROCESS 0 __ocv_lib) + + set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_DEPS_${suffix} ${${__ocv_lib}_MODULE_DEPS_${suffix}})\n") + set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_EXTRA_DEPS_${suffix} ${${__ocv_lib}_EXTRA_DEPS_${suffix}})\n") + + list(APPEND OPENCV_PROCESSED_LIBS ${__ocv_lib}) + list(APPEND OPENCV_LIBS_TO_PROCESS ${${__ocv_lib}_MODULE_DEPS_${suffix}}) + list(REMOVE_ITEM OPENCV_LIBS_TO_PROCESS ${OPENCV_PROCESSED_LIBS}) + endwhile() + unset(OPENCV_PROCESSED_LIBS) + unset(OPENCV_LIBS_TO_PROCESS) + unset(__ocv_lib) +endmacro() + +ocv_generate_dependencies_map_configmake(OPT) +ocv_generate_dependencies_map_configmake(DBG) + +# ------------------------------------------------------------------------------------------- +# Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install" +# ------------------------------------------------------------------------------------------- +set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\" \"${OpenCV_SOURCE_DIR}/include/opencv\"") +set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "${OpenCV_SOURCE_DIR}") +set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}") +set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY) + +#support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work. +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) + + +# -------------------------------------------------------------------------------------------- +# Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install" +# ------------------------------------------------------------------------------------------- +set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"") + +set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "") +if(ANDROID) + set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ANDROID_NDK_ABI_NAME}\"") + set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ANDROID_NDK_ABI_NAME}\"") +else() + set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"") + set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") + if(INSTALL_TO_MANGLED_PATHS) + set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV-${OPENCV_VERSION}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") + endif() +endif() + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) + +if(UNIX) + #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference + # For a command "find_package( [major[.minor]] [EXACT] [REQUIRED|QUIET])" + # cmake will look in the following dir on unix: + # /(share|lib)/cmake/*/ (U) + # /(share|lib)/*/ (U) + # /(share|lib)/*/(cmake|CMake)/ (U) + if(INSTALL_TO_MANGLED_PATHS) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/) + else() + install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION share/OpenCV/) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV/) + endif() +endif() + +if(ANDROID) + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV) +endif() + +# -------------------------------------------------------------------------------------------- +# Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages +# ------------------------------------------------------------------------------------------- +if(WIN32) + set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"") + set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "") + set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/${OPENCV_LIB_INSTALL_PATH}\"") + set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") + + exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) + + # Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/") +endif() + diff --git a/cmake/OpenCVGenHeaders.cmake b/cmake/OpenCVGenHeaders.cmake new file mode 100644 index 0000000000..f342c6338e --- /dev/null +++ b/cmake/OpenCVGenHeaders.cmake @@ -0,0 +1,36 @@ +# ---------------------------------------------------------------------------- +# Variables for cvconfig.h.cmake +# ---------------------------------------------------------------------------- +set(PACKAGE "opencv") +set(PACKAGE_BUGREPORT "opencvlibrary-devel@lists.sourceforge.net") +set(PACKAGE_NAME "opencv") +set(PACKAGE_STRING "${PACKAGE} ${OPENCV_VERSION}") +set(PACKAGE_TARNAME "${PACKAGE}") +set(PACKAGE_VERSION "${OPENCV_VERSION}") + +# platform-specific config file +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/cvconfig.h.cmake" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h") + +# ---------------------------------------------------------------------------- +# opencv_modules.hpp based on actual modules list +# ---------------------------------------------------------------------------- +set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "") + +set(OPENCV_MOD_LIST ${OPENCV_MODULES_PUBLIC}) +ocv_list_sort(OPENCV_MOD_LIST) +foreach(m ${OPENCV_MOD_LIST}) + string(TOUPPER "${m}" m) + set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}#define HAVE_${m} 1\n") +endforeach() + +set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}\n") + +set(OPENCV_MOD_LIST ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO}) +ocv_list_sort(OPENCV_MOD_LIST) +foreach(m ${OPENCV_MOD_LIST}) + string(TOUPPER "${m}" m) + set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}#undef HAVE_${m}\n") +endforeach() + +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv_modules.hpp.in" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp") +install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2 COMPONENT main) diff --git a/cmake/OpenCVGenPkgconfig.cmake b/cmake/OpenCVGenPkgconfig.cmake new file mode 100644 index 0000000000..045bbb4815 --- /dev/null +++ b/cmake/OpenCVGenPkgconfig.cmake @@ -0,0 +1,75 @@ +# -------------------------------------------------------------------------------------------- +# according to man pkg-config +# The package name specified on the pkg-config command line is defined to +# be the name of the metadata file, minus the .pc extension. If a library +# can install multiple versions simultaneously, it must give each version +# its own name (for example, GTK 1.2 might have the package name "gtk+" +# while GTK 2.0 has "gtk+-2.0"). +# +# ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install" +# ------------------------------------------------------------------------------------------- +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(exec_prefix "\${prefix}") +set(libdir "") #TODO: need link paths for OpenCV_EXTRA_COMPONENTS +set(includedir "\${prefix}/${OPENCV_INCLUDE_PREFIX}") +set(VERSION ${OPENCV_VERSION}) + +if(CMAKE_BUILD_TYPE MATCHES "Release") + set(ocv_optkind OPT) +else() + set(ocv_optkind DBG) +endif() + +#build the list of opencv libs and dependencies for all modules +set(OpenCV_LIB_COMPONENTS "") +set(OpenCV_EXTRA_COMPONENTS "") +foreach(m ${OPENCV_MODULES_PUBLIC}) + list(INSERT OpenCV_LIB_COMPONENTS 0 ${${m}_MODULE_DEPS_${ocv_optkind}} ${m}) + if(${m}_EXTRA_DEPS_${ocv_optkind}) + list(INSERT OpenCV_EXTRA_COMPONENTS 0 ${${m}_EXTRA_DEPS_${ocv_optkind}}) + endif() +endforeach() + +ocv_list_unique(OpenCV_LIB_COMPONENTS) +ocv_list_unique(OpenCV_EXTRA_COMPONENTS) +ocv_list_reverse(OpenCV_LIB_COMPONENTS) +ocv_list_reverse(OpenCV_EXTRA_COMPONENTS) + +#build the list of components +set(OpenCV_LIB_COMPONENTS_ "") +foreach(CVLib ${OpenCV_LIB_COMPONENTS}) + get_target_property(libpath ${CVLib} LOCATION_${CMAKE_BUILD_TYPE}) + get_filename_component(libname "${libpath}" NAME) + + if(INSTALL_TO_MANGLED_PATHS) + set(libname "${libname}.${OPENCV_VERSION}") + endif() + + #need better solution.... + if(libpath MATCHES "3rdparty") + set(installDir "share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}") + else() + set(installDir "${OPENCV_LIB_INSTALL_PATH}") + endif() + + set(OpenCV_LIB_COMPONENTS_ "${OpenCV_LIB_COMPONENTS_} \${exec_prefix}/${installDir}/${libname}") +endforeach() + +# add extra dependencies required for OpenCV +set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_}) +if(OpenCV_EXTRA_COMPONENTS) + string(REPLACE ";" " " OpenCV_EXTRA_COMPONENTS "${OpenCV_EXTRA_COMPONENTS}") + set(OpenCV_LIB_COMPONENTS "${OpenCV_LIB_COMPONENTS} ${OpenCV_EXTRA_COMPONENTS}") +endif() + +#generate the .pc file +if(INSTALL_TO_MANGLED_PATHS) + set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") +else() + set(OPENCV_PC_FILE_NAME opencv.pc) +endif() +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY IMMEDIATE) + +if(UNIX AND NOT ANDROID) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig) +endif() diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 4947945dcc..ca8ff11e0b 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -1,278 +1,682 @@ -set(opencv_public_modules "" CACHE INTERNAL "List of OpenCV modules included into the build") -# helper macro for modules management -macro(opencv_module_register name) - set(opencv_public_modules ${opencv_public_modules} ${name} CACHE INTERNAL "List of OpenCV modules included into the build") -endmacro() - -# Setup include path for OpenCV headers for specified modules -macro(opencv_module_includes) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/src" - "${CMAKE_CURRENT_BINARY_DIR}") - foreach(d ${ARGN}) - if(d MATCHES "opencv_") - string(REPLACE "opencv_" "${OpenCV_SOURCE_DIR}/modules/" d_dir ${d}) - if (EXISTS "${d_dir}/include") - include_directories("${d_dir}/include") - endif() - endif() - endforeach() +# Local variables (set for each module): +# +# name - short name in lower case i.e. core +# the_module - full name in lower case i.e. opencv_core + +# Global variables: +# +# OPENCV_MODULE_${the_module}_LOCATION +# OPENCV_MODULE_${the_module}_DESCRIPTION +# OPENCV_MODULE_${the_module}_HEADERS +# OPENCV_MODULE_${the_module}_SOURCES +# OPENCV_MODULE_${the_module}_DEPS - final flattened set of module dependencies +# OPENCV_MODULE_${the_module}_DEPS_EXT +# OPENCV_MODULE_${the_module}_REQ_DEPS +# OPENCV_MODULE_${the_module}_OPT_DEPS +# HAVE_${the_module} - for fast check of module availability + +# To control the setup of the module you could also set: +# the_description - text to be used as current module description +# OPENCV_MODULE_TYPE - STATIC|SHARED - set to force override global settings for current module + +# The verbose template for OpenCV module: +# +# ocv_add_module(modname ) +# ocv_glob_module_sources() or glob them manually and ocv_set_module_sources(...) +# ocv_module_include_directories() +# ocv_create_module() +# +# ocv_add_precompiled_headers(${the_module}) +# +# ocv_add_accuracy_tests() +# ocv_add_perf_tests() +# +# +# If module have no "extra" then you can define it in one line: +# +# ocv_define_module(modname ) + +# clean flags for modules enabled on previous cmake run +# this is necessary to correctly handle modules removal +foreach(mod ${OPENCV_MODULES_BUILD}) + if(HAVE_${mod}) + unset(HAVE_${mod} CACHE) + endif() +endforeach() + +# clean modules info which needs to be recalculated +set(OPENCV_MODULES_PUBLIC "" CACHE INTERNAL "List of OpenCV modules marked for export") +set(OPENCV_MODULES_BUILD "" CACHE INTERNAL "List of OpenCV modules included into the build") +set(OPENCV_MODULES_DISABLED_USER "" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user") +set(OPENCV_MODULES_DISABLED_AUTO "" CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies") +set(OPENCV_MODULES_DISABLED_FORCE "" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration") + +# adds dependencies to OpenCV module +# Usage: +# add_dependencies(opencv_ [REQUIRED] [] [OPTIONAL ]) +# Notes: +# * - can include full names of modules or full pathes to shared/static libraries or cmake targets +macro(ocv_add_dependencies full_modname) + #we don't clean the dependencies here to allow this macro several times for every module + foreach(d "REQIRED" ${ARGN}) + if(d STREQUAL "REQIRED") + set(__depsvar OPENCV_MODULE_${full_modname}_REQ_DEPS) + elseif(d STREQUAL "OPTIONAL") + set(__depsvar OPENCV_MODULE_${full_modname}_OPT_DEPS) + else() + list(APPEND ${__depsvar} "${d}") + endif() + endforeach() + + if(OPENCV_MODULE_${full_modname}_REQ_DEPS) + list(REMOVE_DUPLICATES OPENCV_MODULE_${full_modname}_REQ_DEPS) + endif() + if(OPENCV_MODULE_${full_modname}_OPT_DEPS) + list(REMOVE_DUPLICATES OPENCV_MODULE_${full_modname}_OPT_DEPS) + endif() + set(OPENCV_MODULE_${full_modname}_REQ_DEPS ${OPENCV_MODULE_${full_modname}_REQ_DEPS} CACHE INTERNAL "Required dependencies of ${full_modname} module") + set(OPENCV_MODULE_${full_modname}_OPT_DEPS ${OPENCV_MODULE_${full_modname}_OPT_DEPS} CACHE INTERNAL "Optional dependencies of ${full_modname} module") + + unset(__depsvar) endmacro() -# opencv precompiled headers macro (can add pch to modules and tests) -# this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work -macro(add_opencv_precompiled_headers the_target) - if("${the_target}" MATCHES "opencv_test_.*") - SET(pch_name "test/test_precomp") - elseif("${the_target}" MATCHES "opencv_perf_.*") - SET(pch_name "perf/perf_precomp") +# declare new OpenCV module in current folder +# Usage: +# ocv_add_module( [INTERNAL|BINDINGS] [REQUIRED] [] [OPTIONAL ]) +# Example: +# ocv_add_module(yaom INTERNAL opencv_core opencv_highgui NOLINK opencv_flann OPTIONAL opencv_gpu) +macro(ocv_add_module _name) + string(TOLOWER "${_name}" name) + string(REGEX REPLACE "^opencv_" "" ${name} "${name}") + set(the_module opencv_${name}) + + # the first pass - collect modules info, the second pass - create targets + if(OPENCV_INITIAL_PASS) + #remember module details + if(NOT DEFINED the_description) + set(the_description "The ${name} OpenCV module") + endif() + set(OPENCV_MODULE_${the_module}_DESCRIPTION "${the_description}" CACHE INTERNAL "Brief description of ${the_module} module") + set(OPENCV_MODULE_${the_module}_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${the_module} module sources") + + #create option to enable/disable this module + option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ON) + if(NOT BUILD_${the_module}) + set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user") else() - SET(pch_name "src/precomp") + #register new module + if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS") + set(__ocv_argn__ ${ARGN}) + list(REMOVE_AT __ocv_argn__ 0) + ocv_add_dependencies(${the_module} ${__ocv_argn__}) + unset(__ocv_argn__) + else() + ocv_add_dependencies(${the_module} ${ARGN}) + set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export") + endif() + set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build") endif() - set(pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${pch_name}.hpp") - if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}") - if(CMAKE_GENERATOR MATCHES Visual) - set(${the_target}_pch "${CMAKE_CURRENT_SOURCE_DIR}/${pch_name}.cpp") - add_native_precompiled_header(${the_target} ${pch_header}) - elseif(CMAKE_GENERATOR MATCHES Xcode) - add_native_precompiled_header(${the_target} ${pch_header}) - elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES Makefiles) - add_precompiled_header(${the_target} ${pch_header}) - endif() + + #TODO: add submodules if any + + #stop processing of current file + return() + else(OPENCV_INITIAL_PASS) + if(NOT BUILD_${the_module}) + #extra protection from redefinition + return() endif() + project(${the_module}) + endif(OPENCV_INITIAL_PASS) endmacro() -# this is a template for a OpenCV performance tests -# define_opencv_perf_test( ) -macro(define_opencv_perf_test name) - set(perf_path "${CMAKE_CURRENT_SOURCE_DIR}/perf") - if(BUILD_PERF_TESTS AND EXISTS "${perf_path}") - - # opencv_highgui is required for imread/imwrite - set(perf_deps opencv_${name} ${ARGN} opencv_ts opencv_highgui ${EXTRA_OPENCV_${name}_DEPS}) - - include_directories("${perf_path}") - opencv_module_includes(${perf_deps}) - - file(GLOB perf_srcs "${perf_path}/*.cpp") - file(GLOB perf_hdrs "${perf_path}/*.h*") - - source_group("Src" FILES ${perf_srcs}) - source_group("Include" FILES ${perf_hdrs}) +# Internal macro; disables OpenCV module +# ocv_module_turn_off() +macro(__ocv_module_turn_off the_module) + list(APPEND OPENCV_MODULES_DISABLED_AUTO "${the_module}") + list(REMOVE_ITEM OPENCV_MODULES_BUILD "${the_module}") + list(REMOVE_ITEM OPENCV_MODULES_PUBLIC "${the_module}") + set(HAVE_${the_module} OFF CACHE INTERNAL "Module ${the_module} can not be built in current configuration") +endmacro() - set(the_target "opencv_perf_${name}") - add_executable(${the_target} ${perf_srcs} ${perf_hdrs}) +macro(ocv_module_disable module) + set(__modname ${module}) + if(NOT __modname MATCHES "^opencv_") + set(__modname opencv_${module}) + endif() + list(APPEND OPENCV_MODULES_DISABLED_FORCE "${__modname}") + set(HAVE_${__modname} OFF CACHE INTERNAL "Module ${__modname} can not be built in current configuration") + set(OPENCV_MODULES_DISABLED_FORCE "${OPENCV_MODULES_DISABLED_FORCE}" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration") + unset(__modname) + return()#leave the current folder +endmacro() - # Additional target properties - set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" - ) - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "performance tests") - endif() +macro(__ocv_flatten_module_required_dependencies the_module) + set(__flattened_deps "") + set(__resolved_deps "") + set(__req_depends ${OPENCV_MODULE_${the_module}_REQ_DEPS}) + + while(__req_depends) + list(GET __req_depends 0 __dep) + list(REMOVE_AT __req_depends 0) + if(__dep STREQUAL the_module) + #TODO: think how to deal with cyclic dependency + __ocv_module_turn_off(${the_module}) + break() + elseif("${OPENCV_MODULES_DISABLED_USER};${OPENCV_MODULES_DISABLED_AUTO}" MATCHES "(^|;)${__dep}(;|$)") + #depends on disabled module + __ocv_module_turn_off(${the_module}) + break() + elseif("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)") + if(__resolved_deps MATCHES "(^|;)${__dep}(;|$)") + #all dependencies of this module are already resolved + list(APPEND __flattened_deps "${__dep}") + else() + #put all required subdependencies before this dependency and mark it as resolved + list(APPEND __resolved_deps "${__dep}") + list(INSERT __req_depends 0 ${OPENCV_MODULE_${__dep}_REQ_DEPS} ${__dep}) + endif() + elseif(__dep MATCHES "^opencv_") + #depends on missing module + __ocv_module_turn_off(${the_module}) + break() + else() + #skip non-modules + endif() + endwhile() + + if(__flattened_deps) + list(REMOVE_DUPLICATES __flattened_deps) + set(OPENCV_MODULE_${the_module}_DEPS ${__flattened_deps}) + else() + set(OPENCV_MODULE_${the_module}_DEPS "") + endif() + + unset(__resolved_deps) + unset(__flattened_deps) + unset(__req_depends) + unset(__dep) +endmacro() - target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${perf_deps}) +macro(__ocv_flatten_module_optional_dependencies the_module) + set(__flattened_deps ${OPENCV_MODULE_${the_module}_DEPS}) + set(__resolved_deps ${OPENCV_MODULE_${the_module}_DEPS}) + set(__opt_depends ${OPENCV_MODULE_${the_module}_OPT_DEPS}) + + while(__opt_depends) + list(GET __opt_depends 0 __dep) + list(REMOVE_AT __opt_depends 0) + if(__dep STREQUAL the_module) + #TODO: think how to deal with cyclic dependency + __ocv_module_turn_off(${the_module}) + break() + elseif("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)") + if(__resolved_deps MATCHES "(^|;)${__dep}(;|$)") + #all dependencies of this module are already resolved + list(APPEND __flattened_deps "${__dep}") + else() + #put all subdependencies before this dependency and mark it as resolved + list(APPEND __resolved_deps "${__dep}") + list(INSERT __opt_depends 0 ${OPENCV_MODULE_${__dep}_REQ_DEPS} ${OPENCV_MODULE_${__dep}_OPT_DEPS} ${__dep}) + endif() + else() + #skip non-modules or missing modules + endif() + endwhile() + if(__flattened_deps) + list(REMOVE_DUPLICATES __flattened_deps) + set(OPENCV_MODULE_${the_module}_DEPS ${__flattened_deps}) + else() + set(OPENCV_MODULE_${the_module}_DEPS "") + endif() + + unset(__resolved_deps) + unset(__flattened_deps) + unset(__opt_depends) + unset(__dep) +endmacro() - add_opencv_precompiled_headers(${the_target}) +macro(__ocv_flatten_module_dependencies) + foreach(m ${OPENCV_MODULES_DISABLED_USER}) + set(HAVE_${m} OFF CACHE INTERNAL "Module ${m} will not be built in current configuration") + endforeach() + foreach(m ${OPENCV_MODULES_BUILD}) + set(HAVE_${m} ON CACHE INTERNAL "Module ${m} will not be built in current configuration") + __ocv_flatten_module_required_dependencies(${m}) + endforeach() + + foreach(m ${OPENCV_MODULES_BUILD}) + __ocv_flatten_module_optional_dependencies(${m}) + + #dependencies from other modules + set(OPENCV_MODULE_${m}_DEPS ${OPENCV_MODULE_${m}_DEPS} CACHE INTERNAL "Flattened dependencies of ${m} module") + #extra dependencies + set(OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_REQ_DEPS} ${OPENCV_MODULE_${m}_OPT_DEPS}) + if(OPENCV_MODULE_${m}_DEPS_EXT AND OPENCV_MODULE_${m}_DEPS) + list(REMOVE_ITEM OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_DEPS}) + endif() + ocv_list_filterout(OPENCV_MODULE_${m}_DEPS_EXT "^opencv_[^ ]+$") + set(OPENCV_MODULE_${m}_DEPS_EXT ${OPENCV_MODULE_${m}_DEPS_EXT} CACHE INTERNAL "Extra dependencies of ${m} module") + endforeach() + + set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} CACHE INTERNAL "List of OpenCV modules marked for export") + set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} CACHE INTERNAL "List of OpenCV modules included into the build") + set(OPENCV_MODULES_DISABLED_AUTO ${OPENCV_MODULES_DISABLED_AUTO} CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies") +endmacro() - if (PYTHON_EXECUTABLE) - add_dependencies(perf ${the_target}) +# collect modules from specified directories +# NB: must be called only once! +macro(ocv_glob_modules) + #collect modules + set(OPENCV_INITIAL_PASS ON) + foreach(__path ${ARGN}) + file(GLOB __ocvmodules RELATIVE "${__path}" "${__path}/*") + if(__ocvmodules) + list(SORT __ocvmodules) + foreach(mod ${__ocvmodules}) + if(EXISTS "${__path}/${mod}/CMakeLists.txt") + add_subdirectory("${__path}/${mod}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}") endif() + endforeach() endif() + endforeach() + unset(__ocvmodules) + + #resolve dependencies + __ocv_flatten_module_dependencies() + + #create modules + set(OPENCV_INITIAL_PASS OFF) + foreach(m ${OPENCV_MODULES_BUILD}) + string(REGEX REPLACE "^opencv_" "" __shortname "${m}") + add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" "${CMAKE_CURRENT_BINARY_DIR}/${__shortname}") + endforeach() + unset(__shortname) endmacro() -# this is a template for a OpenCV regression tests -# define_opencv_test( ) -macro(define_opencv_test name) - set(test_path "${CMAKE_CURRENT_SOURCE_DIR}/test") - if(BUILD_TESTS AND EXISTS "${test_path}") - - # opencv_highgui is required for imread/imwrite - set(test_deps opencv_${name} ${ARGN} opencv_ts opencv_highgui ${EXTRA_OPENCV_${name}_DEPS}) - - include_directories("${test_path}") - opencv_module_includes(${test_deps}) - - file(GLOB test_srcs "${test_path}/*.cpp") - file(GLOB test_hdrs "${test_path}/*.h*") +# setup include paths for the list of passed modules +macro(ocv_include_modules) + foreach(d ${ARGN}) + if(d MATCHES "^opencv_" AND HAVE_${d}) + if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include") + include_directories("${OPENCV_MODULE_${d}_LOCATION}/include") + endif() + elseif(EXISTS "${d}") + include_directories("${d}") + endif() + endforeach() +endmacro() - source_group("Src" FILES ${test_srcs}) - source_group("Include" FILES ${test_hdrs}) +# setup include path for OpenCV headers for specified module +# ocv_module_include_directories() +macro(ocv_module_include_directories) + include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/include" + "${OPENCV_MODULE_${the_module}_LOCATION}/src" + "${CMAKE_CURRENT_BINARY_DIR}"#for precompiled headers + ) + ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS} ${ARGN}) +endmacro() - set(the_target "opencv_test_${name}") - add_executable(${the_target} ${test_srcs} ${test_hdrs}) - # Additional target properties - set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" - ) +# sets header and source files for the current module +# NB: all files specified as headers will be installed +# Usage: +# ocv_set_module_sources([HEADERS] [SOURCES] ) +macro(ocv_set_module_sources) + set(OPENCV_MODULE_${the_module}_HEADERS "") + set(OPENCV_MODULE_${the_module}_SOURCES "") + + foreach(f "HEADERS" ${ARGN}) + if(f STREQUAL "HEADERS" OR f STREQUAL "SOURCES") + set(__filesvar "OPENCV_MODULE_${the_module}_${f}") + else() + list(APPEND ${__filesvar} "${f}") + endif() + endforeach() + + # the hacky way to embeed any files into the OpenCV without modification of its build system + if(COMMAND ocv_get_module_external_sources) + ocv_get_module_external_sources() + endif() - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "tests") - endif() + set(OPENCV_MODULE_${the_module}_HEADERS ${OPENCV_MODULE_${the_module}_HEADERS} CACHE INTERNAL "List of header files for ${the_module}") + set(OPENCV_MODULE_${the_module}_SOURCES ${OPENCV_MODULE_${the_module}_SOURCES} CACHE INTERNAL "List of source files for ${the_module}") +endmacro() - target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${test_deps}) +# finds and sets headers and sources for the standard OpenCV module +# Usage: +# ocv_glob_module_sources() +macro(ocv_glob_module_sources) + file(GLOB lib_srcs "src/*.cpp") + file(GLOB lib_int_hdrs "src/*.hpp" "src/*.h") + file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") + file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h") - enable_testing() - get_target_property(LOC ${the_target} LOCATION) - add_test(${the_target} "${LOC}") + source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs}) + source_group("Include" FILES ${lib_hdrs}) + source_group("Include\\detail" FILES ${lib_hdrs_detail}) - #if(WIN32) - # install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main) - #endif() - add_opencv_precompiled_headers(${the_target}) - endif() + ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} SOURCES ${lib_srcs} ${lib_int_hdrs}) endmacro() -# Set standard properties, install rules and precompiled headers for OpenCV module -macro(opencv_module_setup name) - set(the_target "opencv_${name}") - - # For dynamic link numbering convenions - if(NOT ANDROID) - # Android SDK build scripts can include only .so files into final .apk - # As result we should not set version properties for Android - set_target_properties(${the_target} PROPERTIES - VERSION ${OPENCV_VERSION} - SOVERSION ${OPENCV_SOVERSION} - ) +# creates OpenCV module in current folder +# creates new target, configures standard dependencies, compilers flags, install rules +# Usage: +# ocv_create_module() +macro(ocv_create_module) + add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES}) + target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) + + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_module} PROPERTIES FOLDER "modules") + endif() + + set_target_properties(${the_module} PROPERTIES + OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}" + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} + RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + INSTALL_NAME_DIR lib + ) + + # For dynamic link numbering convenions + if(NOT ANDROID) + # Android SDK build scripts can include only .so files into final .apk + # As result we should not set version properties for Android + set_target_properties(${the_module} PROPERTIES + VERSION ${OPENCV_VERSION} + SOVERSION ${OPENCV_SOVERSION} + ) + endif() + + if(BUILD_SHARED_LIBS) + if(MSVC) + set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS) + else() + add_definitions(-DCVAPI_EXPORTS) endif() + endif() - set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}" ) - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "modules") + if(MSVC) + if(CMAKE_CROSSCOMPILING) + set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk") endif() + set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG") + endif() - if (BUILD_SHARED_LIBS) - if(MSVC) - set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS) - else() - add_definitions(-DCVAPI_EXPORTS) - endif() - endif() + install(TARGETS ${the_module} + RUNTIME DESTINATION bin COMPONENT main + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main + ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - # Additional target properties - set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - INSTALL_NAME_DIR lib - ) + ) - if(MSVC) - if(CMAKE_CROSSCOMPILING) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk") + # only "public" headers need to be installed + if(OPENCV_MODULE_${the_module}_HEADERS AND OPENCV_MODULES_PUBLIC MATCHES "(^|;)${the_module}(;|$)") + install(FILES ${OPENCV_MODULE_${the_module}_HEADERS} + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} COMPONENT main) + endif() +endmacro() + +# opencv precompiled headers macro (can add pch to modules and tests) +# this macro must be called after any "add_definitions" commands, otherwise precompiled headers will not work +# Usage: +# ocv_add_precompiled_headers(${the_module}) +macro(ocv_add_precompiled_headers the_target) + if("${the_target}" MATCHES "^opencv_test_.*$") + SET(pch_path "test/test_") + elseif("${the_target}" MATCHES "^opencv_perf_.*$") + SET(pch_path "perf/perf_") + else() + SET(pch_path "src/") + endif() + set(pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.hpp") + + if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}") + if(CMAKE_GENERATOR MATCHES Visual) + set(${the_target}_pch "${CMAKE_CURRENT_SOURCE_DIR}/${pch_path}precomp.cpp") + add_native_precompiled_header(${the_target} ${pch_header}) + elseif(CMAKE_GENERATOR MATCHES Xcode) + add_native_precompiled_header(${the_target} ${pch_header}) + elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES Makefiles) + add_precompiled_header(${the_target} ${pch_header}) endif() - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG") endif() + unset(pch_header) + unset(pch_path) + unset(${the_target}_pch) +endmacro() - install(TARGETS ${the_target} - RUNTIME DESTINATION bin COMPONENT main - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) +# short command for adding simple OpenCV module +# see ocv_add_module for argument details +# Usage: +# ocv_define_module(module_name [INTERNAL] [REQUIRED] [] [OPTIONAL ]) +macro(ocv_define_module module_name) + ocv_add_module(${module_name} ${ARGN}) + ocv_glob_module_sources() + ocv_module_include_directories() + ocv_create_module() + ocv_add_precompiled_headers(${the_module}) + + ocv_add_accuracy_tests() + ocv_add_perf_tests() +endmacro() - if(lib_hdrs) - install(FILES ${lib_hdrs} - DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} - COMPONENT main) +# ensures that all passed modules are available +# sets OCV_DEPENDENCIES_FOUND variable to TRUE/FALSE +macro(ocv_check_dependencies) + set(OCV_DEPENDENCIES_FOUND TRUE) + foreach(d ${ARGN}) + if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d}) + set(OCV_DEPENDENCIES_FOUND FALSE) + break() endif() - - add_opencv_precompiled_headers(${the_target}) + endforeach() endmacro() -# this is a template for a OpenCV module declaration -# define_opencv_moduleEx( [public|internal] ) -macro(define_opencv_moduleEx _name _visibility) - string(TOLOWER "${_name}" name) - string(TOUPPER "${_name}" mname) - string(TOLOWER "${_visibility}" visibility) - - option(OCVMODULE_${mname} "Include ${name} module into the OpenCV build" ON) - if(OCVMODULE_${mname}) - set(the_target "opencv_${name}") - project(${the_target}) - - opencv_module_includes(${ARGN}) +#auxiliary macro to parse arguments of ocv_add_accuracy_tests and ocv_add_perf_tests commands +macro(__ocv_parse_test_sources tests_type) + set(OPENCV_${tests_type}_${the_module}_SOURCES "") + set(OPENCV_${tests_type}_${the_module}_DEPS "") + set(__file_group_name "") + set(__file_group_sources "") + foreach(arg "DEPENDS_ON" ${ARGN} "FILES") + if(arg STREQUAL "FILES") + set(__currentvar "__file_group_sources") + if(__file_group_name AND __file_group_sources) + source_group("${__file_group_name}" FILES ${__file_group_sources}) + list(APPEND OPENCV_${tests_type}_${the_module}_SOURCES ${__file_group_sources}) + endif() + set(__file_group_name "") + set(__file_group_sources "") + elseif(arg STREQUAL "DEPENDS_ON") + set(__currentvar "OPENCV_TEST_${the_module}_DEPS") + elseif("${__currentvar}" STREQUAL "__file_group_sources" AND NOT __file_group_name) + set(__file_group_name "${arg}") + else() + list(APPEND ${__currentvar} "${arg}") + endif() + endforeach() + unset(__file_group_name) + unset(__file_group_sources) + unset(__currentvar) +endmacro() - file(GLOB lib_srcs "src/*.cpp") - file(GLOB lib_int_hdrs "src/*.h*") - file(GLOB lib_hdrs "include/opencv2/${name}/*.h*") - file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.h*") +# this is a command for adding OpenCV performance tests to the module +# ocv_add_perf_tests() +macro(ocv_add_perf_tests) + set(perf_path "${CMAKE_CURRENT_SOURCE_DIR}/perf") + if(BUILD_PERF_TESTS AND EXISTS "${perf_path}") + __ocv_parse_test_sources(PERF ${ARGN}) - if(COMMAND get_module_external_sources) - get_module_external_sources(${name}) - endif() + # opencv_highgui is required for imread/imwrite + set(perf_deps ${the_module} opencv_ts opencv_highgui ${OPENCV_PERF_${the_module}_DEPS}) + ocv_check_dependencies(${perf_deps}) - source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs}) - source_group("Include" FILES ${lib_hdrs}) - source_group("Include\\detail" FILES ${lib_hdrs_detail}) + if(OCV_DEPENDENCIES_FOUND) + set(the_target "opencv_perf_${name}") + #project(${the_target}) + + ocv_module_include_directories(${perf_deps} "${perf_path}") - list(APPEND lib_hdrs ${lib_hdrs_detail}) + if(NOT OPENCV_PERF_${the_module}_SOURCES) + file(GLOB perf_srcs "${perf_path}/*.cpp") + file(GLOB perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h") + source_group("Src" FILES ${perf_srcs}) + source_group("Include" FILES ${perf_hdrs}) + set(OPENCV_PERF_${the_module}_SOURCES ${perf_srcs} ${perf_hdrs}) + endif() - if(HAVE_CUDA AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cuda") - file(GLOB lib_cuda "src/cuda/*.cu") - source_group("Cuda" FILES "${lib_cuda}") - - include_directories(${CUDA_INCLUDE_DIRS}) - include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/src") - include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/src/cuda") - - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_10,code=sm_10 - -gencode arch=compute_11,code=sm_11 - -gencode arch=compute_12,code=sm_12 - -gencode arch=compute_13,code=sm_13 - -gencode arch=compute_20,code=sm_20 - -gencode arch=compute_20,code=sm_21) - - if(UNIX OR APPLE) - set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fPIC) - endif() - if(APPLE) - set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fno-finite-math-only) - endif() + add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES}) + target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${perf_deps}) - #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep") - #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/EHsc-;") - - # we remove -ggdb3 flag as it leads to preprocessor errors when compiling CUDA files (CUDA 4.1) - set(tmp ${CMAKE_CXX_FLAGS_DEBUG}) - string(REPLACE "-ggdb3" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) - CUDA_COMPILE(cuda_objs ${lib_cuda}) - set(CMAKE_CXX_DEBUG_FLAGS ${tmp}) + # Additional target properties + set_target_properties(${the_target} PROPERTIES + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" + ) + + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "tests performance") + endif() + + ocv_add_precompiled_headers(${the_target}) + + if (PYTHON_EXECUTABLE) + add_dependencies(perf ${the_target}) + endif() + else(OCV_DEPENDENCIES_FOUND) + #TODO: warn about unsatisfied dependencies + endif(OCV_DEPENDENCIES_FOUND) + endif() +endmacro() - else() - set(lib_cuda "") - set(cuda_objs "") - endif() +# this is a command for adding OpenCV accuracy/regression tests to the module +# ocv_add_accuracy_tests([FILES ] [DEPENDS_ON] ) +macro(ocv_add_accuracy_tests) + set(test_path "${CMAKE_CURRENT_SOURCE_DIR}/test") + ocv_check_dependencies(${test_deps}) + if(BUILD_TESTS AND EXISTS "${test_path}") + __ocv_parse_test_sources(TEST ${ARGN}) + + # opencv_highgui is required for imread/imwrite + set(test_deps ${the_module} opencv_ts opencv_highgui ${OPENCV_TEST_${the_module}_DEPS}) + ocv_check_dependencies(${test_deps}) + + if(OCV_DEPENDENCIES_FOUND) + set(the_target "opencv_test_${name}") + #project(${the_target}) + + ocv_module_include_directories(${test_deps} "${test_path}") - add_library(${the_target} ${OPENCV_${mname}_MODULE_TYPE} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${lib_cuda} ${cuda_objs}) - target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) + if(NOT OPENCV_TEST_${the_module}_SOURCES) + file(GLOB test_srcs "${test_path}/*.cpp") + file(GLOB test_hdrs "${test_path}/*.hpp" "${test_path}/*.h") + source_group("Src" FILES ${test_srcs}) + source_group("Include" FILES ${test_hdrs}) + set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs}) + endif() + + add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES}) + target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${test_deps}) - if(HAVE_CUDA AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cuda") - target_link_libraries(${the_target} ${CUDA_LIBRARIES}) + # Additional target properties + set_target_properties(${the_target} PROPERTIES + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" + ) + + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy") + endif() + + enable_testing() + get_target_property(LOC ${the_target} LOCATION) + add_test(${the_target} "${LOC}") + + ocv_add_precompiled_headers(${the_target}) + else(OCV_DEPENDENCIES_FOUND) + #TODO: warn about unsatisfied dependencies + endif(OCV_DEPENDENCIES_FOUND) + endif() +endmacro() - unset(CUDA_npp_LIBRARY CACHE) - find_cuda_helper_libs(npp) - target_link_libraries(${the_target} ${CUDA_npp_LIBRARY}) - endif() +# internal macro; finds all link dependencies of module +# should be used at the end of CMake processing +macro(__ocv_track_module_link_dependencies the_module optkind) + set(${the_module}_MODULE_DEPS_${optkind} "") + set(${the_module}_EXTRA_DEPS_${optkind} "") + + get_target_property(__module_type ${the_module} TYPE) + if(__module_type STREQUAL "STATIC_LIBRARY") + #in case of static library we have to inherit its dependencies (in right order!!!) + if(NOT DEFINED ${the_module}_LIB_DEPENDS_${optkind}) + ocv_split_libs_list(${the_module}_LIB_DEPENDS ${the_module}_LIB_DEPENDS_DBG ${the_module}_LIB_DEPENDS_OPT) + endif() - if(visibility STREQUAL "public") - opencv_module_register(${the_target}) + set(__resolved_deps "") + set(__mod_depends ${${the_module}_LIB_DEPENDS_${optkind}}) + set(__has_cycle FALSE) + + while(__mod_depends) + list(GET __mod_depends 0 __dep) + list(REMOVE_AT __mod_depends 0) + if(__dep STREQUAL the_module) + set(__has_cycle TRUE) + else()#if("${OPENCV_MODULES_BUILD}" MATCHES "(^|;)${__dep}(;|$)") + ocv_regex_escape(__rdep "${__dep}") + if(__resolved_deps MATCHES "(^|;)${__rdep}(;|$)") + #all dependencies of this module are already resolved + list(APPEND ${the_module}_MODULE_DEPS_${optkind} "${__dep}") + else() + get_target_property(__module_type ${__dep} TYPE) + if(__module_type STREQUAL "STATIC_LIBRARY") + if(NOT DEFINED ${__dep}_LIB_DEPENDS_${optkind}) + ocv_split_libs_list(${__dep}_LIB_DEPENDS ${__dep}_LIB_DEPENDS_DBG ${__dep}_LIB_DEPENDS_OPT) + endif() + list(INSERT __mod_depends 0 ${${__dep}_LIB_DEPENDS_${optkind}} ${__dep}) + list(APPEND __resolved_deps "${__dep}") + elseif(NOT __module_type) + list(APPEND ${the_module}_EXTRA_DEPS_${optkind} "${__dep}") + endif() endif() - - opencv_module_setup(${name}) - define_opencv_test(${name}) - define_opencv_perf_test(${name}) + #else() + # get_target_property(__dep_location "${__dep}" LOCATION) + endif() + endwhile() + + ocv_list_unique(${the_module}_MODULE_DEPS_${optkind}) + #ocv_list_reverse(${the_module}_MODULE_DEPS_${optkind}) + ocv_list_unique(${the_module}_EXTRA_DEPS_${optkind}) + #ocv_list_reverse(${the_module}_EXTRA_DEPS_${optkind}) + + if(__has_cycle) + #not sure if it can work + list(APPEND ${the_module}_MODULE_DEPS_${optkind} "${the_module}") endif() -endmacro() -# this is a shorthand for a public OpenCV module declaration -# define_opencv_module( ) -macro(define_opencv_module name) - define_opencv_moduleEx(${name} PUBLIC ${ARGN}) + unset(__dep_location) + unset(__mod_depends) + unset(__resolved_deps) + unset(__has_cycle) + unset(__rdep) + endif()#STATIC_LIBRARY + unset(__module_type) + +#message("${the_module}_MODULE_DEPS_${optkind}") +#message(" ${${the_module}_MODULE_DEPS_${optkind}}") +#message(" ${OPENCV_MODULE_${the_module}_DEPS}") +#message("") +#message("${the_module}_EXTRA_DEPS_${optkind}") +#message(" ${${the_module}_EXTRA_DEPS_${optkind}}") +#message("") endmacro() +# creates lists of build dependencies needed for external projects +macro(ocv_track_build_dependencies) + foreach(m ${OPENCV_MODULES_BUILD}) + __ocv_track_module_link_dependencies("${m}" OPT) + __ocv_track_module_link_dependencies("${m}" DBG) + endforeach() +endmacro() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index d8f09c8cc8..7dfe938921 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1,14 +1,14 @@ # Search packages for host system instead of packages for target system # in case of cross compilation thess macro should be defined by toolchain file if(NOT COMMAND find_host_package) - macro(find_host_package) - find_package(${ARGN}) - endmacro() + macro(find_host_package) + find_package(${ARGN}) + endmacro() endif() if(NOT COMMAND find_host_program) - macro(find_host_program) - find_program(${ARGN}) - endmacro() + macro(find_host_program) + find_program(${ARGN}) + endmacro() endif() @@ -17,17 +17,17 @@ endif() # Usage: # option( "help string describing option" [IF ]) macro(OCV_OPTION variable description value) - SET(__condition ${ARGN}) - if("${__condition}" STREQUAL "") - SET(__condition 1) - endif() - list(REMOVE_ITEM __condition "IF" "if") - if(${__condition}) - OPTION(${variable} "${description}" ${value}) - else() - UNSET(${variable} CACHE) - endif() - UNSET(__condition) + SET(__condition ${ARGN}) + if("${__condition}" STREQUAL "") + SET(__condition 1) + endif() + list(REMOVE_ITEM __condition "IF" "if") + if(${__condition}) + OPTION(${variable} "${description}" ${value}) + else() + UNSET(${variable} CACHE) + endif() + UNSET(__condition) endmacro() @@ -115,3 +115,62 @@ macro(status text) message(STATUS "${text}") endif() endmacro() + +# splits cmake libraries list of format "general;item1;debug;item2;release;item3" to two lists +macro(ocv_split_libs_list lst lstdbg lstopt) + set(${lstdbg} "") + set(${lstopt} "") + set(perv_keyword "") + foreach(word ${${lst}}) + if(word STREQUAL "debug" OR word STREQUAL "optimized") + set(perv_keyword ${word}) + elseif(word STREQUAL "general") + set(perv_keyword "") + elseif(perv_keyword STREQUAL "debug") + list(APPEND ${lstdbg} "${word}") + set(perv_keyword "") + elseif(perv_keyword STREQUAL "optimized") + list(APPEND ${lstopt} "${word}") + set(perv_keyword "") + else() + list(APPEND ${lstdbg} "${word}") + list(APPEND ${lstopt} "${word}") + set(perv_keyword "") + endif() + endforeach() +endmacro() + +# remove all matching elements from the list +macro(ocv_list_filterout lst regex) + foreach(item ${${lst}}) + if(item MATCHES "${regex}") + list(REMOVE_ITEM ${lst} "${item}") + endif() + endforeach() +endmacro() + +# stable & safe duplicates removal macro +macro(ocv_list_unique __lst) + if(${__lst}) + list(REMOVE_DUPLICATES ${__lst}) + endif() +endmacro() + +# safe list reversal macro +macro(ocv_list_reverse __lst) + if(${__lst}) + list(REVERSE ${__lst}) + endif() +endmacro() + +# safe list sorting macro +macro(ocv_list_sort __lst) + if(${__lst}) + list(SORT ${__lst}) + endif() +endmacro() + +# simple regex escaping routine (does not cover all cases!!!) +macro(ocv_regex_escape var regex) + string(REGEX REPLACE "([+.*^$])" "\\\\1" ${var} "${regex}") +endmacro() diff --git a/cmake/OpenCVVersion.cmake b/cmake/OpenCVVersion.cmake new file mode 100644 index 0000000000..241032590d --- /dev/null +++ b/cmake/OpenCVVersion.cmake @@ -0,0 +1,28 @@ +SET(OPENCV_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/modules/core/include/opencv2/core/version.hpp") +FILE(STRINGS "${OPENCV_VERSION_FILE}" OPENCV_VERSION_PARTS REGEX "#define CV_.+OR_VERSION[ ]+[0-9]+" ) +string(REGEX REPLACE ".+CV_MAJOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MAJOR "${OPENCV_VERSION_PARTS}") +string(REGEX REPLACE ".+CV_MINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_MINOR "${OPENCV_VERSION_PARTS}") +string(REGEX REPLACE ".+CV_SUBMINOR_VERSION[ ]+([0-9]+).*" "\\1" OPENCV_VERSION_PATCH "${OPENCV_VERSION_PARTS}") +set(OPENCV_VERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}") + +set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}") + +# create a dependency on version file +# we never use output of the following command but cmake will rerun automatically if the version file changes +configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY) + +if(WIN32) + # Postfix of DLLs: + set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}") + set(OPENCV_DEBUG_POSTFIX d) +else() + # Postfix of so's: + set(OPENCV_DLLVERSION "") + set(OPENCV_DEBUG_POSTFIX) +endif() + +#name mangling +set(OPENCV_INCLUDE_PREFIX include) +if(INSTALL_TO_MANGLED_PATHS) + set(OPENCV_INCLUDE_PREFIX include/opencv-${OPENCV_VERSION}) +endif() diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index bed9248420..ae5087b3c2 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -1,33 +1,37 @@ # In order to compile your application under cygwin -# you need to define NDK_USE_CYGPATH=1 before calling ndk-build +# you might need to define NDK_USE_CYGPATH=1 before calling the ndk-build USER_LOCAL_PATH:=$(LOCAL_PATH) LOCAL_PATH:=$(subst ?,,$(firstword ?$(subst \, ,$(subst /, ,$(call my-dir))))) OPENCV_THIS_DIR:=$(patsubst $(LOCAL_PATH)\\%,%,$(patsubst $(LOCAL_PATH)/%,%,$(call my-dir))) -OPENCV_LIBS_DIR:=@CMAKE_LIBS_DIR_CONFIGCMAKE@ -OPENCV_BASEDIR:=@CMAKE_BASE_INCLUDE_DIR_CONFIGCMAKE@ -OPENCV_LOCAL_C_INCLUDES:=@CMAKE_INCLUDE_DIRS_CONFIGCMAKE@ +OPENCV_LIBS_DIR:=@OPENCV_LIBS_DIR_CONFIGCMAKE@ +OPENCV_BASEDIR:=@OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE@ +OPENCV_LOCAL_C_INCLUDES:=@OPENCV_INCLUDE_DIRS_CONFIGCMAKE@ -OPENCV_MODULES := contrib legacy stitching objdetect calib3d features2d video highgui imgproc ml flann core +OPENCV_LIB_TYPE:=@OPENCV_LIBTYPE_CONFIGMAKE@ +OPENCV_MODULES:=@OPENCV_MODULES_CONFIGMAKE@ +OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ +OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ ifeq (${OPENCV_CAMERA_MODULES},off) OPENCV_CAMERA_MODULES:= else - OPENCV_CAMERA_MODULES:=@CMAKE_CAMERA_LIBS_CONFIGCMAKE@ + ifeq ($(TARGET_ARCH_ABI),armeabi) + OPENCV_CAMERA_MODULES:=@OPENCV_CAMERA_LIBS_ARMEABI_CONFIGCMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) + OPENCV_CAMERA_MODULES:=@OPENCV_CAMERA_LIBS_ARMEABI_V7A_CONFIGCMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),x86) + OPENCV_CAMERA_MODULES:=@OPENCV_CAMERA_LIBS_X86_CONFIGCMAKE@ + endif endif -OPENCV_LIB_TYPE:=@OPENCV_LIBTYPE_CONFIGMAKE@ - ifeq ($(OPENCV_LIB_TYPE),SHARED) OPENCV_LIB_SUFFIX:=so - OPENCV_EXTRA_COMPONENTS:= else OPENCV_LIB_SUFFIX:=a - ifeq (@WITH_ANDROID_CAMERA@,ON) - OPENCV_MODULES+= androidcamera - endif - OPENCV_EXTRA_COMPONENTS:=@JPEG_LIBRARIES@ @PNG_LIBRARIES@ @TIFF_LIBRARIES@ @JASPER_LIBRARIES@ @ZLIB_LIBRARY@ endif define add_opencv_module @@ -37,7 +41,7 @@ define add_opencv_module include $(PREBUILT_@OPENCV_LIBTYPE_CONFIGMAKE@_LIBRARY) endef -define add_opencv_extra_component +define add_opencv_3rdparty_component include $(CLEAR_VARS) LOCAL_MODULE:=$1 LOCAL_SRC_FILES:=$(OPENCV_THIS_DIR)/3rdparty/libs/$(TARGET_ARCH_ABI)/lib$1.a @@ -52,7 +56,7 @@ define add_opencv_camera_module endef $(foreach module,$(OPENCV_MODULES),$(eval $(call add_opencv_module,$(module)))) -$(foreach module,$(OPENCV_EXTRA_COMPONENTS),$(eval $(call add_opencv_extra_component,$(module)))) +$(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module)))) $(foreach module,$(OPENCV_CAMERA_MODULES),$(eval $(call add_opencv_camera_module,$(module)))) ifneq ($(OPENCV_BASEDIR),) @@ -70,5 +74,7 @@ include $(CLEAR_VARS) LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES) LOCAL_STATIC_LIBRARIES += $(OPENCV_LOCAL_LIBRARIES) LOCAL_CFLAGS += $(OPENCV_LOCAL_CFLAGS) +LOCAL_LDLIBS += $(foreach lib,$(OPENCV_EXTRA_COMPONENTS), -l$(lib)) +#restore the LOCAL_PATH LOCAL_PATH:=$(USER_LOCAL_PATH) diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index 468ea327f7..0fae74cc22 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -6,43 +6,50 @@ # Usage from an external project: # In your CMakeLists.txt, add these lines: # -# FIND_PACKAGE(OpenCV REQUIRED ) +# FIND_PACKAGE(OpenCV REQUIRED) # TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${OpenCV_LIBS}) # +# Or you can search for specific OpenCV modules: +# +# FIND_PACKAGE(OpenCV REQUIRED core highgui) +# +# If the module found then OPENCV__FOUND is set. +# # This file will define the following variables: -# - OpenCV_LIBS : The list of libraries to links against. -# - OpenCV_LIB_DIR : The directory where lib files are. Calling LINK_DIRECTORIES -# with this path is NOT needed. -# - OpenCV_INCLUDE_DIRS : The OpenCV include directories. -# - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability -# - OpenCV_VERSION : The version of this OpenCV build. Example: "@OPENCV_VERSION@" -# - OpenCV_VERSION_MAJOR : Major version part of OpenCV_VERSION. Example: "@OPENCV_VERSION_MAJOR@" -# - OpenCV_VERSION_MINOR : Minor version part of OpenCV_VERSION. Example: "@OPENCV_VERSION_MINOR@" -# - OpenCV_VERSION_PATCH : Patch version part of OpenCV_VERSION. Example: "@OPENCV_VERSION_PATCH@" +# - +# - OpenCV_LIBS : The list of libraries to links against. +# - OpenCV_LIB_DIR : The directory where lib files are. Calling LINK_DIRECTORIES +# with this path is NOT needed. +# - OpenCV_INCLUDE_DIRS : The OpenCV include directories. +# - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability +# - OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API +# - OpenCV_VERSION : The version of this OpenCV build. Example: "@OPENCV_VERSION@" +# - OpenCV_VERSION_MAJOR : Major version part of OpenCV_VERSION. Example: "@OPENCV_VERSION_MAJOR@" +# - OpenCV_VERSION_MINOR : Minor version part of OpenCV_VERSION. Example: "@OPENCV_VERSION_MINOR@" +# - OpenCV_VERSION_PATCH : Patch version part of OpenCV_VERSION. Example: "@OPENCV_VERSION_PATCH@" # # Advanced variables: # - OpenCV_SHARED # - OpenCV_CONFIG_PATH # - OpenCV_INSTALL_PATH # - OpenCV_LIB_COMPONENTS -# - OpenCV_EXTRA_COMPONENTS # - OpenCV_USE_MANGLED_PATHS # - OpenCV_HAVE_ANDROID_CAMERA # - OpenCV_SOURCE_PATH # # ================================================================================================= -# ====================================================== -# Version Compute Capability from which library OpenCV -# has been compiled is remembered -# ====================================================== -SET(OpenCV_COMPUTE_CAPABILITIES @OpenCV_CUDA_CC@) +# Version Compute Capability from which OpenCV has been compiled is remembered +set(OpenCV_COMPUTE_CAPABILITIES @OpenCV_CUDA_CC_CONFIGMAKE@) + +# Android API level from which OpenCV has been compiled is remembered +set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGMAKE@) # Some additional settings are required if OpenCV is built as static libs set(OpenCV_SHARED @BUILD_SHARED_LIBS@) # Enables mangled install paths, that help with side by side installs -set(OpenCV_USE_MANGLED_PATHS @OPENCV_MANGLED_INSTALL_PATHS@) +set(OpenCV_USE_MANGLED_PATHS @OpenCV_USE_MANGLED_PATHS@) # Extract the directory where *this* file has been installed (determined at cmake run-time) get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH) @@ -50,86 +57,172 @@ get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH) # Get the absolute path with no ../.. relative marks, to eliminate implicit linker warnings get_filename_component(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/../.." REALPATH) -# Presence of Android native camera support -set (OpenCV_HAVE_ANDROID_CAMERA @WITH_ANDROID_CAMERA@) +# Presence of Android native camera wrappers +set(OpenCV_HAVE_ANDROID_CAMERA @HAVE_opencv_androidcamera@) # ====================================================== # Include directories to add to the user project: # ====================================================== # Provide the include directories to the caller -SET(OpenCV_INCLUDE_DIRS @CMAKE_INCLUDE_DIRS_CONFIGCMAKE@) -INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) +set(OpenCV_INCLUDE_DIRS @CMAKE_INCLUDE_DIRS_CONFIGCMAKE@) +include_directories(${OpenCV_INCLUDE_DIRS}) # ====================================================== # Link directories to add to the user project: # ====================================================== -# Provide the libs directory anyway, it may be needed in some cases. +# Provide the libs directories to the caller SET(OpenCV_LIB_DIR @CMAKE_LIB_DIRS_CONFIGCMAKE@) -LINK_DIRECTORIES(${OpenCV_LIB_DIR}) +link_directories(${OpenCV_LIB_DIR}) + +# ====================================================== +# Version variables: +# ====================================================== +SET(OpenCV_VERSION @OPENCV_VERSION@) +SET(OpenCV_VERSION_MAJOR @OPENCV_VERSION_MAJOR@) +SET(OpenCV_VERSION_MINOR @OPENCV_VERSION_MINOR@) +SET(OpenCV_VERSION_PATCH @OPENCV_VERSION_PATCH@) # ==================================================================== # Link libraries: e.g. libopencv_core.so, opencv_imgproc220d.lib, etc... # ==================================================================== -# OpenCV internal dependencies: -# opencv_androidcamera -> {} -# opencv_core -> {} -# opencv_flann -> {opencv_core} -# opencv_imgproc -> {opencv_core} -# opencv_ml -> {opencv_core} -# opencv_highgui -> {opencv_core, opencv_imgproc, opencv_androidcamera} -# opencv_video -> {opencv_core, opencv_imgproc} -# opencv_features2d -> {opencv_core, opencv_imgproc, opencv_flann, opencv_highgui} -# opencv_calib3d -> {opencv_core, opencv_imgproc, opencv_flann, opencv_features2d} -# opencv_objdetect -> {opencv_core, opencv_imgproc, opencv_flann, opencv_highgui, opencv_features2d, opencv_calib3d} -# opencv_gpu -> {opencv_core, opencv_imgproc, opencv_flann, opencv_features2d, opencv_calib3d, opencv_objdetect} -# opencv_stitching -> {opencv_core, opencv_imgproc, opencv_flann, opencv_features2d, opencv_calib3d, opencv_objdetect, opencv_gpu} -# opencv_legacy -> {opencv_core, opencv_imgproc, opencv_flann, opencv_highgui, opencv_features2d, opencv_calib3d, opencv_video} -# opencv_contrib -> {opencv_core, opencv_imgproc, opencv_flann, opencv_highgui, opencv_features2d, opencv_calib3d, opencv_objdetect, opencv_video, opencv_ml} - -SET(OpenCV_LIB_COMPONENTS opencv_contrib opencv_legacy opencv_stitching opencv_gpu opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core opencv_androidcamera) - -# remove modules unavailable on current platform: -if(ANDROID) - LIST(REMOVE_ITEM OpenCV_LIB_COMPONENTS opencv_gpu) - SET(OpenCV_LIB_ANDROID @OpenCV_LIB_ANDROID@) - IF(OpenCV_LIB_ANDROID) - SET(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS} ${OpenCV_LIB_ANDROID}) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-shlib-undefined") - ENDIF() +SET(OpenCV_LIB_COMPONENTS @OPENCV_MODULES_CONFIGMAKE@) + +@OPENCV_DEPENDENCIES_MAP_OPT@ + +@OPENCV_DEPENDENCIES_MAP_DBG@ + + +# ============================================================== +# Check OpenCV availability +# ============================================================== +if(ANDROID AND OpenCV_ANDROID_NATIVE_API_LEVEL LESS ANDROID_NATIVE_API_LEVEL) + message(FATAL_ERROR "Minimum required by OpenCV API level is android-${OpenCV_ANDROID_NATIVE_API_LEVEL}") + #always FATAL_ERROR because we can't say to the caller that OpenCV is not found + #http://www.mail-archive.com/cmake@cmake.org/msg37831.html + if(OpenCV_FIND_REQUIRED) + message(FATAL_ERROR "Minimum required by OpenCV API level is android-${OpenCV_ANDROID_NATIVE_API_LEVEL}") + elseif(NOT OpenCV_FIND_QUIETLY) + message(WARNING "Minimum required by OpenCV API level is android-${OpenCV_ANDROID_NATIVE_API_LEVEL}") + endif() + set(OpenCV_FOUND "OpenCV_FOUND-NOTFOUND") + return()#Android toolchain requires CMake > 2.6 endif() -if(NOT ANDROID OR OpenCV_SHARED OR NOT OpenCV_HAVE_ANDROID_CAMERA) - LIST(REMOVE_ITEM OpenCV_LIB_COMPONENTS opencv_androidcamera) + +# ============================================================== +# Form list of modules (components) to find +# ============================================================== +if(NOT OpenCV_FIND_COMPONENTS) + set(OpenCV_FIND_COMPONENTS ${OpenCV_LIB_COMPONENTS}) endif() +#expand short module names +set(OpenCV_FIND_COMPONENTS_ "") +foreach(__cvcomponent ${OpenCV_FIND_COMPONENTS}) + if(NOT __cvcomponent MATCHES "^opencv_") + set(__cvcomponent opencv_${__cvcomponent}) + endif() + list(FIND OpenCV_LIB_COMPONENTS ${__cvcomponent} __cvcomponentIdx) + if(__cvcomponentIdx LESS 0) + if(OpenCV_FIND_REQUIRED) + message(FATAL_ERROR "${__cvcomponent} is required but was not found") + elseif(NOT OpenCV_FIND_QUIETLY) + message(WARNING "${__cvcomponent} is required but was not found") + endif() + string(TOUPPER "${__cvcomponent}" __cvcomponent) + set(${__cvcomponent}_FOUND "${__cvcomponent}_FOUND-NOTFOUND") + else() + list(APPEND OpenCV_FIND_COMPONENTS_ ${__cvcomponent}) + endif() +endforeach() +set(OpenCV_FIND_COMPONENTS ${OpenCV_FIND_COMPONENTS_}) + +# ============================================================== +# Resolve dependencies +# ============================================================== if(OpenCV_USE_MANGLED_PATHS) - #be explicit about the library names. - set(OpenCV_LIB_COMPONENTS_ ) - foreach( CVLib ${OpenCV_LIB_COMPONENTS}) - list(APPEND OpenCV_LIB_COMPONENTS_ ${OpenCV_LIB_DIR}/lib${CVLib}.so.@OPENCV_VERSION@ ) - endforeach() - set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_}) + set(OpenCV_LIB_SUFFIX_DBG ".so.${OpenCV_VERSION}") + set(OpenCV_LIB_SUFFIX_OPT ".so.${OpenCV_VERSION}") +else() + set(OpenCV_LIB_SUFFIX_DBG "@OPENCV_DLLVERSION@@OPENCV_DEBUG_POSTFIX@") + set(OpenCV_LIB_SUFFIX_OPT "@OPENCV_DLLVERSION@") endif() +set(OpenCV_3RDPARTY_LIB_SUFFIX_DBG "@OPENCV_DEBUG_POSTFIX@") +set(OpenCV_3RDPARTY_LIB_SUFFIX_OPT "") -SET(OpenCV_LIBS "") -if(WIN32) - foreach(__CVLIB ${OpenCV_LIB_COMPONENTS}) - # CMake>=2.6 supports the notation "debug XXd optimized XX" - if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 2.4) - # Modern CMake: - SET(OpenCV_LIBS ${OpenCV_LIBS} debug ${__CVLIB}@OPENCV_DLLVERSION@@OPENCV_DEBUG_POSTFIX@ optimized ${__CVLIB}@OPENCV_DLLVERSION@) +# choose required dependencies +set(OpenCV_NEED_3RDPARTY_LINK_DEPS FALSE) +set(OpenCV_REQUIRED_MODULES ${OpenCV_FIND_COMPONENTS}) +foreach(__opttype OPT DBG) + SET(OpenCV_LIBS_${__opttype} "") + SET(OpenCV_EXTRA_LIBS_${__opttype} "") + foreach(__cvlib ${OpenCV_FIND_COMPONENTS}) + foreach(__cvdep ${OpenCV_${__cvlib}_DEPS_${__opttype}}) + if(__cvdep MATCHES "^opencv_") + list(APPEND OpenCV_LIBS_${__opttype} ${__cvdep}${OpenCV_LIB_SUFFIX_${__opttype}}) + list(APPEND OpenCV_REQUIRED_MODULES ${__cvdep}) + #indicate that this module is also found + string(TOUPPER "${__cvdep}" __cvdep) + set(${__cvdep}_FOUND 1) else() - # Old CMake: - SET(OpenCV_LIBS ${OpenCV_LIBS} ${__CVLIB}@OPENCV_DLLVERSION@) + list(APPEND OpenCV_LIBS_${__opttype} ${__cvdep}${OpenCV_3RDPARTY_LIB_SUFFIX_${__opttype}}) + set(OpenCV_NEED_3RDPARTY_LINK_DEPS TRUE) endif() + endforeach() + list(APPEND OpenCV_LIBS_${__opttype} ${__cvlib}${OpenCV_LIB_SUFFIX_${__opttype}}) + list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${OpenCV_${__cvlib}_EXTRA_DEPS_${__opttype}}) + #indicate that module is found + string(TOUPPER "${__cvlib}" __cvlib) + set(${__cvlib}_FOUND 1) endforeach() -else() - foreach(__CVLIB ${OpenCV_LIB_COMPONENTS}) - SET(OpenCV_LIBS ${OpenCV_LIBS} ${__CVLIB}) + + if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 2.4) + if(OpenCV_LIBS_${__opttype}) + list(REMOVE_DUPLICATES OpenCV_LIBS_${__opttype}) + endif() + if(OpenCV_EXTRA_LIBS_${__opttype}) + list(REMOVE_DUPLICATES OpenCV_EXTRA_LIBS_${__opttype}) + endif() + if(OpenCV_REQUIRED_MODULES) + list(REMOVE_DUPLICATES OpenCV_REQUIRED_MODULES) + endif() + else() + #TODO: duplicates are annoying but they should not be the problem + endif() +endforeach() + +if(OpenCV_NEED_3RDPARTY_LINK_DEPS) + list(APPEND OpenCV_LIB_DIR @CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE@) + link_directories(@CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE@) +endif() + +if(OpenCV_LIBS_DBG) + list(REVERSE OpenCV_LIBS_DBG) +endif() + +if(OpenCV_LIBS_OPT) + list(REVERSE OpenCV_LIBS_OPT) +endif() + +# CMake>=2.6 supports the notation "debug XXd optimized XX" +if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 2.4) + # Modern CMake: + SET(OpenCV_LIBS "") + foreach(__cvlib ${OpenCV_LIBS_DBG} ${OpenCV_EXTRA_LIBS_DBG}) + list(APPEND OpenCV_LIBS debug "${__cvlib}") + endforeach() + foreach(__cvlib ${OpenCV_LIBS_OPT} ${OpenCV_EXTRA_LIBS_OPT}) + list(APPEND OpenCV_LIBS optimized "${__cvlib}") endforeach() +else() + # Old CMake: + if(CMAKE_BUILD_TYPE MATCHES "Debug") + SET(OpenCV_LIBS ${OpenCV_LIBS_DBG} ${OpenCV_EXTRA_LIBS_DBG}) + else() + SET(OpenCV_LIBS ${OpenCV_LIBS_OPT} ${OpenCV_EXTRA_LIBS_OPT}) + endif() endif() # ============================================================== @@ -137,62 +230,33 @@ endif() # ============================================================== SET(OpenCV_SOURCE_PATH "@CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE@") if(NOT "${OpenCV_SOURCE_PATH}" STREQUAL "") - foreach(__CVLIB ${OpenCV_LIB_COMPONENTS}) - # We only need the "core",... part here: "opencv_core" -> "core" - STRING(REGEX REPLACE "opencv_(.*)" "\\1" __MODNAME ${__CVLIB}) - INCLUDE_DIRECTORIES("${OpenCV_SOURCE_PATH}/modules/${__MODNAME}/include") - LIST(APPEND OpenCV_INCLUDE_DIRS "${OpenCV_SOURCE_PATH}/modules/${__MODNAME}/include") - endforeach() + foreach(__cvlib ${OpenCV_REQUIRED_MODULES}) + # We only need the "core",... part here: "opencv_core" -> "core" + string(REGEX REPLACE "opencv_(.*)" "\\1" __MODNAME ${__cvlib}) + include_directories("${OpenCV_SOURCE_PATH}/modules/${__MODNAME}/include") + list(APPEND OpenCV_INCLUDE_DIRS "${OpenCV_SOURCE_PATH}/modules/${__MODNAME}/include") + endforeach() endif() -# For OpenCV built as static libs, we need the user to link against -# many more dependencies: -IF (NOT OpenCV_SHARED) - # Under static libs, the user of OpenCV needs access to the 3rdparty libs as well: - LINK_DIRECTORIES(@CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE@) - - set(OpenCV_LIBS @OPENCV_LINKER_LIBS@ @IPP_LIBS@ @HIGHGUI_LIBRARIES@ ${OpenCV_LIBS}) - set(OpenCV_EXTRA_COMPONENTS @JPEG_LIBRARIES@ @PNG_LIBRARIES@ @TIFF_LIBRARIES@ @JASPER_LIBRARIES@ @ZLIB_LIBRARY@) - - if (WIN32 AND ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 2.4) - # Modern CMake: - foreach(__EXTRA_LIB ${OpenCV_EXTRA_COMPONENTS}) - set(OpenCV_LIBS ${OpenCV_LIBS} - debug ${__EXTRA_LIB}@OPENCV_DEBUG_POSTFIX@ - optimized ${__EXTRA_LIB}) - endforeach() - else() - # Old CMake: - set(OpenCV_LIBS ${OpenCV_LIBS} ${OpenCV_EXTRA_COMPONENTS}) - endif() - - if (APPLE) - set(OpenCV_LIBS ${OpenCV_LIBS} "-lbz2" "-framework Cocoa" "-framework QuartzCore" "-framework QTKit") - endif() -ENDIF() - -# ====================================================== +# ============================================================== # Android camera helper macro -# ====================================================== -IF (OpenCV_HAVE_ANDROID_CAMERA) - macro( COPY_NATIVE_CAMERA_LIBS target ) +# ============================================================== +if(OpenCV_HAVE_ANDROID_CAMERA) + macro(COPY_NATIVE_CAMERA_LIBS target) get_target_property(target_location ${target} LOCATION) get_filename_component(target_location "${target_location}" PATH) file(GLOB camera_wrappers "${OpenCV_LIB_DIR}/libnative_camera_r*.so") foreach(wrapper ${camera_wrappers}) - ADD_CUSTOM_COMMAND( + add_custom_command( TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${target_location}" ) endforeach() endmacro() -ENDIF() +endif() -# ====================================================== -# Version variables: -# ====================================================== -SET(OpenCV_VERSION @OPENCV_VERSION@) -SET(OpenCV_VERSION_MAJOR @OPENCV_VERSION_MAJOR@) -SET(OpenCV_VERSION_MINOR @OPENCV_VERSION_MINOR@) -SET(OpenCV_VERSION_PATCH @OPENCV_VERSION_PATCH@) +# ============================================================== +# Compatibility stuff +# ============================================================== +set(OpenCV_LIBRARIES ${OpenCV_LIBS}) diff --git a/cmake/templates/opencv.pc.cmake.in b/cmake/templates/opencv.pc.cmake.in deleted file mode 100755 index c068400200..0000000000 --- a/cmake/templates/opencv.pc.cmake.in +++ /dev/null @@ -1,13 +0,0 @@ -# Package Information for pkg-config - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir_old=@includedir@/opencv -includedir_new=@includedir@ - -Name: OpenCV -Description: Open Source Computer Vision Library -Version: @VERSION@ -Libs: -L${libdir} -lopencv_core@OPENCV_DLLVERSION@ -lopencv_imgproc@OPENCV_DLLVERSION@ -lopencv_highgui@OPENCV_DLLVERSION@ -lopencv_ml@OPENCV_DLLVERSION@ -lopencv_video@OPENCV_DLLVERSION@ -lopencv_features2d@OPENCV_DLLVERSION@ -lopencv_calib3d@OPENCV_DLLVERSION@ -lopencv_objdetect@OPENCV_DLLVERSION@ -lopencv_contrib@OPENCV_DLLVERSION@ -lopencv_legacy@OPENCV_DLLVERSION@ -lopencv_flann@OPENCV_DLLVERSION@ -Cflags: -I${includedir_old} -I${includedir_new} diff --git a/cmake/templates/opencv_modules.hpp.in b/cmake/templates/opencv_modules.hpp.in new file mode 100644 index 0000000000..035f3e9a8d --- /dev/null +++ b/cmake/templates/opencv_modules.hpp.in @@ -0,0 +1,9 @@ +/* + * ** File generated automatically, do not modify ** + * + * This file defines the list of modules available in current build configuration + * + * +*/ + +@OPENCV_MODULE_DEFINITIONS_CONFIGMAKE@ \ No newline at end of file diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 7620a4832e..4a6ed6d11e 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,10 +1,5 @@ -file(GLOB ocvmodules RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*") -if(ocvmodules) - list(SORT ocvmodules) +if(NOT OPENCV_MODULES_PATH) + set(OPENCV_MODULES_PATH "${CMAKE_CURRENT_SOURCE_DIR}") endif() -foreach(mod ${ocvmodules}) - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${mod}/CMakeLists.txt") - add_subdirectory("${mod}") - endif() -endforeach() +ocv_glob_modules(${OPENCV_MODULES_PATH}) diff --git a/modules/androidcamera/CMakeLists.txt b/modules/androidcamera/CMakeLists.txt index a910a07547..8bc2bf6d4c 100644 --- a/modules/androidcamera/CMakeLists.txt +++ b/modules/androidcamera/CMakeLists.txt @@ -1,11 +1,30 @@ -IF(NOT ANDROID OR NOT WITH_ANDROID_CAMERA) - return() +IF(NOT ANDROID OR ANDROID_NATIVE_API_LEVEL LESS 8) + ocv_module_disable(androidcamera) ENDIF() +set(the_description "Auxiliary module for Android native camera support") +set(OPENCV_MODULE_TYPE STATIC) + +ocv_define_module(androidcamera INTERNAL log dl) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper") -set(OPENCV_ANDROIDCAMERA_MODULE_TYPE STATIC) -define_opencv_moduleEx(androidcamera INTERNAL log dl) +# Android source tree for native camera +SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH + "Path to Android source tree. Set this variable to path to your Android sources to compile libnative_camera_rx.x.x.so for your Android") +SET(BUILD_ANDROID_CAMERA_WRAPPER OFF) +if(ANDROID_SOURCE_TREE) + FILE(STRINGS "${ANDROID_SOURCE_TREE}/development/sdk/platform_source.properties" ANDROID_VERSION REGEX "Platform\\.Version=[0-9]+\\.[0-9]+(\\.[0-9]+)?" ) + string(REGEX REPLACE "Platform\\.Version=([0-9]+\\.[0-9]+(\\.[0-9]+)?)" "\\1" ANDROID_VERSION "${ANDROID_VERSION}") + if(ANDROID_VERSION MATCHES "^[0-9]+\\.[0-9]+$") + SET(ANDROID_VERSION "${ANDROID_VERSION}.0") + endif() + if(NOT "${ANDROID_VERSION}" STREQUAL "") + SET(BUILD_ANDROID_CAMERA_WRAPPER ON) + endif() +endif() +MARK_AS_ADVANCED(ANDROID_SOURCE_TREE) + +# process wrapper libs if (BUILD_ANDROID_CAMERA_WRAPPER) add_subdirectory(camera_wrapper) else() @@ -13,13 +32,12 @@ else() foreach(wrapper ${camera_wrappers}) ADD_CUSTOM_COMMAND( - TARGET ${the_target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${LIBRARY_OUTPUT_PATH}" - ) + TARGET ${the_module} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${wrapper}" "${LIBRARY_OUTPUT_PATH}" + ) get_filename_component(wrapper_name "${wrapper}" NAME) install(FILES "${LIBRARY_OUTPUT_PATH}/${wrapper_name}" - DESTINATION ${OPENCV_LIB_INSTALL_PATH} - COMPONENT main) + DESTINATION ${OPENCV_LIB_INSTALL_PATH} + COMPONENT main) endforeach() endif() diff --git a/modules/calib3d/CMakeLists.txt b/modules/calib3d/CMakeLists.txt index a1a7ca72b9..4fb7a1b618 100644 --- a/modules/calib3d/CMakeLists.txt +++ b/modules/calib3d/CMakeLists.txt @@ -1 +1,2 @@ -define_opencv_module(calib3d opencv_core opencv_imgproc opencv_features2d opencv_flann) +set(the_description "Camera Calibration and 3D Reconstruction") +ocv_define_module(calib3d opencv_imgproc opencv_features2d) diff --git a/modules/contrib/CMakeLists.txt b/modules/contrib/CMakeLists.txt index 2255f8ef82..2c338b8f4f 100644 --- a/modules/contrib/CMakeLists.txt +++ b/modules/contrib/CMakeLists.txt @@ -1 +1 @@ -define_opencv_module(contrib opencv_core opencv_imgproc opencv_calib3d opencv_features2d opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_flann) +ocv_define_module(contrib opencv_imgproc opencv_calib3d opencv_features2d opencv_highgui opencv_ml opencv_video opencv_objdetect) diff --git a/modules/contrib/src/featuretracker.cpp b/modules/contrib/src/featuretracker.cpp index 9feff6d230..84f8460e51 100644 --- a/modules/contrib/src/featuretracker.cpp +++ b/modules/contrib/src/featuretracker.cpp @@ -42,7 +42,6 @@ #include "precomp.hpp" #include #include -#include #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/contrib/hybridtracker.hpp" diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 99d477c62d..bb7fbcc6b1 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -1,7 +1,43 @@ -if(ZLIB_FOUND) - include_directories(${ZLIB_INCLUDE_DIR}) +set(the_description "The Core Functionality") +ocv_add_module(core ${ZLIB_LIBRARY}) + +if(HAVE_CUDA) + file(GLOB lib_cuda "src/cuda/*.cu") + source_group("Cuda" FILES "${lib_cuda}") + + include_directories(${CUDA_INCLUDE_DIRS} "${OpenCV_SOURCE_DIR}/modules/gpu/src" "${OpenCV_SOURCE_DIR}/modules/gpu/src/cuda") + + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_10,code=sm_10 + -gencode arch=compute_11,code=sm_11 + -gencode arch=compute_12,code=sm_12 + -gencode arch=compute_13,code=sm_13 + -gencode arch=compute_20,code=sm_20 + -gencode arch=compute_20,code=sm_21) + + OCV_CUDA_COMPILE(cuda_objs ${lib_cuda}) + + unset(CUDA_npp_LIBRARY CACHE) + find_cuda_helper_libs(npp) + set(cuda_link_libs ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) else() - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/zlib") + set(lib_cuda "") + set(cuda_objs "") + set(cuda_link_libs "") +endif() + +ocv_glob_module_sources(SOURCES ${lib_cuda} ${cuda_objs}) + +if(NOT ZLIB_FOUND) + set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/zlib") endif() +ocv_module_include_directories(${ZLIB_INCLUDE_DIR}) + +ocv_create_module(${cuda_link_libs}) +ocv_add_precompiled_headers(${the_module}) + +ocv_add_accuracy_tests() +ocv_add_perf_tests() + + + -define_opencv_module(core ${ZLIB_LIBRARY}) diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index 897d2dcc67..4b0efa0d34 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -49,7 +49,7 @@ #define CV_MAJOR_VERSION 2 #define CV_MINOR_VERSION 3 -#define CV_SUBMINOR_VERSION 2 +#define CV_SUBMINOR_VERSION 3 #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) diff --git a/modules/features2d/CMakeLists.txt b/modules/features2d/CMakeLists.txt index 8065e65685..99a46f9f8e 100644 --- a/modules/features2d/CMakeLists.txt +++ b/modules/features2d/CMakeLists.txt @@ -1,2 +1,3 @@ -define_opencv_module(features2d opencv_core opencv_imgproc opencv_highgui opencv_flann) +set(the_description "2D Features Framework") +ocv_define_module(features2d opencv_imgproc opencv_highgui opencv_flann) diff --git a/modules/flann/CMakeLists.txt b/modules/flann/CMakeLists.txt index 79fbf0d2af..645e8ce857 100644 --- a/modules/flann/CMakeLists.txt +++ b/modules/flann/CMakeLists.txt @@ -1,2 +1,3 @@ -define_opencv_module(flann opencv_core) +set(the_description "Clustering and Search in Multi-Dimensional Spaces") +ocv_define_module(flann opencv_core) diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 3f0b98ecd6..88d59c46ed 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -1,181 +1,101 @@ if(ANDROID OR IOS) - return() + ocv_module_disable(gpu) endif() -option(OCVMODULE_GPU "Include gpu module into the OpenCV build" ON) -if(NOT OCVMODULE_GPU) - return() -endif() - -set(name "gpu") - -set(the_target "opencv_${name}") -project(${the_target}) +set(the_description "GPU-accelerated Computer Vision") +ocv_add_module(gpu opencv_imgproc opencv_calib3d opencv_objdetect) -set(DEPS "opencv_core" "opencv_imgproc" "opencv_calib3d" "opencv_objdetect") -set(DEPS_HEADER ${DEPS} "opencv_features2d" "opencv_flann") -set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} opencv_gpu) +ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/cuda") -opencv_module_includes(${DEPS_HEADER}) -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/cuda") +file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") +file(GLOB lib_int_hdrs "src/*.hpp" "src/*.h") +file(GLOB lib_cuda_hdrs "src/cuda/*.hpp" "src/cuda/*.h") +file(GLOB lib_device_hdrs "src/opencv2/gpu/device/*.hpp" "src/opencv2/gpu/device/*.h") +file(GLOB lib_device_hdrs_detail "src/opencv2/gpu/device/detail/*.hpp" "src/opencv2/gpu/device/detail/*.h") +file(GLOB lib_srcs "src/*.cpp") +file(GLOB lib_cuda "src/cuda/*.cu*") -file(GLOB lib_srcs "src/*.cpp") -file(GLOB lib_int_hdrs "src/*.h*") -file(GLOB lib_cuda "src/cuda/*.cu*") -file(GLOB lib_cuda_hdrs "src/cuda/*.h*") +source_group("Include" FILES ${lib_hdrs}) source_group("Src\\Host" FILES ${lib_srcs} ${lib_int_hdrs}) source_group("Src\\Cuda" FILES ${lib_cuda} ${lib_cuda_hdrs}) - -file(GLOB lib_hdrs "include/opencv2/${name}/*.h*") -source_group("Include" FILES ${lib_hdrs}) - -#file(GLOB lib_device_hdrs "include/opencv2/${name}/device/*.h*") -file(GLOB lib_device_hdrs "src/opencv2/gpu/device/*.h*") -file(GLOB lib_device_hdrs_detail "src/opencv2/gpu/device/detail/*.h*") source_group("Device" FILES ${lib_device_hdrs}) source_group("Device\\Detail" FILES ${lib_device_hdrs_detail}) if (HAVE_CUDA) - file(GLOB_RECURSE ncv_srcs "src/nvidia/*.cpp") - file(GLOB_RECURSE ncv_cuda "src/nvidia/*.cu") - file(GLOB_RECURSE ncv_hdrs "src/nvidia/*.hpp" "src/nvidia/*.h") - - source_group("Src\\NVidia" FILES ${ncv_srcs} ${ncv_hdrs} ${ncv_cuda}) - include_directories("src/nvidia/core" "src/nvidia/NPP_staging") -endif() + file(GLOB_RECURSE ncv_srcs "src/nvidia/*.cpp") + file(GLOB_RECURSE ncv_cuda "src/nvidia/*.cu") + file(GLOB_RECURSE ncv_hdrs "src/nvidia/*.hpp" "src/nvidia/*.h") + set(ncv_files ${ncv_srcs} ${ncv_hdrs} ${ncv_cuda}) -if (HAVE_CUDA) - include_directories(${CUDA_INCLUDE_DIRS}) + source_group("Src\\NVidia" FILES ${ncv_files}) + include_directories("src/nvidia/core" "src/nvidia/NPP_staging" ${CUDA_INCLUDE_DIRS}) - if (UNIX OR APPLE) - set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;-fPIC;") - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-fPIC") - endif() - - #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep") - #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/EHsc-;") + #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep") + #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/EHsc-;") - if (APPLE) - set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;-fno-finite-math-only;") - endif() - - string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - - if(MSVC) - #string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - #string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - #string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4211 /wd4201 /wd4100 /wd4505 /wd4408 /wd4251") + foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) + string(REPLACE "/W4" "/W3" ${var} "${${var}}") + endforeach() - string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/EHsc-" "/EHs" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/EHsc-" "/EHs" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - endif() + if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4211 /wd4201 /wd4100 /wd4505 /wd4408 /wd4251") - if (BUILD_SHARED_LIBS) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;-DCVAPI_EXPORTS") - endif() + foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) + string(REPLACE "/EHsc-" "/EHs" ${var} "${${var}}") + endforeach() - if(MSVC) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/wd4251") - endif() - - - - # we remove -ggdb3 flag as it leads to preprocessor errors when compiling CUDA files (CUDA 4.1) - set(tmp ${CMAKE_CXX_FLAGS_DEBUG}) - string(REPLACE "-ggdb3" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) - CUDA_COMPILE(cuda_objs ${lib_cuda} ${ncv_cuda}) - set(CMAKE_CXX_DEBUG_FLAGS ${tmp}) - - #CUDA_BUILD_CLEAN_TARGET() -endif() - -add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${lib_cuda} ${lib_cuda_hdrs} ${lib_device_hdrs} ${lib_device_hdrs_detail} ${ncv_srcs} ${ncv_hdrs} ${ncv_cuda} ${cuda_objs}) -target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${DEPS} ) -opencv_module_register(${the_target}) - -if (HAVE_CUDA) - target_link_libraries(${the_target} ${CUDA_LIBRARIES}) - - unset(CUDA_npp_LIBRARY CACHE) - find_cuda_helper_libs(npp) - target_link_libraries(${the_target} ${CUDA_npp_LIBRARY}) - - if(HAVE_CUFFT) - CUDA_ADD_CUFFT_TO_TARGET(${the_target}) - endif() - - if(HAVE_CUBLAS) - CUDA_ADD_CUBLAS_TO_TARGET(${the_target}) - endif() + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler /wd4251) + endif() + + OCV_CUDA_COMPILE(cuda_objs ${lib_cuda} ${ncv_cuda}) + #CUDA_BUILD_CLEAN_TARGET() + + unset(CUDA_npp_LIBRARY CACHE) + find_cuda_helper_libs(npp) + set(cuda_link_libs ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) +else() + set(lib_cuda "") + set(cuda_objs "") + set(cuda_link_libs "") + set(ncv_files "") endif() -opencv_module_setup(${name}) - -install(FILES src/nvidia/NPP_staging/NPP_staging.hpp src/nvidia/core/NCV.hpp +ocv_set_module_sources( + HEADERS ${lib_hdrs} + SOURCES ${lib_int_hdrs} ${lib_cuda_hdrs} ${lib_device_hdrs} ${lib_device_hdrs_detail} ${lib_srcs} ${lib_cuda} ${ncv_files} ${cuda_objs} + ) + +ocv_create_module(${cuda_link_libs}) + +if(HAVE_CUDA) + if(HAVE_CUFFT) + CUDA_ADD_CUFFT_TO_TARGET(${the_module}) + endif() + + if(HAVE_CUBLAS) + CUDA_ADD_CUBLAS_TO_TARGET(${the_module}) + endif() + + install(FILES src/nvidia/NPP_staging/NPP_staging.hpp src/nvidia/core/NCV.hpp DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} COMPONENT main) +endif() -#install(FILES ${lib_device_hdrs} -# DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name}/device -# COMPONENT main) - +ocv_add_precompiled_headers(${the_module}) ################################################################################################################ ################################ GPU Module Tests ##################################################### ################################################################################################################ - -# Test files processing is in the separated directory to avoid 'Src' source -# filter creation in Visual Studio -if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test) - set(the_test_target "opencv_test_${name}") - set(test_deps opencv_${name} opencv_ts opencv_highgui opencv_calib3d ${DEPS}) - - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/test") - opencv_module_includes(${test_deps}) - - file(GLOB test_srcs "test/*.cpp") - file(GLOB test_hdrs "test/*.h*") - - source_group("Src" FILES ${test_hdrs} ${test_srcs}) - if(HAVE_CUDA) - include_directories(${CUDA_INCLUDE_DIRS} ${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia ${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia/core ${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia/NPP_staging) - - file(GLOB nvidia "test/nvidia/*.cpp" "test/nvidia/*.h*") - source_group("Src\\NVidia" FILES ${nvidia}) - endif() - - add_executable(${the_test_target} ${test_srcs} ${test_hdrs} ${nvidia}) - - # Additional target properties - set_target_properties(${the_test_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" - ) - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_test_target} PROPERTIES FOLDER "tests") - endif() - - # Add the required libraries for linking: - target_link_libraries(${the_test_target} ${OPENCV_LINKER_LIBS} ${test_deps}) - - enable_testing() - get_target_property(LOC ${the_test_target} LOCATION) - add_test(${the_test_target} "${LOC}") - - #if(WIN32) - # install(TARGETS ${the_test_target} RUNTIME DESTINATION bin COMPONENT main) - #endif() - - add_opencv_precompiled_headers(${the_test_target}) +file(GLOB test_srcs "test/*.cpp") +file(GLOB test_hdrs "test/*.hpp" "test/*.h") +if(HAVE_CUDA) + file(GLOB nvidia "test/nvidia/*.cpp" "test/nvidia/*.hpp" "test/nvidia/*.h") + set(nvidia FILES "Src\\\\\\\\NVidia" ${nvidia}) # 8 ugly backslashes :'( +else() + set(nvidia "") endif() - -define_opencv_perf_test(${name}) +ocv_add_accuracy_tests(FILES "Include" ${test_hdrs} + FILES "Src" ${test_srcs} + ${nvidia}) +ocv_add_perf_tests() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index a49952377a..1452806f20 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -1,21 +1,13 @@ +set(the_description "High-level GUI and Media I/O") +ocv_add_module(highgui opencv_imgproc OPTIONAL opencv_androidcamera) + # ---------------------------------------------------------------------------- # CMake file for highgui. See root CMakeLists.txt # Some parts taken from version of Hartmut Seichter, HIT Lab NZ. # Jose Luis Blanco, 2008 # ---------------------------------------------------------------------------- -option(OCVMODULE_HIGHGUI "Include highgui module into the OpenCV build" ON) -if(NOT OCVMODULE_HIGHGUI) - return() -endif() - -set(the_target "opencv_highgui") -project(${the_target}) - -#so that the headers get installed. -file(GLOB lib_hdrs "include/opencv2/highgui/*.h*") - -set(GRFMT_LIBS) +set(GRFMT_LIBS "") if(WITH_PNG OR WITH_TIFF OR WITH_OPENEXR) if(ZLIB_FOUND) @@ -85,6 +77,7 @@ set(grfmt_srcs src/bitstrm.cpp ${grfmt_srcs}) source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs}) +set(highgui_hdrs src/precomp.hpp src/utils.hpp) set(highgui_srcs src/cap.cpp src/cap_images.cpp @@ -94,15 +87,7 @@ set(highgui_srcs src/utils.cpp src/window.cpp ) - -set(highgui_hdrs src/precomp.hpp src/utils.hpp) - -#YV -set(lib_hdr_names highgui_c.h highgui.hpp) -set(highgui_ext_hdrs) -foreach(h ${lib_hdr_names}) - list(APPEND highgui_ext_hdrs "${CMAKE_CURRENT_SOURCE_DIR}/include/opencv2/highgui/${h}") -endforeach() +file(GLOB highgui_ext_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") #YV if (HAVE_QT) @@ -225,11 +210,9 @@ if(APPLE) endif() endif(APPLE) -if(WITH_ANDROID_CAMERA) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../androidcamera/include") +if(WITH_ANDROID_CAMERA AND OPENCV_MODULE_ANDROIDCAMERA) set(highgui_srcs ${highgui_srcs} src/cap_android.cpp) - add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA) - set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} opencv_androidcamera) + add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line endif() if(HAVE_XIMEA AND XIMEA_FOUND) @@ -265,32 +248,16 @@ if(OPENCV_BUILD_3RDPARTY_LIBS AND WIN32) link_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/lib") endif() -if(COMMAND get_module_external_sources) - set( lib_srcs "${highgui_srcs}" ) - set( lib_int_hdrs "${highgui_hdrs}" ) - get_module_external_sources(highgui) - set( highgui_srcs "${lib_srcs}" ) - set( highgui_hdrs "${lib_int_hdrs}" ) -endif() - source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs}) source_group("Include" FILES ${highgui_ext_hdrs}) +ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs} ${grfmt_srcs} ${grfmt_hdrs}) -#message(STATUS "GRFMT: ${GRFMT_LIBS}") -#message(STATUS "OPENCV_LIBS: ${OPENCV_LINKER_LIBS}") -#message(STATUS "HIGHGUI_LIBS: ${HIGHGUI_LIBRARIES}") - -# ---------------------------------------------------------------------------------- -# Define the library target: -# ---------------------------------------------------------------------------------- -opencv_module_includes(opencv_core opencv_imgproc) +ocv_module_include_directories() if(WIN32) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/include") endif() -add_library(${the_target} ${highgui_srcs} ${grfmt_srcs} ${highgui_hdrs} ${grfmt_hdrs} ${highgui_ext_hdrs}) -target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core opencv_imgproc ${GRFMT_LIBS} ${HIGHGUI_LIBRARIES}) -opencv_module_register(${the_target}) +ocv_create_module(${GRFMT_LIBS} ${HIGHGUI_LIBRARIES}) if(BUILD_SHARED_LIBS) add_definitions(-DHIGHGUI_EXPORTS) @@ -300,6 +267,7 @@ if(MSVC) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") endif() -opencv_module_setup(highgui) -define_opencv_test(highgui) -define_opencv_perf_test(highgui) +ocv_add_precompiled_headers(${the_module}) + +ocv_add_accuracy_tests() +ocv_add_perf_tests() diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp index 971793d930..233e6f6480 100644 --- a/modules/highgui/src/cap_libv4l.cpp +++ b/modules/highgui/src/cap_libv4l.cpp @@ -221,7 +221,6 @@ make & enjoy! // //M*/ -#include "highgui.h" #include "precomp.hpp" #if !defined WIN32 && defined HAVE_LIBV4L @@ -393,6 +392,7 @@ static void icvInitCapture_V4L() { static int try_init_v4l(CvCaptureCAM_V4L* capture, char *deviceName) + { // if detect = -1 then unable to open device diff --git a/modules/imgproc/CMakeLists.txt b/modules/imgproc/CMakeLists.txt index 133348b411..652d6e1ebe 100644 --- a/modules/imgproc/CMakeLists.txt +++ b/modules/imgproc/CMakeLists.txt @@ -1 +1,2 @@ -define_opencv_module(imgproc opencv_core) +set(the_description "Image Processing") +ocv_define_module(imgproc opencv_core) diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 3d66b60fac..05a355048b 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -1,21 +1,17 @@ -if(NOT BUILD_JAVA_SUPPORT OR NOT PYTHON_EXECUTABLE) - return() -endif() - # ---------------------------------------------------------------------------- # CMake file for java support # ---------------------------------------------------------------------------- -project(opencv_java) -set(target opencv_java) -include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp") +if(NOT BUILD_JAVA_SUPPORT OR NOT PYTHON_EXECUTABLE) + ocv_module_disable(java) +endif() +set(the_description "The java bindings") +ocv_add_module(java BINDINGS opencv_objdetect opencv_features2d opencv_imgproc opencv_video opencv_highgui opencv_ml opencv_core opencv_calib3d) -SET(OPENCV_JAVA_MODULES objdetect features2d imgproc video highgui ml core calib3d) -SET(OPENCV_EXTRA_JAVA_MODULES contrib legacy flann) -IF(WITH_ANDROID_CAMERA AND NOT BUILD_SHARED_LIBS) - LIST(APPEND OPENCV_EXTRA_JAVA_MODULES androidcamera) -ENDIF() +string(REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS}") +set(target ${the_module}) +include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp") SET(GEN_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/gen_java.py") SET(HDR_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py") @@ -81,25 +77,21 @@ foreach(module ${OPENCV_JAVA_MODULES}) endforeach() FILE(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp") -FILE(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.h*") +FILE(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.h??") FILE(GLOB handwrittren_java_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/java/*.java") SET (generated_cpp_sources) SET (generated_java_sources) SET (documented_java_files) SET (undocumented_java_files) -SET (dependent_libs) -SET (dependent_extra_libs) foreach(module ${OPENCV_JAVA_MODULES}) LIST(APPEND generated_cpp_sources "${CMAKE_CURRENT_BINARY_DIR}/${module}.cpp") LIST(APPEND generated_java_sources ${${module}_generated_java_sources}) - LIST(APPEND dependent_libs opencv_${module}) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include") endforeach() -# extra includes and dependencies -foreach(module ${OPENCV_EXTRA_JAVA_MODULES}) - LIST(APPEND dependent_extra_libs opencv_${module}) +# all needed includes +foreach(module ${OPENCV_MODULE_${the_module}_DEPS}) + string(REPLACE "opencv_" "" module "${module}") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../${module}/include") endforeach() @@ -154,8 +146,8 @@ ADD_CUSTOM_TARGET(${api_target} DEPENDS ${java_files}) # add opencv_java library add_library(${target} SHARED ${handwrittren_h_sources} ${handwrittren_cpp_sources} ${generated_cpp_sources}) -target_link_libraries(${target} ${dependent_libs} ${dependent_extra_libs} ${OPENCV_LINKER_LIBS}) -add_dependencies(${target} ${dependent_extra_libs} ${dependent_libs} ${api_target}) +target_link_libraries(${target} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) +add_dependencies(${target} ${api_target}) # Additional target properties set_target_properties(${target} PROPERTIES diff --git a/modules/legacy/CMakeLists.txt b/modules/legacy/CMakeLists.txt index 9e6812b50f..8c9af52ddc 100644 --- a/modules/legacy/CMakeLists.txt +++ b/modules/legacy/CMakeLists.txt @@ -1 +1 @@ -define_opencv_module(legacy opencv_core opencv_imgproc opencv_calib3d opencv_features2d opencv_highgui opencv_video opencv_flann) +ocv_define_module(legacy opencv_calib3d opencv_highgui opencv_video) diff --git a/modules/ml/CMakeLists.txt b/modules/ml/CMakeLists.txt index b44de8b6f8..27b4990030 100644 --- a/modules/ml/CMakeLists.txt +++ b/modules/ml/CMakeLists.txt @@ -1 +1,2 @@ -define_opencv_module(ml opencv_core) +set(the_description "Machine Learning") +ocv_define_module(ml opencv_core) diff --git a/modules/objdetect/CMakeLists.txt b/modules/objdetect/CMakeLists.txt index f41067f82a..fa2f4eb48f 100644 --- a/modules/objdetect/CMakeLists.txt +++ b/modules/objdetect/CMakeLists.txt @@ -1 +1,2 @@ -define_opencv_module(objdetect opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_calib3d opencv_flann) +set(the_description "Object Detection") +ocv_define_module(objdetect opencv_highgui opencv_calib3d) diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index 589c764bda..730f52a2cf 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -1,14 +1,16 @@ +# ---------------------------------------------------------------------------- +# CMake file for python support +# ---------------------------------------------------------------------------- + if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") - return() + ocv_module_disable(python) endif() if(NOT PYTHONLIBS_FOUND OR NOT BUILD_NEW_PYTHON_SUPPORT OR NOT PYTHON_USE_NUMPY) - return() + ocv_module_disable(python) endif() -# ---------------------------------------------------------------------------- -# CMake file for python support -# ---------------------------------------------------------------------------- -project(opencv_python) +set(the_description "The python bindings") +ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib) include_directories(${PYTHON_INCLUDE_PATH}) include_directories( diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index 20866ee5cd..88fd865f54 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -1,11 +1,3 @@ -if(IOS) - return() -endif() - -set(DEPS opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_flann opencv_objdetect) -if(NOT ANDROID) - set(DEPS ${DEPS} opencv_gpu) -endif() - -define_opencv_module(stitching ${DEPS}) +set(the_description "Images stitching") +ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_gpu) diff --git a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp index 7e75916d53..9ae5760bde 100644 --- a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp @@ -46,7 +46,8 @@ #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" -#ifndef ANDROID +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_GPU #include "opencv2/gpu/gpu.hpp" #endif @@ -102,7 +103,7 @@ private: }; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder { public: diff --git a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp index c52d1cdb4c..a6b897250b 100644 --- a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp @@ -44,6 +44,7 @@ #define __OPENCV_STITCHING_SEAM_FINDERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/opencv_modules.hpp" namespace cv { namespace detail { @@ -114,7 +115,7 @@ private: }; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder { public: diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index abb99fb67e..7061411402 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -45,7 +45,8 @@ #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" -#ifndef ANDROID +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_GPU # include "opencv2/gpu/gpu.hpp" #endif @@ -184,7 +185,7 @@ protected: }; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU class CV_EXPORTS PlaneWarperGpu : public PlaneWarper { public: diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp index b612de6e07..a321c3987f 100644 --- a/modules/stitching/include/opencv2/stitching/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/warpers.hpp @@ -76,7 +76,7 @@ public: }; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU class PlaneWarperGpu: public WarperCreator { public: diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index ec6959dd94..1ab45c84a5 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -189,7 +189,7 @@ Rect FeatherBlender::createWeightMaps(const vector &masks, const vector &pyr) void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) { -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU pyr.resize(num_levels + 1); vector gpu_pyr(num_levels + 1); @@ -419,7 +419,7 @@ void restoreImageFromLaplacePyr(vector &pyr) void restoreImageFromLaplacePyrGpu(vector &pyr) { -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (pyr.empty()) return; diff --git a/modules/stitching/src/exposure_compensate.cpp b/modules/stitching/src/exposure_compensate.cpp index 2a2609b458..8345423184 100644 --- a/modules/stitching/src/exposure_compensate.cpp +++ b/modules/stitching/src/exposure_compensate.cpp @@ -43,9 +43,6 @@ #include "precomp.hpp" using namespace std; -#ifndef ANDROID -using namespace cv::gpu; -#endif namespace cv { namespace detail { diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index cc1da497ee..0859d0e4ac 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -46,7 +46,7 @@ using namespace std; using namespace cv; using namespace cv::detail; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU using namespace cv::gpu; #endif @@ -127,7 +127,7 @@ private: float match_conf_; }; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU class GpuMatcher : public FeaturesMatcher { public: @@ -202,7 +202,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat LOG("1->2 & 2->1 matches: " << matches_info.matches.size() << endl); } -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info) { matches_info.matches.clear(); @@ -398,7 +398,7 @@ void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features) } } -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, int num_octaves_descr, int num_layers_descr) { @@ -499,7 +499,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2) { -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (try_use_gpu && getCudaEnabledDeviceCount() > 0) impl_ = new GpuMatcher(match_conf); else diff --git a/modules/stitching/src/precomp.hpp b/modules/stitching/src/precomp.hpp index d84afe4d23..a6209206cd 100644 --- a/modules/stitching/src/precomp.hpp +++ b/modules/stitching/src/precomp.hpp @@ -46,6 +46,7 @@ #ifdef HAVE_CVCONFIG_H #include "cvconfig.h" #endif +#include "opencv2/opencv_modules.hpp" #include #include @@ -69,11 +70,11 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU # include "opencv2/gpu/gpu.hpp" #endif -#include "modules/imgproc/src/gcgraph.hpp" +#include "../../imgproc/src/gcgraph.hpp" #ifdef HAVE_TEGRA_OPTIMIZATION # include "opencv2/stitching/stitching_tegra.hpp" diff --git a/modules/stitching/src/seam_finders.cpp b/modules/stitching/src/seam_finders.cpp index d2d50fd620..9350307025 100644 --- a/modules/stitching/src/seam_finders.cpp +++ b/modules/stitching/src/seam_finders.cpp @@ -417,7 +417,7 @@ void GraphCutSeamFinder::find(const vector &src, const vector &corne } -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, vector &masks) { diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index 9cc7b53a74..a03d4ac8f9 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -58,7 +58,7 @@ Stitcher Stitcher::createDefault(bool try_use_gpu) stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(try_use_gpu)); stitcher.setBundleAdjuster(new detail::BundleAdjusterRay()); -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (try_use_gpu && gpu::getCudaEnabledDeviceCount() > 0) { stitcher.setFeaturesFinder(new detail::SurfFeaturesFinderGpu()); diff --git a/modules/stitching/src/warpers.cpp b/modules/stitching/src/warpers.cpp index 3aa308cd6e..235656e4f7 100644 --- a/modules/stitching/src/warpers.cpp +++ b/modules/stitching/src/warpers.cpp @@ -212,7 +212,7 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b } -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) { return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); diff --git a/modules/traincascade/CMakeLists.txt b/modules/traincascade/CMakeLists.txt deleted file mode 100644 index 4cfca3e66d..0000000000 --- a/modules/traincascade/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -if(IOS) - return() -endif() - -project(traincascade) - -include_directories( - "${CMAKE_CURRENT_SOURCE_DIR}" - "${OpenCV_SOURCE_DIR}/modules/core/include" - "${OpenCV_SOURCE_DIR}/modules/imgproc/include" - "${OpenCV_SOURCE_DIR}/modules/objdetect/include" - "${OpenCV_SOURCE_DIR}/modules/ml/include" - "${OpenCV_SOURCE_DIR}/modules/highgui/include" - "${OpenCV_SOURCE_DIR}/modules/video/include" - "${OpenCV_SOURCE_DIR}/modules/features2d/include" - "${OpenCV_SOURCE_DIR}/modules/flann/include" - "${OpenCV_SOURCE_DIR}/modules/calib3d/include" - "${OpenCV_SOURCE_DIR}/modules/legacy/include" - ) - -set(traincascade_libs opencv_core opencv_ml opencv_imgproc - opencv_objdetect opencv_highgui opencv_haartraining_engine) - -set(traincascade_files traincascade.cpp - cascadeclassifier.cpp cascadeclassifier.h - boost.cpp boost.h features.cpp traincascade_features.h - haarfeatures.cpp haarfeatures.h - lbpfeatures.cpp lbpfeatures.h - HOGfeatures.cpp HOGfeatures.h - imagestorage.cpp imagestorage.h) - -set(the_target opencv_traincascade) -add_executable(${the_target} ${traincascade_files}) - -add_dependencies(${the_target} ${traincascade_libs}) -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - INSTALL_NAME_DIR lib - OUTPUT_NAME "opencv_traincascade") - -if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "applications") -endif() - -target_link_libraries(${the_target} ${traincascade_libs}) - -if(NOT ANDROID) - install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main) -endif() diff --git a/modules/ts/CMakeLists.txt b/modules/ts/CMakeLists.txt index 3574f98f3b..d4f4c52c50 100644 --- a/modules/ts/CMakeLists.txt +++ b/modules/ts/CMakeLists.txt @@ -1,16 +1,24 @@ -if(BUILD_TESTS OR BUILD_PERF_TESTS) - if(BUILD_SHARED_LIBS AND NOT MINGW) - add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=1) - if (MSVC) - add_definitions( "/wd4251 /wd4275") - endif() - else() - add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=0) - endif() +if(IOS) + ocv_module_disable(ts) +endif() - if(MINGW) - set(OPENCV_TS_MODULE_TYPE STATIC) - endif() +if(MINGW) + set(OPENCV_MODULE_TYPE STATIC) +endif() + +set(the_description "The ts module") +ocv_add_module(ts opencv_core) +ocv_glob_module_sources() +ocv_module_include_directories() +ocv_create_module() - define_opencv_module(ts opencv_core) +if(BUILD_SHARED_LIBS AND NOT MINGW) + add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=1) + if (MSVC) + add_definitions( "/wd4251 /wd4275") + endif() +else() + add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=0) endif() + +ocv_add_precompiled_headers(${the_module}) diff --git a/modules/video/CMakeLists.txt b/modules/video/CMakeLists.txt index ef3d99cdca..7423803a2a 100644 --- a/modules/video/CMakeLists.txt +++ b/modules/video/CMakeLists.txt @@ -1 +1,2 @@ -define_opencv_module(video opencv_core opencv_imgproc) \ No newline at end of file +set(the_description "Video Analysis") +ocv_define_module(video opencv_imgproc) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 3bd7b32de7..b7ec3a3bbb 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -5,16 +5,8 @@ add_subdirectory(c) add_subdirectory(cpp) +add_subdirectory(gpu) -if(NOT ANDROID) - add_subdirectory(gpu) -endif() - -if(BUILD_ANDROID_EXAMPLES) - add_subdirectory(android) -endif() - -if(0) -add_subdirectory(swig_python) -add_subdirectory(octave) +if(ANDROID AND BUILD_ANDROID_EXAMPLES) + add_subdirectory(android) endif() diff --git a/samples/android/CMakeLists.txt b/samples/android/CMakeLists.txt index 28166b7d5e..48d653c512 100644 --- a/samples/android/CMakeLists.txt +++ b/samples/android/CMakeLists.txt @@ -2,46 +2,33 @@ # CMake file for Android samples. See root CMakeLists.txt # # ---------------------------------------------------------------------------- +SET(OPENCV_ANDROID_SAMPLES_REQUIRED_DEPS opencv_contrib opencv_legacy opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core) -if (BUILD_ANDROID_EXAMPLES) - project(android_samples) +ocv_check_dependencies(${OPENCV_ANDROID_SAMPLES_REQUIRED_DEPS} opencv_java) - include_directories( - "${CMAKE_SOURCE_DIR}/modules/core/include" - "${CMAKE_SOURCE_DIR}/modules/flann/include" - "${CMAKE_SOURCE_DIR}/modules/imgproc/include" - "${CMAKE_SOURCE_DIR}/modules/video/include" - "${CMAKE_SOURCE_DIR}/modules/highgui/include" - "${CMAKE_SOURCE_DIR}/modules/ml/include" - "${CMAKE_SOURCE_DIR}/modules/calib3d/include" - "${CMAKE_SOURCE_DIR}/modules/features2d/include" - "${CMAKE_SOURCE_DIR}/modules/objdetect/include" - "${CMAKE_SOURCE_DIR}/modules/legacy/include" - "${CMAKE_SOURCE_DIR}/modules/contrib/include" - ) +if(BUILD_ANDROID_EXAMPLES AND OCV_DEPENDENCIES_FOUND) + project(android_samples) - SET (sample_dependencies opencv_contrib opencv_legacy opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core) - if(NOT BUILD_SHARED_LIBS) - LIST(APPEND sample_dependencies opencv_androidcamera) - endif() + foreach(m ${OPENCV_ANDROID_SAMPLES_REQUIRED_DEPS}) + string(REPLACE "opencv_" "" m "${m}") + include_directories("${OpenCV_SOURCE_DIR}/modules/${m}/include") + endforeach() - file(GLOB android_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) - list(REMOVE_ITEM android_samples hello-android) - list(SORT android_samples) + file(GLOB android_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) + list(REMOVE_ITEM android_samples hello-android) + list(SORT android_samples) - foreach(sample ${android_samples}) - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${sample}/AndroidManifest.xml") - add_android_project("${sample}" "${CMAKE_CURRENT_SOURCE_DIR}/${sample}" INSTALL) - endif() - endforeach() - - #hello-android sample - ADD_EXECUTABLE(hello-android hello-android/main.cpp) - ADD_DEPENDENCIES(hello-android ${sample_dependencies}) - TARGET_LINK_LIBRARIES(hello-android ${OPENCV_LINKER_LIBS} ${sample_dependencies}) - set_target_properties(hello-android PROPERTIES OUTPUT_NAME hello-android RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") - if(INSTALL_ANDROID_EXAMPLES) - install(TARGETS hello-android DESTINATION bin COMPONENT main) + foreach(sample ${android_samples}) + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${sample}/AndroidManifest.xml") + add_android_project("${sample}" "${CMAKE_CURRENT_SOURCE_DIR}/${sample}" INSTALL) endif() + endforeach() + #hello-android sample + ADD_EXECUTABLE(hello-android hello-android/main.cpp) + TARGET_LINK_LIBRARIES(hello-android ${OPENCV_LINKER_LIBS} ${OPENCV_ANDROID_SAMPLES_REQUIRED_DEPS}) + set_target_properties(hello-android PROPERTIES OUTPUT_NAME hello-android RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") + if(INSTALL_ANDROID_EXAMPLES) + install(TARGETS hello-android DESTINATION bin COMPONENT main) + endif() endif() diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt index 713624686f..572f32581b 100644 --- a/samples/c/CMakeLists.txt +++ b/samples/c/CMakeLists.txt @@ -3,67 +3,57 @@ # # ---------------------------------------------------------------------------- -if (BUILD_EXAMPLES) - project(c_samples) +SET(OPENCV_C_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect + opencv_features2d opencv_calib3d opencv_legacy opencv_contrib) - if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") - endif() +ocv_check_dependencies(${OPENCV_C_SAMPLES_REQUIRED_DEPS}) + +if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) + project(c_samples) + + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") + endif() - include_directories( - "${CMAKE_SOURCE_DIR}/modules/core/include" - "${CMAKE_SOURCE_DIR}/modules/flann/include" - "${CMAKE_SOURCE_DIR}/modules/imgproc/include" - "${CMAKE_SOURCE_DIR}/modules/video/include" - "${CMAKE_SOURCE_DIR}/modules/highgui/include" - "${CMAKE_SOURCE_DIR}/modules/ml/include" - "${CMAKE_SOURCE_DIR}/modules/calib3d/include" - "${CMAKE_SOURCE_DIR}/modules/features2d/include" - "${CMAKE_SOURCE_DIR}/modules/objdetect/include" - "${CMAKE_SOURCE_DIR}/modules/legacy/include" - "${CMAKE_SOURCE_DIR}/modules/contrib/include" - ) + ocv_include_modules(${OPENCV_C_SAMPLES_REQUIRED_DEPS}) + + # --------------------------------------------- + # Define executable targets + # --------------------------------------------- + MACRO(OPENCV_DEFINE_C_EXAMPLE name srcs) + set(the_target "example_${name}") + add_executable(${the_target} ${srcs}) + target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_C_SAMPLES_REQUIRED_DEPS}) - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(MY_DEFINE_EXAMPLE name srcs) - set(the_target "example_${name}") - add_executable(${the_target} ${srcs}) - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${name}" - PROJECT_LABEL "(EXAMPLE) ${name}") - add_dependencies(${the_target} opencv_core opencv_flann opencv_imgproc opencv_highgui - opencv_ml opencv_video opencv_objdetect opencv_features2d - opencv_calib3d opencv_legacy opencv_contrib) - target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core - opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect - opencv_features2d opencv_calib3d opencv_legacy opencv_contrib) - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//c") - endif() - if(WIN32) - if (MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} - RUNTIME DESTINATION "samples/c" COMPONENT main) - endif() - ENDMACRO(MY_DEFINE_EXAMPLE) + set_target_properties(${the_target} PROPERTIES + OUTPUT_NAME "${name}" + PROJECT_LABEL "(EXAMPLE) ${name}") + + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "samples//c") + endif() + + if(WIN32) + if(MSVC AND NOT BUILD_SHARED_LIBS) + set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") + endif() + install(TARGETS ${the_target} + RUNTIME DESTINATION "samples/c" COMPONENT main) + endif() + ENDMACRO() - file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c) + file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c) - foreach(sample_filename ${cpp_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - MY_DEFINE_EXAMPLE(${sample} ${sample_filename}) - endforeach() -endif(BUILD_EXAMPLES) + foreach(sample_filename ${cpp_samples}) + get_filename_component(sample ${sample_filename} NAME_WE) + OPENCV_DEFINE_C_EXAMPLE(${sample} ${sample_filename}) + endforeach() +endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${C_SAMPLES} - DESTINATION share/opencv/samples/c - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) + install(FILES ${C_SAMPLES} + DESTINATION share/opencv/samples/c + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) endif () diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index c0d8a6c18b..95de6f2f66 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -3,77 +3,67 @@ # # ---------------------------------------------------------------------------- -if (BUILD_EXAMPLES) - project(cpp_samples) +SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect + opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching) - include_directories( - "${CMAKE_SOURCE_DIR}/modules/core/include" - "${CMAKE_SOURCE_DIR}/modules/flann/include" - "${CMAKE_SOURCE_DIR}/modules/imgproc/include" - "${CMAKE_SOURCE_DIR}/modules/video/include" - "${CMAKE_SOURCE_DIR}/modules/highgui/include" - "${CMAKE_SOURCE_DIR}/modules/ml/include" - "${CMAKE_SOURCE_DIR}/modules/calib3d/include" - "${CMAKE_SOURCE_DIR}/modules/features2d/include" - "${CMAKE_SOURCE_DIR}/modules/objdetect/include" - "${CMAKE_SOURCE_DIR}/modules/legacy/include" - "${CMAKE_SOURCE_DIR}/modules/contrib/include" - "${CMAKE_SOURCE_DIR}/modules/stitching/include" - ) - if (NOT ANDROID) - include_directories("${CMAKE_SOURCE_DIR}/modules/gpu/include") - endif() +ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) - if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") - endif() + +if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) + project(cpp_samples) + + include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp + ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) + + if (HAVE_opencv_gpu) + include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include") + endif() + + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") + endif() - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(MY_DEFINE_EXAMPLE name srcs) - set(the_target "example_${name}") - add_executable(${the_target} ${srcs}) - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${name}" - PROJECT_LABEL "(EXAMPLE) ${name}") - add_dependencies(${the_target} opencv_core opencv_flann opencv_imgproc opencv_highgui - opencv_ml opencv_video opencv_objdetect opencv_features2d - opencv_calib3d opencv_legacy opencv_contrib opencv_stitching) - target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core - opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect - opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching) + # --------------------------------------------- + # Define executable targets + # --------------------------------------------- + MACRO(OPENCV_DEFINE_CPP_EXAMPLE name srcs) + set(the_target "example_${name}") + add_executable(${the_target} ${srcs}) + target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS}) + + if (HAVE_opencv_gpu) + target_link_libraries(${the_target} opencv_gpu) + endif() - if (NOT ANDROID) - target_link_libraries(${the_target} opencv_gpu) - add_dependencies(${the_target} opencv_gpu) - endif() + set_target_properties(${the_target} PROPERTIES + OUTPUT_NAME "${name}" + PROJECT_LABEL "(EXAMPLE) ${name}") - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp") - endif() + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp") + endif() - if(WIN32) - if (MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} - RUNTIME DESTINATION "samples/cpp" COMPONENT main) - endif() - ENDMACRO(MY_DEFINE_EXAMPLE) + if(WIN32) + if (MSVC AND NOT BUILD_SHARED_LIBS) + set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") + endif() + install(TARGETS ${the_target} + RUNTIME DESTINATION "samples/cpp" COMPONENT main) + endif() + ENDMACRO() - file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) + file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - foreach(sample_filename ${cpp_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - MY_DEFINE_EXAMPLE(${sample} ${sample_filename}) - endforeach() -endif(BUILD_EXAMPLES) + foreach(sample_filename ${cpp_samples}) + get_filename_component(sample ${sample_filename} NAME_WE) + OPENCV_DEFINE_CPP_EXAMPLE(${sample} ${sample_filename}) + endforeach() +endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) - file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${C_SAMPLES} - DESTINATION share/opencv/samples/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) -endif () + file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) + install(FILES ${C_SAMPLES} + DESTINATION share/opencv/samples/cpp + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) +endif() diff --git a/samples/cpp/hybridtrackingsample.cpp b/samples/cpp/hybridtrackingsample.cpp index 244a191a2d..3dfce990c6 100644 --- a/samples/cpp/hybridtrackingsample.cpp +++ b/samples/cpp/hybridtrackingsample.cpp @@ -11,14 +11,15 @@ * */ -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include #include #include +#include "opencv2/highgui/highgui.hpp" #include "opencv2/contrib/hybridtracker.hpp" using namespace cv; diff --git a/samples/cpp/image.cpp b/samples/cpp/image.cpp index 8b135347c9..e4805c434b 100644 --- a/samples/cpp/image.cpp +++ b/samples/cpp/image.cpp @@ -1,8 +1,7 @@ -#include "cv.h" // include standard OpenCV headers, same as before -#include "highgui.h" -#include "ml.h" #include #include +#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui/highgui.hpp" #include "opencv2/flann/miniflann.hpp" using namespace cv; // all the new API is put into "cv" namespace. Export its content diff --git a/samples/cpp/stitching_detailed.cpp b/samples/cpp/stitching_detailed.cpp index 4f01f72efe..c2f943942c 100644 --- a/samples/cpp/stitching_detailed.cpp +++ b/samples/cpp/stitching_detailed.cpp @@ -43,6 +43,7 @@ #include #include +#include "opencv2/opencv_modules.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/stitching/detail/autocalib.hpp" #include "opencv2/stitching/detail/blenders.hpp" @@ -346,7 +347,7 @@ int main(int argc, char* argv[]) Ptr finder; if (features == "surf") { -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) finder = new SurfFeaturesFinderGpu(); else @@ -530,7 +531,7 @@ int main(int argc, char* argv[]) // Warp images and their masks Ptr warper_creator; -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) { if (warp_type == "plane") warper_creator = new cv::PlaneWarperGpu(); @@ -582,7 +583,7 @@ int main(int argc, char* argv[]) seam_finder = new detail::VoronoiSeamFinder(); else if (seam_find_type == "gc_color") { -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR); else @@ -591,7 +592,7 @@ int main(int argc, char* argv[]) } else if (seam_find_type == "gc_colorgrad") { -#ifndef ANDROID +#ifdef HAVE_OPENCV_GPU if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR_GRAD); else diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index e2cb1071ba..3aa3635408 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -1,77 +1,69 @@ -if (BUILD_EXAMPLES) - set(project "gpu") - string(TOUPPER "${project}" project_upper) +SET(OPENCV_GPU_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui + opencv_ml opencv_video opencv_objdetect opencv_features2d + opencv_calib3d opencv_legacy opencv_contrib opencv_gpu) + +ocv_check_dependencies(${OPENCV_GPU_SAMPLES_REQUIRED_DEPS}) + +if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) + set(project "gpu") + string(TOUPPER "${project}" project_upper) - project("${project}_samples") + project("${project}_samples") - include_directories( - "${CMAKE_SOURCE_DIR}/modules/core/include" - "${CMAKE_SOURCE_DIR}/modules/flann/include" - "${CMAKE_SOURCE_DIR}/modules/imgproc/include" - "${CMAKE_SOURCE_DIR}/modules/video/include" - "${CMAKE_SOURCE_DIR}/modules/highgui/include" - "${CMAKE_SOURCE_DIR}/modules/ml/include" - "${CMAKE_SOURCE_DIR}/modules/calib3d/include" - "${CMAKE_SOURCE_DIR}/modules/features2d/include" - "${CMAKE_SOURCE_DIR}/modules/objdetect/include" - "${CMAKE_SOURCE_DIR}/modules/legacy/include" - "${CMAKE_SOURCE_DIR}/modules/contrib/include" - "${CMAKE_SOURCE_DIR}/modules/gpu/include" - "${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia" - "${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia/core" + ocv_include_modules(${OPENCV_GPU_SAMPLES_REQUIRED_DEPS}) + include_directories( + "${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia" + "${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia/core" ) - if(HAVE_CUDA) - include_directories(${CUDA_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia ${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia/core) - endif() + if(HAVE_CUDA) + include_directories(${CUDA_INCLUDE_DIRS} ${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia ${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia/core) + endif() - if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") - endif() + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") + endif() - # --------------------------------------------- - # Define executable targets - # --------------------------------------------- - MACRO(MY_DEFINE_EXAMPLE name srcs) - set(the_target "example_${project}_${name}") - add_executable(${the_target} ${srcs}) - set_target_properties(${the_target} PROPERTIES - OUTPUT_NAME "${name}_${project}" - PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") - add_dependencies(${the_target} opencv_core opencv_flann opencv_imgproc opencv_highgui - opencv_ml opencv_video opencv_objdetect opencv_features2d - opencv_calib3d opencv_legacy opencv_contrib opencv_gpu) - target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core - opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect - opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_gpu) + # --------------------------------------------- + # Define executable targets + # --------------------------------------------- + MACRO(OPENCV_DEFINE_GPU_EXAMPLE name srcs) + set(the_target "example_${project}_${name}") + add_executable(${the_target} ${srcs}) - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") - endif() + target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_GPU_SAMPLES_REQUIRED_DEPS}) - if(WIN32) - if (MSVC AND NOT BUILD_SHARED_LIBS) - set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${project}" COMPONENT main) - endif() - ENDMACRO(MY_DEFINE_EXAMPLE) + set_target_properties(${the_target} PROPERTIES + OUTPUT_NAME "${name}_${project}" + PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") + + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "samples//${project}") + endif() + + if(WIN32) + if(MSVC AND NOT BUILD_SHARED_LIBS) + set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") + endif() + install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${project}" COMPONENT main) + endif() + ENDMACRO() - file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) + file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - foreach(sample_filename ${all_samples}) - get_filename_component(sample ${sample_filename} NAME_WE) - file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) - MY_DEFINE_EXAMPLE(${sample} ${sample_srcs}) - endforeach() + foreach(sample_filename ${all_samples}) + get_filename_component(sample ${sample_filename} NAME_WE) + file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) + OPENCV_DEFINE_GPU_EXAMPLE(${sample} ${sample_srcs}) + endforeach() - include("performance/CMakeLists.txt") -endif(BUILD_EXAMPLES) + include("performance/CMakeLists.txt") +endif() if (NOT WIN32) - file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${install_list} - DESTINATION share/opencv/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) -endif () + file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) + install(FILES ${install_list} + DESTINATION share/opencv/samples/${project} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) +endif() diff --git a/samples/gpu/cascadeclassifier_nvidia_api.cpp b/samples/gpu/cascadeclassifier_nvidia_api.cpp index c2d216c6e4..528cf0bbd8 100644 --- a/samples/gpu/cascadeclassifier_nvidia_api.cpp +++ b/samples/gpu/cascadeclassifier_nvidia_api.cpp @@ -6,7 +6,6 @@ #include #include #include -#include "opencv2/opencv.hpp" #include "opencv2/gpu/gpu.hpp" #ifdef HAVE_CUDA @@ -228,6 +227,7 @@ int main(int argc, const char** argv) NCVVectorAlloc h_haarNodes(cpuCascadeAllocator, haarNumNodes); ncvAssertPrintReturn(h_haarNodes.isMemAllocated(), "Error in cascade CPU allocator", -1); NCVVectorAlloc h_haarFeatures(cpuCascadeAllocator, haarNumFeatures); + ncvAssertPrintReturn(h_haarFeatures.isMemAllocated(), "Error in cascade CPU allocator", -1); HaarClassifierCascadeDescriptor haar; diff --git a/samples/gpu/opticalflow_nvidia_api.cpp b/samples/gpu/opticalflow_nvidia_api.cpp index 5cbb0a6845..51f38361a5 100644 --- a/samples/gpu/opticalflow_nvidia_api.cpp +++ b/samples/gpu/opticalflow_nvidia_api.cpp @@ -11,7 +11,6 @@ #include "cvconfig.h" #include #include -#include "opencv2/opencv.hpp" #include "opencv2/gpu/gpu.hpp" #ifdef HAVE_CUDA diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 5d07411736..6ad99a1355 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -4,30 +4,23 @@ file(GLOB sources "performance/*.cpp") file(GLOB headers "performance/*.h") add_executable(${the_target} ${sources} ${headers}) +target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_GPU_SAMPLES_REQUIRED_DEPS}) set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "performance_gpu" PROJECT_LABEL "(EXAMPLE_GPU) performance") -add_dependencies(${the_target} opencv_core opencv_flann opencv_imgproc opencv_highgui - opencv_ml opencv_video opencv_objdetect opencv_features2d - opencv_calib3d opencv_legacy opencv_contrib opencv_gpu) - -target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core - opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect - opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_gpu) - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "samples//gpu") + set_target_properties(${the_target} PROPERTIES FOLDER "samples//gpu") endif() if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "samples/gpu" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "samples/gpu" COMPONENT main) endif() if(NOT WIN32) - file(GLOB GPU_FILES performance/*.cpp performance/*.h) - install(FILES ${GPU_FILES} - DESTINATION share/opencv/samples/gpu/performance - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) -endif() \ No newline at end of file + file(GLOB GPU_FILES performance/*.cpp performance/*.h) + install(FILES ${GPU_FILES} + DESTINATION share/opencv/samples/gpu/performance + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) +endif()