Warning, /maui/buho/cmake/FindOpenCV.cmake is written in an unsupported language. File is not indexed.

0001 ##############################################################################
0002  # @file  FindOpenCV.cmake
0003  # @brief Find OpenCV Library (http://sourceforge.net/projects/opencvlibrary/)
0004  #
0005  # @par 1. Setup
0006  #
0007  # The following variables are optionally searched for defaults
0008  #  OpenCV_DIR:            Base directory of OpenCv tree to use.
0009  #
0010  # @par 2. Variable
0011  #
0012  # The following are set after configuration is done:
0013  # - OpenCV_FOUND
0014  # - OpenCV_LIBS
0015  # - OpenCV_INCLUDE_DIR
0016  # - OpenCV_VERSION (OpenCV_VERSION_MAJOR, OpenCV_VERSION_MINOR, OpenCV_VERSION_PATCH)
0017  #
0018  #
0019  # The following variables are used to maintain compatibility with other
0020  # Find<Pkg>.cmake modules, including the FindOpenCV.cmake module of
0021  # Jan Woetzel (2006/09, www.mip.informatik.uni-kiel.de/~jw):
0022  # - OpenCV_INCLUDE_DIRS
0023  # - OpenCV_LIBRARIES
0024  # - OpenCV_LINK_DIRECTORIES
0025  #
0026  # @par 3. Version
0027  #
0028  # 2012/10/22 Andreas Schuh, Find OpenCV 2 also if OpenCVConfig.cmake missing.
0029  # 2012/02/28 Andreas Schuh, Reimplemented module to work also for OpenCV 1.x.
0030  # 2010/04/07 Benoit Rat, Correct a bug when OpenCVConfig.cmake is not found.
0031  # 2010/03/24 Benoit Rat, Add compatibility for when OpenCVConfig.cmake is not found.
0032  # 2010/03/22 Benoit Rat, Creation of the script.
0033  #
0034  #
0035  # tested with:
0036  # - OpenCV 2.1:  MinGW, MSVC2008
0037  # - OpenCV 2.0:  MinGW, MSVC2008, GCC4
0038  #
0039  # @par 4. Licence
0040  #
0041  # LGPL 2.1 : GNU Lesser General Public License Usage
0042  # Alternatively, this file may be used under the terms of the GNU Lesser
0043  #
0044  # General Public License version 2.1 as published by the Free Software
0045  # Foundation and appearing in the file LICENSE.LGPL included in the
0046  # packaging of this file.  Please review the following information to
0047  # ensure the GNU Lesser General Public License version 2.1 requirements
0048  # will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
0049  #
0050  # @ingroup CMakeFindModules
0051  ##############################################################################
0052 
0053  # ----------------------------------------------------------------------------
0054  # initialize search
0055  set (OpenCV_FOUND FALSE)
0056 
0057  set(OpenCV_INCLUDE_DIR /usr/include/opencv4/opencv2)
0058 
0059  set(OpenCV_DIR /usr/lib/cmake/opencv4)
0060 
0061  # 1. set OpenCV_DIR from environment variables
0062  if (NOT OpenCV_DIR)
0063    if (DEFINED ENV{OpenCV_DIR})
0064      set (OpenCV_DIR "$ENV{OpenCV_DIR}" CACHE PATH "Installation prefix of OpenCV Library." FORCE)
0065    elseif (DEFINED ENV{OPENCV_DIR})
0066      set (OpenCV_DIR "$ENV{OPENCV_DIR}" CACHE PATH "Installation prefix of OpenCV Library." FORCE)
0067    endif ()
0068  endif ()
0069  # 2. otherwise, try to derive it from include path
0070  if (NOT OpenCV_DIR)
0071    # a) look for include path which might be easily found using system default
0072    #    paths such as C_INCLUDE_PATH or CXX_INCLUDE_PATH
0073    find_path (
0074      OpenCV_INCLUDE_DIR "cv.h"
0075      PATH_SUFFIXES "include" "include/opencv"
0076      DOC "Directory of cv.h header file."
0077    )
0078    mark_as_advanced (OpenCV_INCLUDE_DIR)
0079    # b) derive OpenCV_DIR from include path
0080    if (OpenCV_INCLUDE_DIR)
0081      # Mac OS Framework
0082      string (REGEX REPLACE "/Headers(/.*)?$" "" OpenCV_DIR "${OpenCV_INCLUDE_DIR}")
0083      # OpenCV 1
0084      string (REGEX REPLACE "/include(/.*)$" "" OpenCV_DIR "${OpenCV_DIR}")
0085      # OpenCV >= 2
0086      if (EXISTS "${OpenCV_DIR}/share/opencv/OpenCVConfig.cmake")
0087        set (OpenCV_DIR "${OpenCV_DIR}/share/opencv")
0088      endif ()
0089      # cache it such that users can view/correct it
0090      set (OpenCV_DIR "${OpenCV_DIR}" CACHE PATH "Installation prefix of OpenCV Library." FORCE)
0091    endif ()
0092  endif ()
0093 
0094  set (OpenCV_LIBS)                # found libraries
0095  set (OpenCV_COMPONENTS_REQUIRED) # requested components
0096  set (OpenCV_LIB_COMPONENTS)      # found components
0097  set (OpenCV_VERSION)             # found version
0098 
0099  # ----------------------------------------------------------------------------
0100  # find headers and libraries
0101  if (EXISTS "${OpenCV_DIR}")
0102 
0103    # --------------------------------------------------------------------------
0104    # OpenCV 2
0105    if (EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake")
0106 
0107      include ("${OpenCV_DIR}/OpenCVConfig.cmake")
0108 
0109      foreach (__CVLIB IN LISTS OpenCV_COMPONENTS)
0110        if (NOT __CVLIB MATCHES "^opencv_")
0111          set (__CVLIB "opencv_${__CVLIB}")
0112        endif ()
0113        list (APPEND OpenCV_COMPONENTS_REQUIRED "${__CVLIB}")
0114      endforeach ()
0115 
0116      # Note that OpenCV 2.0.0 does only call the command include_directories()
0117      # but does not set OpenCV_INCLUDE_DIRS. This variable was added to
0118      # OpenCVConfig.cmake since version 2.1.0 of OpenCV.
0119      get_directory_property (__INCLUDE_DIRS INCLUDE_DIRECTORIES)
0120      find_path (
0121        OpenCV_INCLUDE_DIR "cv.h"
0122        HINTS ${__INCLUDE_DIRS}
0123        DOC "Directory of cv.h header file."
0124        NO_DEFAULT_PATH
0125      )
0126      mark_as_advanced (OpenCV_INCLUDE_DIR)
0127      unset (__INCLUDE_DIRS)
0128 
0129    # --------------------------------------------------------------------------
0130    # OpenCV 1 (or OpenCV 2 with missing OpenCVConfig.cmake file)
0131    else ()
0132 
0133      # will be adjusted on Unix to find the correct library version
0134      set (OpenCV_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
0135 
0136      # find include directory
0137      find_path (
0138        OpenCV_INCLUDE_DIR "cv.h"
0139        PATHS "${OpenCV_DIR}"
0140        PATH_SUFFIXES "include" "include/opencv"
0141        DOC "Directory of cv.h header file."
0142        NO_DEFAULT_PATH
0143      )
0144 
0145      mark_as_advanced (OpenCV_INCLUDE_DIR)
0146 
0147      if (EXISTS ${OpenCV_INCLUDE_DIR})
0148        # should not be done by Find module, but OpenCVConfig.cmake does it
0149        # as well, unfortunately...
0150        include_directories (${OpenCV_INCLUDE_DIR})
0151        # extract version information from header file
0152        if (EXISTS "${OpenCV_INCLUDE_DIR}/cvver.h")
0153          file (STRINGS "${OpenCV_INCLUDE_DIR}/cvver.h" OpenCV_VERSIONS_TMP REGEX "^#define CV_[A-Z]+_VERSION[ \t]+[0-9]+$")
0154        elseif (EXISTS "${OpenCV_INCLUDE_DIR}/../opencv2/core/version.hpp")
0155          file (STRINGS "${OpenCV_INCLUDE_DIR}/../opencv2/core/version.hpp" OpenCV_VERSIONS_TMP REGEX "^#define CV_[A-Z]+_VERSION[ \t]+[0-9]+$")
0156        else ()
0157          message (FATAL_ERROR "Missing ${OpenCV_INCLUDE_DIR}/cvver.h or ${OpenCV_INCLUDE_DIR}/../opencv2/core/version.hpp file!")
0158        endif ()
0159        string (REGEX REPLACE ".*#define CV_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_MAJOR ${OpenCV_VERSIONS_TMP})
0160        string (REGEX REPLACE ".*#define CV_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_MINOR ${OpenCV_VERSIONS_TMP})
0161        string (REGEX REPLACE ".*#define CV_SUBMINOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_PATCH ${OpenCV_VERSIONS_TMP})
0162        set (OpenCV_VERSION "${OpenCV_VERSION_MAJOR}.${OpenCV_VERSION_MINOR}.${OpenCV_VERSION_PATCH}")
0163        # file name suffixes
0164        if (UNIX)
0165          set (OpenCV_CVLIB_NAME_SUFFIX)
0166          set (CMAKE_FIND_LIBRARY_SUFFIXES)
0167          foreach (SUFFIX IN LISTS OpenCV_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
0168            if (NOT SUFFIX MATCHES "\\.${OpenCV_VERSION_MAJOR}\\.${OpenCV_VERSION_MINOR}\\.${OpenCV_VERSION_PATCH}$")
0169              set (SUFFIX "${SUFFIX}.${OpenCV_VERSION}")
0170            endif ()
0171            list (APPEND CMAKE_FIND_LIBRARY_SUFFIXES "${SUFFIX}")
0172          endforeach ()
0173          # for the 1.1pre1 version, the suffix of the libraries is by default .2.0.0 instead of .1.1.0
0174          # thus consider these library files as well, assuming that the suffix has not been corrected
0175          if (OpenCV_VERSION VERSION_EQUAL 1.1.0)
0176            foreach (SUFFIX IN LISTS OpenCV_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
0177              if (NOT SUFFIX MATCHES "\\.2\\.0\\.0$")
0178                list (APPEND CMAKE_FIND_LIBRARY_SUFFIXES "${SUFFIX}.2.0.0")
0179              endif ()
0180            endforeach ()
0181          endif ()
0182        else ()
0183          set (OpenCV_CVLIB_NAME_SUFFIX "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
0184        endif ()
0185      endif ()
0186 
0187      # library components
0188      if (OpenCV_VERSION_MAJOR GREATER 1)
0189        set (OpenCV_LIB_COMPONENTS core ml  video calib3d contrib features2d flann gpu highgui imgproc objdetect legacy)
0190      else ()
0191        set (OpenCV_LIB_COMPONENTS cxcore cv ml highgui cvaux)
0192      endif ()
0193 
0194      if (OpenCV_COMPONENTS)
0195        foreach (__CVLIB IN LISTS OpenCV_COMPONENTS)
0196          string (REGEX REPLACE "^opencv_" "" __CVLIB__ "${__CVLIB}")
0197          list (FIND OpenCV_LIB_COMPONENTS ${__CVLIB__} IDX)
0198          if (IDX EQUAL -1)
0199            message (FATAL_ERROR "Unknown OpenCV library component: ${__CVLIB}"
0200                                 " Are you looking for OpenCV 2.0.0 or greater?"
0201                                 " In this case, please set OpenCV_DIR to the"
0202                                 " directory containing the OpenCVConfig.cmake file.")
0203          endif ()
0204          list (APPEND OpenCV_COMPONENTS_REQUIRED "${__CVLIB__}")
0205        endforeach ()
0206      else ()
0207        set (OpenCV_COMPONENTS_REQUIRED ${OpenCV_LIB_COMPONENTS})
0208      endif ()
0209 
0210      # find libraries of components
0211      set (OpenCV_LIB_COMPONENTS)
0212      foreach (__CVLIB IN LISTS OpenCV_COMPONENTS_REQUIRED)
0213 
0214        # debug build
0215        find_library (
0216          OpenCV_${__CVLIB}_LIBRARY_DEBUG
0217          NAMES "opencv_${__CVLIB}${OpenCV_CVLIB_NAME_SUFFIX}d" "${__CVLIB}${OpenCV_CVLIB_NAME_SUFFIX}d"
0218          PATHS "${OpenCV_DIR}/lib"
0219          NO_DEFAULT_PATH
0220        )
0221 
0222        # release build
0223        if (APPLE AND OpenCV_DIR MATCHES "/OpenCV\\.framework/*$" AND EXISTS "${OpenCV_DIR}/OpenCV" AND NOT IS_DIRECTORY "${OpenCV_DIR}/OpenCV")
0224          find_file (
0225            OpenCV_${__CVLIB}_LIBRARY_RELEASE
0226            NAMES OpenCV
0227            PATHS "${OpenCV_DIR}"
0228            NO_DEFAULT_PATH
0229          )
0230        else ()
0231          find_library (
0232            OpenCV_${__CVLIB}_LIBRARY_RELEASE
0233            NAMES "opencv_${__CVLIB}${OpenCV_CVLIB_NAME_SUFFIX}" "${__CVLIB}${OpenCV_CVLIB_NAME_SUFFIX}"
0234            PATHS "${OpenCV_DIR}/lib"
0235            NO_DEFAULT_PATH
0236          )
0237        endif ()
0238 
0239        mark_as_advanced (OpenCV_${__CVLIB}_LIBRARY_DEBUG)
0240        mark_as_advanced (OpenCV_${__CVLIB}_LIBRARY_RELEASE)
0241 
0242        # both debug/release
0243        if (OpenCV_${__CVLIB}_LIBRARY_DEBUG AND OpenCV_${__CVLIB}_LIBRARY_RELEASE)
0244          set (OpenCV_${__CVLIB}_LIBRARY debug ${OpenCV_${__CVLIB}_LIBRARY_DEBUG} optimized ${OpenCV_${__CVLIB}_LIBRARY_RELEASE})
0245        # only debug
0246        elseif (OpenCV_${__CVLIB}_LIBRARY_DEBUG)
0247          set (OpenCV_${__CVLIB}_LIBRARY ${OpenCV_${__CVLIB}_LIBRARY_DEBUG})
0248        # only release
0249        elseif (OpenCV_${__CVLIB}_LIBRARY_RELEASE)
0250          set (OpenCV_${__CVLIB}_LIBRARY ${OpenCV_${__CVLIB}_LIBRARY_RELEASE})
0251        # not found
0252        else ()
0253          set (OpenCV_${__CVLIB}_LIBRARY)
0254        endif()
0255 
0256        # add to list of found libraries
0257        if (OpenCV_${__CVLIB}_LIBRARY)
0258          list (APPEND OpenCV_LIB_COMPONENTS ${__CVLIB})
0259          list (APPEND OpenCV_LIBS "${OpenCV_${__CVLIB}_LIBRARY}")
0260        endif ()
0261 
0262      endforeach ()
0263 
0264      # restore library suffixes
0265      set (CMAKE_FIND_LIBRARY_SUFFIXES "${OpenCV_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}")
0266 
0267      # compatibility with OpenCV 2
0268      set (OpenCV_INCLUDE_DIRS "${OpenCV_INCLUDE_DIR}")
0269 
0270    endif ()
0271 
0272    # --------------------------------------------------------------------------
0273    # set OpenCV_INCLUDE_DIRS - required for OpenCV before version 2.1.0
0274    if (OpenCV_INCLUDE_DIR MATCHES "/opencv$" AND NOT OpenCV_INCLUDE_DIRS)
0275      get_filename_component (OpenCV_INCLUDE_DIRS "${OpenCV_INCLUDE_DIR}" PATH)
0276      list (APPEND OpenCV_INCLUDE_DIRS "${OpenCV_INCLUDE_DIR}")
0277    endif ()
0278 
0279    # --------------------------------------------------------------------------
0280    # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
0281    # if all listed variables are found or TRUE
0282    include (FindPackageHandleStandardArgs)
0283 
0284    set (OpenCV_REQUIRED_COMPONENTS_FOUND TRUE)
0285    set (OpenCV_COMPONENTS_NOT_FOUND)
0286    foreach (__CVLIB IN LISTS OpenCV_COMPONENTS_REQUIRED)
0287      list (FIND OpenCV_LIB_COMPONENTS ${__CVLIB} IDX)
0288      if (IDX EQUAL -1)
0289        set (OpenCV_REQUIRED_COMPONENTS_FOUND FALSE)
0290        list (APPEND OpenCV_COMPONENTS_NOT_FOUND ${__CVLIB})
0291      endif ()
0292    endforeach ()
0293 
0294    if (NOT OpenCV_REQUIRED_COMPONENTS_FOUND)
0295      if (NOT OpenCV_FIND_QUIET AND OpenCV_FIND_REQUIRED)
0296        message (FATAL_ERROR "The following required OpenCV components"
0297                             " were not found: ${OpenCV_COMPONENTS_NOT_FOUND}")
0298      endif ()
0299    endif ()
0300 
0301    find_package_handle_standard_args (
0302      OpenCV
0303      REQUIRED_VARS
0304        OpenCV_INCLUDE_DIR
0305        OpenCV_LIBS
0306        OpenCV_REQUIRED_COMPONENTS_FOUND
0307      VERSION_VAR
0308        OpenCV_VERSION
0309    )
0310 
0311    set (OpenCV_FOUND "${OPENCV_FOUND}")
0312 
0313    # --------------------------------------------------------------------------
0314    # (backward) compatibility
0315    if (OpenCV_FOUND)
0316      set (OpenCV_LIBRARIES "${OpenCV_LIBS}")
0317    endif ()
0318 
0319  elseif (NOT OpenCV_FIND_QUIET AND OpenCV_FIND_REQUIRED)
0320    message (FATAL_ERROR "Please specify the OpenCV directory using OpenCV_DIR (environment) variable.")
0321  endif ()