########################################################### # Find OpenCV Library # See http://sourceforge.net/projects/opencvlibrary/ #---------------------------------------------------------- # ## 1: Setup: # The following variables are optionally searched for defaults # OpenCV_DIR: Base directory of OpenCv tree to use. # ## 2: Variable # The following are set after configuration is done: # # OpenCV_FOUND # OpenCV_LIBS # OpenCV_INCLUDE_DIR # OpenCV_VERSION (OpenCV_VERSION_MAJOR, OpenCV_VERSION_MINOR, OpenCV_VERSION_PATCH) # # # Deprecated variable are used to maintain backward compatibility with # the script of Jan Woetzel (2006/09): www.mip.informatik.uni-kiel.de/~jw # OpenCV_INCLUDE_DIRS # OpenCV_LIBRARIES # OpenCV_LINK_DIRECTORIES # ## 3: Version # # 2010/04/07 Benoit Rat, Correct a bug when OpenCVConfig.cmake is not found. # 2010/03/24 Benoit Rat, Add compatibility for when OpenCVConfig.cmake is not found. # 2010/03/22 Benoit Rat, Creation of the script. # # # tested with: # - OpenCV 2.1: MinGW, MSVC2008 # - OpenCV 2.0: MinGW, MSVC2008, GCC4 # # ## 4: Licence: # # LGPL 2.1 : GNU Lesser General Public License Usage # Alternatively, this file may be used under the terms of the GNU Lesser # General Public License version 2.1 as published by the Free Software # Foundation and appearing in the file LICENSE.LGPL included in the # packaging of this file. Please review the following information to # ensure the GNU Lesser General Public License version 2.1 requirements # will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. # #---------------------------------------------------------- if (ANDROID) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/android/${ANDROID_ABI}/OpenCV/sdk/native/jni" CACHE PATH "OpenCV SDK path" FORCE) elseif(WIN32 AND (WIN64 OR (CMAKE_SIZEOF_VOID_P EQUAL 8))) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/windows/x64/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(WIN32) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/windows/x86/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(APPLE AND NOT APPLE_IOS) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/apple/OSX/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(APPLE AND APPLE_IOS) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/apple/IOS/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(EMSCRIPTEN) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/emscripten/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(PIZERO) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/RPIZERO/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(PITHREE) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/RPI3/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(PIFOUR) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/RPI4/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(RPI) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/RPI2/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(LINUX32) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/linux32/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) elseif(LINUX64) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/linux64/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) else(SCOL_INSTALL_PREFIX) set(OpenCV_SDK_DIR "$ENV{SCOL_DEPENDENCIES_PATH}/sdk/${SCOL_INSTALL_PREFIX}/OpenCV" CACHE PATH "OpenCV SDK path" FORCE) endif() message(STATUS "trying to find opencv in ${OpenCV_SDK_DIR}") # On IOS, OpenCV is provided as a framework file find_path(OpenCV_DIR "OpenCVConfig.cmake" DOC "Root directory of OpenCV" PATH ${OpenCV_SDK_DIR} ${OpenCV_SDK_DIR}/share/OpenCV ${OpenCV_SDK_DIR}/lib/cmake/opencv4 NO_CMAKE_FIND_ROOT_PATH) message(STATUS "found OpenCV_DIR in ${OpenCV_DIR}") ##==================================================== ## Find OpenCV libraries ##---------------------------------------------------- if(EXISTS "${OpenCV_DIR}") #When its possible to use the Config script use it. if(EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake") ## Include the standard CMake script include("${OpenCV_DIR}/OpenCVConfig.cmake") ## Search for a specific version set(CVLIB_SUFFIX "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}") #Otherwise it try to guess it. else(EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake") set(OPENCV_LIB_COMPONENTS cxcore cv ml highgui cvaux) find_path(OpenCV_INCLUDE_DIR "opencv2/opencv.hpp" PATHS "${OpenCV_DIR}" PATH_SUFFIXES "include" "include" "include/opencv4" DOC "") if(EXISTS ${OpenCV_INCLUDE_DIR}) include_directories(${OpenCV_INCLUDE_DIR}) endif(EXISTS ${OpenCV_INCLUDE_DIR}) #Find OpenCV version by looking at version.hpp file(STRINGS ${OpenCV_INCLUDE_DIR}/core/version.hpp.h OpenCV_VERSIONS_TMP REGEX "^#define CV_[A-Z]+_VERSION[ \t]+[0-9]+$") string(REGEX REPLACE ".*#define CV_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_MAJOR ${OpenCV_VERSIONS_TMP}) string(REGEX REPLACE ".*#define CV_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_MINOR ${OpenCV_VERSIONS_TMP}) string(REGEX REPLACE ".*#define CV_SUBMINOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_PATCH ${OpenCV_VERSIONS_TMP}) set(OpenCV_VERSION ${OpenCV_VERSION_MAJOR}.${OpenCV_VERSION_MINOR}.${OpenCV_VERSION_PATCH} CACHE STRING "" FORCE) set(CVLIB_SUFFIX "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}") endif(EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake") if (OpenCV_VERSION) set(OpenCV_FOUND TRUE CACHE BOOL "" FORCE) endif() else(EXISTS "${OpenCV_DIR}") set(ERR_MSG "Please specify OpenCV directory using OpenCV_DIR env. variable") endif(EXISTS "${OpenCV_DIR}") ##==================================================== if(IOS) # OpenCV depends on several frameworks, we need to link against them in static builds if (Scol_STATIC) include(AppleMacros) find_apple_system_fwk(AVFOUNDATION_FWK AVFoundation) find_apple_system_fwk(COREVIDEO_FWK CoreVideo) find_apple_system_fwk(COREMEDIA_FWK CoreMedia) if (NOT (AVFOUNDATION_FWK AND COREVIDEO_FWK AND COREMEDIA_FWK)) set(OpenCV_FOUND FALSE) else() set(OpenCV_LIBS ${OpenCV_LIBS} ${AVFOUNDATION_FWK} ${COREMEDIA_FWK} ${COREVIDEO_FWK}) endif() endif(Scol_STATIC) endif(IOS) ##==================================================== ## Print message ##---------------------------------------------------- if(NOT OpenCV_FOUND) # make FIND_PACKAGE friendly if(NOT OpenCV_FIND_QUIETLY) if(OpenCV_FIND_REQUIRED) message(FATAL_ERROR "OpenCV required but some headers or libs not found. ${ERR_MSG}") else(OpenCV_FIND_REQUIRED) message(STATUS "WARNING: OpenCV was not found. ${ERR_MSG}") endif(OpenCV_FIND_REQUIRED) endif(NOT OpenCV_FIND_QUIETLY) endif(NOT OpenCV_FOUND) ##====================================================