1# The CMake modules shipped with OpenCV do not contain targets.
2find_package(PkgConfig)
3
4pkg_check_modules(OPENCV opencv4)
5
6if(NOT OPENCV_FOUND)
7  pkg_check_modules(OPENCV opencv)
8endif()
9
10include(FindPackageHandleStandardArgs)
11find_package_handle_standard_args(OpenCV
12  REQUIRED_VARS OPENCV_LIBRARIES
13)
14
15# OpenCV 4 can contain broken path in .pc file so we need to filter it.
16# https://github.com/opencv/opencv/pull/17377
17set(OPENCV_VALID_INCLUDE_DIRS)
18foreach(dir ${OPENCV_INCLUDE_DIRS})
19  if(EXISTS ${dir})
20    list(APPEND OPENCV_VALID_INCLUDE_DIRS ${dir})
21  endif()
22endforeach()
23
24add_library(OpenCV::OpenCV INTERFACE IMPORTED)
25set_target_properties(OpenCV::OpenCV PROPERTIES
26  INTERFACE_INCLUDE_DIRECTORIES "${OPENCV_VALID_INCLUDE_DIRS}"
27  INTERFACE_LINK_LIBRARIES "${OPENCV_LIBRARIES}"
28)
29