diff --git a/CMakeLists.txt b/CMakeLists.txt index ee355a5ea..c26c824cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,7 +268,6 @@ if(ZM_SYSTEMD OR (IS_DIRECTORY /usr/lib/systemd/system) OR (IS_DIRECTORY /lib/sy endif() # System checks -check_include_file("linux/videodev2.h" HAVE_LINUX_VIDEODEV2_H) check_include_file("execinfo.h" HAVE_EXECINFO_H) if(HAVE_EXECINFO_H) check_function_exists("backtrace" HAVE_DECL_BACKTRACE) @@ -530,15 +529,16 @@ endif() # Check for V4L header files and enable ZM_HAS_V4L, ZM_HAS_V4L2 accordingly # Setting to zeros first is required because ZM uses #define for these +find_package(V4L2) set(ZM_HAS_V4L 0) set(ZM_HAS_V4L2 0) -if(HAVE_LINUX_VIDEODEV2_H) +if(TARGET V4L2::videodev2) set(ZM_HAS_V4L 1) set(ZM_HAS_V4L2 1) -endif() -if(NOT HAVE_LINUX_VIDEODEV2_H) +else() message(AUTHOR_WARNING "Video 4 Linux headers weren't found - Analog and USB camera support will not be available") endif() + # Check for PCRE and enable ZM_PCRE accordingly set(ZM_PCRE 0) if(HAVE_LIBPCRE AND HAVE_PCRE_H) diff --git a/cmake/Modules/FindV4L2.cmake b/cmake/Modules/FindV4L2.cmake new file mode 100644 index 000000000..bad2e6793 --- /dev/null +++ b/cmake/Modules/FindV4L2.cmake @@ -0,0 +1,99 @@ +#[=======================================================================[.rst: +FindV4L2 +---------- + +Find V4L2 headers and libv4l2 + + +This module accepts optional COMPONENTS: + + videodev2 (default) + libv4l2 + +IMPORTED Targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` targets:: + +``V4L2::videodev2`` + The Video for Linux Two header file, if found. +``V4L2::libv4l2`` + A thin abstraction layer on top of video4linux2 devices, if found. + +Result Variables +^^^^^^^^^^^^^^^^ + +``V4L2_FOUND`` + System has v4l2 support. If no components are specified only the videodev2.h header has to be found. +``V4L2_INCLUDE_DIRS`` + The v4l2 include directories. +``V4L2_LIBRARIES`` + The libraries needed to have v4l2 support according to the specified components. +#]=======================================================================] + +find_path(V4L2_VIDEODEV2_INCLUDE_DIR + NAMES linux/videodev2.h) +mark_as_advanced(V4L2_VIDEODEV2_INCLUDE_DIR) + +if(EXISTS "${V4L2_VIDEODEV2_INCLUDE_DIR}") + set(V4L2_videodev2_FOUND TRUE) +else() + set(V4L2_videodev2_FOUND FALSE) +endif() + +pkg_check_modules(PC_V4L2_LIBV4L2 QUIET libv4l2) + +find_path(V4L2_LIBV4L2_INCLUDE_DIR + NAMES libv4l2.h + HINTS + ${PC_V4L2_LIBV4L2_INCLUDEDIR} + ${PC_V4L2_LIBV4L2_INCLUDE_DIRS}) +mark_as_advanced(V4L2_LIBV4L2_INCLUDE_DIR) + +find_library(V4L2_LIBV4L2_LIBRARY + NAMES ${PC_V4L2_LIBV4L2_LIBRARIES} + HINTS + ${PC_V4L2_LIBV4L2_LIBDIR} + ${PC_V4L2_LIBV4L2_LIBRARY_DIR}) +mark_as_advanced(V4L2_LIBV4L2_LIBRARY) + +if(EXISTS "${V4L2_LIBV4L2_INCLUDE_DIR}" AND + EXISTS "${V4L2_LIBV4L2_LIBRARY}") + set(V4L2_libv4l2_FOUND TRUE) +else() + set(V4L2_libv4l2_FOUND FALSE) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(V4L2 + REQUIRED_VARS + V4L2_VIDEODEV2_INCLUDE_DIR + HANDLE_COMPONENTS) + +set(V4L2_INCLUDE_DIRS) +set(V4L2_LIBRARIES) + +if(V4L2_videodev2_FOUND) + set(V4L2_VIDEODEV2_INCLUDE_DIRS ${V4L2_VIDEODEV2_INCLUDE_DIR}) + list(APPEND V4L2_INCLUDE2_DIRS + "${V4L2_VIDEODEV2_INCLUDE_DIRS}") + + add_library(V4L2::videodev2 INTERFACE IMPORTED) + set_target_properties(V4L2::videodev2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${V4L2_VIDEODEV2_INCLUDE_DIRS}") +endif() + +if(V4L2_libv4l2_FOUND) + set(V4L2_LIBV4L2_INCLUDE_DIRS ${V4L2_LIBV4L2_INCLUDE_DIR}) + set(V4L2_LIBV4L2_LIBRARIES ${V4L2_LIBV4L2_LIBRARY}) + + list(APPEND V4L2_INCLUDE_DIRS + "${V4L2_LIBV4L2_INCLUDE_DIRS}") + list(APPEND V4L2_LIBRARIES + "${V4L2_LIBV4L2_LIBRARIES}") + + add_library(V4L2::libv4l2 UNKNOWN IMPORTED) + set_target_properties(V4L2::libv4l2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${V4L2_LIBV4L2_INCLUDE_DIRS}" + IMPORTED_LOCATION "${V4L2_LIBV4L2_LIBRARY}") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e8224db2..5f37ff0ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,6 +98,12 @@ elseif(${ZM_JWT_BACKEND} STREQUAL "libjwt") JWT::libjwt) endif() +if(TARGET V4L2::videodev2) + target_link_libraries(zm + PRIVATE + V4L2::videodev2) +endif() + add_executable(zmc zmc.cpp) add_executable(zms zms.cpp) add_executable(zmu zmu.cpp)