FindOpenCV.cmake 2.08 KB
Newer Older
1 2 3
find_path(
cv_INCLUDE_DIR
opencv/cv.h
4 5
DOC "The directory where opencv/cv.h is installed")

6 7 8
find_path(
opencv2_INCLUDE_DIR
opencv2/opencv.hpp
9 10 11 12 13 14 15 16
DOC "The directory where opencv2/opencv.hpp is installed")

set(opencv_core_NAMES opencv_core)
set(opencv_ml_NAMES opencv_ml)

if ( cv_INCLUDE_DIR AND opencv2_INCLUDE_DIR )
	set(OPENCV_INCLUDE_DIRS "${cv_INCLUDE_DIR};${opencv2_INCLUDE_DIR}")
	list(REMOVE_DUPLICATES OPENCV_INCLUDE_DIRS)
17

18 19
	if(NOT OpenCV_VERSION)
		file(READ "${opencv2_INCLUDE_DIR}/opencv2/core/version.hpp" _header_content)
20
		string(REGEX REPLACE ".*# *define +CV_VERSION_EPOCH +([0-9]+).*" "\\1"
21
		OpenCV_VERSION_MAJOR ${_header_content})
22
		string(REGEX REPLACE ".*# *define +CV_VERSION_MAJOR +([0-9]+).*" "\\1"
23
		OpenCV_VERSION_MINOR ${_header_content})
24
		string(REGEX REPLACE ".*# *define +CV_VERSION_MINOR +([0-9]+).*" "\\1"
25
		OpenCV_VERSION_PATCH ${_header_content})
26
		string(REGEX REPLACE ".*# *define +CV_VERSION_REVISION +([0-9]+).*" "\\1"
27
		OpenCV_VERSION_TWEAK ${_header_content})
28
		set(OpenCV_VERSION
29 30
		"${OpenCV_VERSION_MAJOR}.${OpenCV_VERSION_MINOR}.${OpenCV_VERSION_PATCH}")
	endif()
31

32
	if(WIN32)
33
	list(APPEND opencv_core_NAMES
34
	"opencv_core${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
35
	list(APPEND opencv_ml_NAMES
36 37 38 39 40
	"opencv_ml${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
	endif()
endif()

# Prefer the static library.
41
find_library(
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
OPENCV_core_LIBRARY
NAMES ${opencv_core_NAMES}
DOC "Path to opencv_core library")

find_library(
OPENCV_ml_LIBRARY
NAMES ${opencv_ml_NAMES}
DOC "Path to opencv_ml library")

set(OpenCV_FOUND FALSE)
if ( OPENCV_core_LIBRARY AND OPENCV_ml_LIBRARY )
	set(OPENCV_LIBRARIES "${OPENCV_core_LIBRARY};${OPENCV_ml_LIBRARY}")
endif ()

if( OPENCV_INCLUDE_DIRS AND OPENCV_LIBRARIES )
57 58
  set(OpenCV_FOUND TRUE)
  set(OPENCV_VERSION ${OpenCV_VERSION}) #for compatility
59 60 61
endif()

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
62
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENCV
63 64
  REQUIRED_VARS OPENCV_core_LIBRARY OPENCV_INCLUDE_DIRS
  VERSION_VAR OpenCV_VERSION)