FindOpenCV.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Filename: FindOpenCV.cmake
  2. # Authors: CFSworks (3 Nov, 2018)
  3. #
  4. # Usage:
  5. # find_package(OpenCV [REQUIRED] [QUIET])
  6. #
  7. # This supports the following components:
  8. # calib3d
  9. # contrib
  10. # core
  11. # features2d
  12. # flann
  13. # gpu
  14. # highgui
  15. # imgproc
  16. # legacy
  17. # ml
  18. # nonfree
  19. # objdetect
  20. # photo
  21. # stitching
  22. # superres
  23. # video
  24. # videoio
  25. # videostab
  26. #
  27. # Once done this will define:
  28. # OPENCV_FOUND - system has OpenCV
  29. # OpenCV_INCLUDE_DIRS - the include dir(s) containing OpenCV header files
  30. # OpenCV_comp_LIBRARY - the path to the OpenCV library for the particular
  31. # component
  32. # OpenCV_LIBS - the paths to the OpenCV libraries for the requested
  33. # component(s)
  34. # OpenCV_VERSION_MAJOR- a "best guess" of the major version (X.x)
  35. # OpenCV_VERSION_MINOR- a "best guess" of the minor version (x.X)
  36. #
  37. set(OpenCV_INCLUDE_DIRS)
  38. find_path(OpenCV_V1_INCLUDE_DIR
  39. NAMES "cv.h"
  40. PATH_SUFFIXES "opencv")
  41. mark_as_advanced(OpenCV_V1_INCLUDE_DIR)
  42. if(OpenCV_V1_INCLUDE_DIR)
  43. list(APPEND OpenCV_INCLUDE_DIRS "${OpenCV_V1_INCLUDE_DIR}")
  44. # This is a wild guess:
  45. set(OpenCV_VERSION_MAJOR 1)
  46. set(OpenCV_VERSION_MINOR 0)
  47. endif()
  48. find_path(OpenCV_V2_INCLUDE_DIR "opencv2/core/version.hpp")
  49. mark_as_advanced(OpenCV_V2_INCLUDE_DIR)
  50. if(OpenCV_V2_INCLUDE_DIR)
  51. list(APPEND OpenCV_INCLUDE_DIRS "${OpenCV_V2_INCLUDE_DIR}")
  52. file(STRINGS "${OpenCV_V2_INCLUDE_DIR}/opencv2/core/version.hpp"
  53. _version_major REGEX "#define CV_VERSION_EPOCH")
  54. file(STRINGS "${OpenCV_V2_INCLUDE_DIR}/opencv2/core/version.hpp"
  55. _version_minor REGEX "#define CV_VERSION_MAJOR")
  56. string(REGEX REPLACE "[^0-9]" "" OpenCV_VERSION_MAJOR "${_version_major}")
  57. string(REGEX REPLACE "[^0-9]" "" OpenCV_VERSION_MINOR "${_version_minor}")
  58. unset(_version_major)
  59. unset(_version_minor)
  60. endif()
  61. set(OpenCV_LIBS)
  62. foreach(_component calib3d contrib core features2d flann gpu highgui imgproc
  63. legacy ml nonfree objdetect photo stitching superres video
  64. videoio videostab)
  65. list(FIND OpenCV_FIND_COMPONENTS "${_component}" _index)
  66. if(_index GREATER -1 OR _component STREQUAL "core")
  67. if(NOT OpenCV_${_component}_LIBRARY)
  68. find_library(OpenCV_${_component}_LIBRARY
  69. NAMES "opencv_${_component}")
  70. endif()
  71. if(OpenCV_${_component}_LIBRARY)
  72. list(APPEND OpenCV_LIBS "${OpenCV_${_component}_LIBRARY}")
  73. set(OpenCV_${_component}_FOUND ON)
  74. endif()
  75. endif()
  76. unset(_index)
  77. endforeach(_component)
  78. unset(_component)
  79. include(FindPackageHandleStandardArgs)
  80. find_package_handle_standard_args(OpenCV HANDLE_COMPONENTS
  81. REQUIRED_VARS OpenCV_INCLUDE_DIRS OpenCV_LIBS
  82. OpenCV_VERSION_MAJOR OpenCV_VERSION_MINOR)