FindLibv4l2.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #[=======================================================================[.rst
  2. FindLibv4l2
  3. -----------
  4. FindModule for Libv4l2 and associated libraries
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. .. versionadded:: 2.0
  10. This module defines the :prop_tgt:`IMPORTED` target ``Libv4l2::Libv4l2``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``Libv4l2_FOUND``
  15. True, if all required components and the core library were found.
  16. ``Libv4l2_VERSION``
  17. Detected version of found Libv4l2 libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``Libv4l2_LIBRARY``
  22. Path to the library component of Libv4l2.
  23. ``Libv4l2_INCLUDE_DIR``
  24. Directory containing ``libv4l2.h``.
  25. #]=======================================================================]
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_Libv4l2 QUIET libv4l2 v4l2 v4l-utils)
  30. endif()
  31. find_path(
  32. Libv4l2_INCLUDE_DIR
  33. NAMES libv4l2.h
  34. HINTS ${PC_Libv4l2_INCLUDE_DIRS}
  35. PATHS /usr/include /usr/local/include
  36. DOC "Libv4l2 include directory"
  37. )
  38. find_library(
  39. Libv4l2_LIBRARY
  40. NAMES v4l2
  41. HINTS ${PC_Libv4l2_LIBRARY_DIRS}
  42. PATHS /usr/lib /usr/local/lib
  43. DOC "Libv4l2 location"
  44. )
  45. if(PC_Libv4l2_VERSION VERSION_GREATER 0)
  46. set(Libv4l2_VERSION ${PC_Libv4l2_VERSION})
  47. else()
  48. if(NOT Libv4l2_FIND_QUIETLY)
  49. message(AUTHOR_WARNING "Failed to find Libv4l2 version.")
  50. endif()
  51. set(Libv4l2_VERSION 0.0.0)
  52. endif()
  53. find_package_handle_standard_args(
  54. Libv4l2
  55. REQUIRED_VARS Libv4l2_LIBRARY Libv4l2_INCLUDE_DIR
  56. VERSION_VAR Libv4l2_VERSION
  57. REASON_FAILURE_MESSAGE "Ensure that v4l-utils is installed on the system."
  58. )
  59. mark_as_advanced(Libv4l2_INCLUDE_DIR Libv4l2_LIBRARY)
  60. if(Libv4l2_FOUND)
  61. if(NOT TARGET Libv4l2::Libv4l2)
  62. if(IS_ABSOLUTE "${Libv4l2_LIBRARY}")
  63. add_library(Libv4l2::Libv4l2 UNKNOWN IMPORTED)
  64. set_property(TARGET Libv4l2::Libv4l2 PROPERTY IMPORTED_LOCATION "${Libv4l2_LIBRARY}")
  65. else()
  66. add_library(Libv4l2::Libv4l2 INTERFACE IMPORTED)
  67. set_property(TARGET Libv4l2::Libv4l2 PROPERTY IMPORTED_LIBNAME "${Libv4l2_LIBRARY}")
  68. endif()
  69. set_target_properties(
  70. Libv4l2::Libv4l2
  71. PROPERTIES
  72. INTERFACE_COMPILE_OPTIONS "${PC_Libv4l2_CFLAGS_OTHER}"
  73. INTERFACE_INCLUDE_DIRECTORIES "${Libv4l2_INCLUDE_DIR}"
  74. VERSION ${Libv4l2_VERSION}
  75. )
  76. endif()
  77. endif()
  78. include(FeatureSummary)
  79. set_package_properties(
  80. Lib4l2
  81. PROPERTIES
  82. URL "https://linuxtv.org/wiki/index.php/V4l-utils"
  83. DESCRIPTION "The v4l-utils are a series of packages for handling media devices."
  84. )