Salome HOME
OpenCV 4 compatibility: even better check
[tools/configuration.git] / cmake / FindOpenCV.cmake
1 #########################################################################
2 # Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # - Find OpenCV
22 # Sets the following variables:
23 #   OpenCV_FOUND        - found flag
24 #   OpenCV_INCLUDE_DIRS - path to the OpenCV include directories
25 #   OpenCV_LIBS         - path to the OpenCV libraries to be linked against
26 #
27
28 IF(NOT OpenCV_FIND_QUIETLY)
29   MESSAGE(STATUS "Check for OpenCV ...")
30 ENDIF()
31
32 FIND_PATH(OpenCV_INCLUDE_DIRS opencv2/opencv.hpp)
33
34 SET(OpenCV_LIB_COMPONENTS videostab;video;ts;superres;stitching;photo;ocl;objdetect;ml;legacy;imgproc;highgui;gpu;flann;features2d;core;objdetect;imgcodecs;shape)
35
36 FOREACH(_compo ${OpenCV_LIB_COMPONENTS})
37   FIND_LIBRARY(OpenCV_${_compo} opencv_${_compo})
38   IF(OpenCV_${_compo})
39     LIST(APPEND OpenCV_LIBRARIES ${OpenCV_${_compo}})
40   ENDIF()
41 ENDFOREACH()
42 IF(OpenCV_LIBRARIES AND OpenCV_INCLUDE_DIRS)
43   IF(NOT OpenCV_LIBS)
44     SET(OpenCV_LIBS ${OpenCV_LIBRARIES})
45   ENDIF()
46   SET(OpenCV_FOUND 1)  
47
48   IF(NOT OpenCV_FIND_QUIETLY)
49     MESSAGE("OpenCV found !")
50   ENDIF()
51 ELSE()
52   IF(NOT OpenCV_FIND_QUIETLY)
53     MESSAGE("Could not find OpenCV ...")
54   ENDIF()
55 ENDIF()