Merge pull request #3276 from Carbenium/cmake-ffmpeg

Build: Add CMake package module for FFmpeg
This commit is contained in:
Isaac Connor 2021-06-04 17:35:45 -04:00 committed by GitHub
commit 9cce9744d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 202 additions and 88 deletions

View File

@ -438,130 +438,83 @@ else()
message(FATAL_ERROR "ZoneMinder requires mysqlclient but it was not found on your system")
endif()
set(PATH_FFMPEG "")
set(OPT_FFMPEG "no")
# avformat (using find_library and find_path)
find_library(AVFORMAT_LIBRARIES avformat)
if(AVFORMAT_LIBRARIES)
find_package(FFMPEG COMPONENTS avformat)
if(FFMPEG_avformat_FOUND)
set(HAVE_LIBAVFORMAT 1)
list(APPEND ZM_BIN_LIBS "${AVFORMAT_LIBRARIES}")
find_path(AVFORMAT_INCLUDE_DIR "libavformat/avformat.h" /usr/include/ffmpeg)
if(AVFORMAT_INCLUDE_DIR)
include_directories("${AVFORMAT_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${AVFORMAT_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE AVFORMAT_LIBRARIES AVFORMAT_INCLUDE_DIR)
check_include_file("libavformat/avformat.h" HAVE_LIBAVFORMAT_AVFORMAT_H)
set(HAVE_LIBAVFORMAT_AVFORMAT_H 1)
list(APPEND ZM_BIN_LIBS "FFMPEG::avformat")
set(optlibsfound "${optlibsfound} AVFormat")
else()
set(optlibsnotfound "${optlibsnotfound} AVFormat")
endif()
# avcodec (using find_library and find_path)
find_library(AVCODEC_LIBRARIES avcodec)
if(AVCODEC_LIBRARIES)
find_package(FFMPEG COMPONENTS avcodec)
if(FFMPEG_avcodec_FOUND)
set(HAVE_LIBAVCODEC 1)
list(APPEND ZM_BIN_LIBS "${AVCODEC_LIBRARIES}")
find_path(AVCODEC_INCLUDE_DIR "libavcodec/avcodec.h" /usr/include/ffmpeg)
if(AVCODEC_INCLUDE_DIR)
include_directories("${AVCODEC_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${AVCODEC_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE AVCODEC_LIBRARIES AVCODEC_INCLUDE_DIR)
check_include_file("libavcodec/avcodec.h" HAVE_LIBAVCODEC_AVCODEC_H)
set(HAVE_LIBAVCODEC_AVCODEC_H 1)
list(APPEND ZM_BIN_LIBS "${FFMPEG_avcodec_LIBRARIES}")
set(optlibsfound "${optlibsfound} AVCodec")
else()
message(WARNING "\nWhile it should be possible to build ZM without AVCODEC the result will pretty useless.")
set(optlibsnotfound "${optlibsnotfound} AVCodec")
endif()
# avdevice (using find_library and find_path)
find_library(AVDEVICE_LIBRARIES avdevice)
if(AVDEVICE_LIBRARIES)
find_package(FFMPEG COMPONENTS avdevice)
if(FFMPEG_avdevice_FOUND)
set(HAVE_LIBAVDEVICE 1)
list(APPEND ZM_BIN_LIBS "${AVDEVICE_LIBRARIES}")
find_path(AVDEVICE_INCLUDE_DIR "libavdevice/avdevice.h" /usr/include/ffmpeg)
if(AVDEVICE_INCLUDE_DIR)
include_directories("${AVDEVICE_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${AVDEVICE_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE AVDEVICE_LIBRARIES AVDEVICE_INCLUDE_DIR)
check_include_file("libavdevice/avdevice.h" HAVE_LIBAVDEVICE_AVDEVICE_H)
set(HAVE_LIBAVDEVICE_AVDEVICE_H 1)
list(APPEND ZM_BIN_LIBS "${FFMPEG_avdevice_LIBRARIES}")
set(optlibsfound "${optlibsfound} AVDevice")
else()
set(optlibsnotfound "${optlibsnotfound} AVDevice")
endif()
# avutil (using find_library and find_path)
find_library(AVUTIL_LIBRARIES avutil)
if(AVUTIL_LIBRARIES)
find_package(FFMPEG COMPONENTS avutil)
if(FFMPEG_avutil_FOUND)
set(HAVE_LIBAVUTIL 1)
list(APPEND ZM_BIN_LIBS "${AVUTIL_LIBRARIES}")
find_path(AVUTIL_INCLUDE_DIR "libavutil/avutil.h" /usr/include/ffmpeg)
if(AVUTIL_INCLUDE_DIR)
include_directories("${AVUTIL_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${AVUTIL_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE AVUTIL_LIBRARIES AVUTIL_INCLUDE_DIR)
check_include_file("libavutil/avutil.h" HAVE_LIBAVUTIL_AVUTIL_H)
set(HAVE_LIBAVUTIL_AVUTIL_H 1)
set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_avutil_INCLUDE_DIRS})
check_include_file("libavutil/mathematics.h" HAVE_LIBAVUTIL_MATHEMATICS_H)
check_include_file("libavutil/hwcontext.h" HAVE_LIBAVUTIL_HWCONTEXT_H)
list(APPEND ZM_BIN_LIBS "${FFMPEG_avutil_LIBRARIES}")
set(optlibsfound "${optlibsfound} AVUtil")
else()
set(optlibsnotfound "${optlibsnotfound} AVUtil")
endif()
# swscale (using find_library and find_path)
find_library(SWSCALE_LIBRARIES swscale)
if(SWSCALE_LIBRARIES)
find_package(FFMPEG COMPONENTS swscale)
if(FFMPEG_swscale_FOUND)
set(HAVE_LIBSWSCALE 1)
list(APPEND ZM_BIN_LIBS "${SWSCALE_LIBRARIES}")
find_path(SWSCALE_INCLUDE_DIR "libswscale/swscale.h" /usr/include/ffmpeg)
if(SWSCALE_INCLUDE_DIR)
include_directories("${SWSCALE_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${SWSCALE_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE SWSCALE_LIBRARIES SWSCALE_INCLUDE_DIR)
check_include_file("libswscale/swscale.h" HAVE_LIBSWSCALE_SWSCALE_H)
set(HAVE_LIBSWSCALE_SWSCALE_H 1)
list(APPEND ZM_BIN_LIBS "${FFMPEG_swscale_LIBRARIES}")
set(optlibsfound "${optlibsfound} SWScale")
else()
set(optlibsnotfound "${optlibsnotfound} SWScale")
endif()
# SWresample (using find_library and find_path)
find_library(SWRESAMPLE_LIBRARIES swresample)
if(SWRESAMPLE_LIBRARIES)
find_package(FFMPEG COMPONENTS swresample)
if(FFMPEG_swresample_FOUND)
set(HAVE_LIBSWRESAMPLE 1)
list(APPEND ZM_BIN_LIBS "${SWRESAMPLE_LIBRARIES}")
find_path(SWRESAMPLE_INCLUDE_DIR "libswresample/swresample.h" /usr/include/ffmpeg)
if(SWRESAMPLE_INCLUDE_DIR)
include_directories("${SWRESAMPLE_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${SWRESAMPLE_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE SWRESAMPLE_LIBRARIES SWRESAMPLE_INCLUDE_DIR)
check_include_file("libswresample/swresample.h" HAVE_LIBSWRESAMPLE_SWRESAMPLE_H)
set(HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 1)
list(APPEND ZM_BIN_LIBS "${FFMPEG_swresample_LIBRARIES}")
set(optlibsfound "${optlibsfound} SWResample")
else()
set(optlibsnotfound "${optlibsnotfound} SWResample")
# AVresample (using find_library and find_path)
find_library(AVRESAMPLE_LIBRARIES avresample)
if(AVRESAMPLE_LIBRARIES)
find_package(FFMPEG COMPONENTS avresample)
if(FFMPEG_avresample_FOUND)
set(HAVE_LIBAVRESAMPLE 1)
list(APPEND ZM_BIN_LIBS "${AVRESAMPLE_LIBRARIES}")
find_path(AVRESAMPLE_INCLUDE_DIR "libavresample/avresample.h" /usr/include/ffmpeg)
if(AVRESAMPLE_INCLUDE_DIR)
include_directories("${AVRESAMPLE_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES "${AVRESAMPLE_INCLUDE_DIR}")
endif()
mark_as_advanced(FORCE AVRESAMPLE_LIBRARIES AVRESAMPLE_INCLUDE_DIR)
check_include_file("libavresample/avresample.h" HAVE_LIBAVRESAMPLE_AVRESAMPLE_H)
set(HAVE_LIBAVRESAMPLE_AVRESAMPLE_H 1)
list(APPEND ZM_BIN_LIBS "${FFMPEG_avresample_LIBRARIES}")
set(optlibsfound "${optlibsfound} AVResample")
else()
set(optlibsnotfound "${optlibsnotfound} AVResample")
endif()
endif()
set(PATH_FFMPEG "")
set(OPT_FFMPEG "no")
# Find the path to the ffmpeg executable
find_program(FFMPEG_EXECUTABLE
NAMES ffmpeg avconv

View File

@ -0,0 +1,166 @@
#[=======================================================================[.rst:
FindFFMPEG
----------
Find the FFmpeg and associated libraries.
This module accepts following COMPONENTS::
avcodec
avdevice
avfilter
avformat
avutil
swresample
swscale
avresample
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` targets:
``FFMPEG::<component>``
The FFmpeg component.
Result Variables
^^^^^^^^^^^^^^^^
``FFMPEG_INCLUDE_DIRS``
Include directories necessary to use FFmpeg.
``FFMPEG_LIBRARIES``
Libraries necessary to use FFmpeg. Note that this only includes libraries for the components requested.
``FFMPEG_VERSION``
The version of FFMPEG found (avutil).
For each component, the following are provided:
``FFMPEG_<component>_FOUND``
FFmpeg component was found.
``FFMPEG_<component>_INCLUDE_DIRS``
Include directories for the component.
``FFMPEG_<component>_LIBRARIES``
Libraries for the component.
#]=======================================================================]
function(_ffmpeg_find component pkgconfig_name header)
find_package(PkgConfig)
pkg_check_modules(PC_FFMPEG_${component} ${pkgconfig_name})
find_path(FFMPEG_${component}_INCLUDE_DIR
NAMES "lib${component}/${header}"
HINTS
${PC_FFMPEG_${component}_INCLUDEDIR}
${PC_FFMPEG_${component}_INCLUDE_DIRS}
PATH_SUFFIXES
ffmpeg)
mark_as_advanced("FFMPEG_${component}_INCLUDE_DIR")
find_library(FFMPEG_${component}_LIBRARY
NAMES
${component}
${PC_FFMPEG_${component}_LIBRARIES}
HINTS
${PC_FFMPEG_${component}_LIBDIR}
${PC_FFMPEG_${component}_LIBRARY_DIRS})
mark_as_advanced("${component}_LIBRARY")
if(FFMPEG_${component}_LIBRARY AND FFMPEG_${component}_INCLUDE_DIR)
set(_deps_found TRUE)
set(_deps_link)
foreach(_ffmpeg_dep IN LISTS ARGN)
if(TARGET "FFMPEG::${_ffmpeg_dep}")
list(APPEND _deps_link "FFMPEG::${_ffmpeg_dep}")
else()
set(_deps_found FALSE)
endif()
endforeach()
if(_deps_found)
if(NOT TARGET "FFMPEG::${component}")
add_library("FFMPEG::${component}" UNKNOWN IMPORTED)
set_target_properties("FFMPEG::${component}" PROPERTIES
IMPORTED_LOCATION "${FFMPEG_${component}_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_${component}_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES "${_deps_link}")
endif()
set(FFMPEG_${component}_FOUND 1 PARENT_SCOPE)
set(FFMPEG_${component}_VERSION "${PC_FFMPEG_${component}_VERSION}" PARENT_SCOPE)
else()
set("FFMPEG_${component}_FOUND" 0 PARENT_SCOPE)
set(what)
if(NOT FFMPEG_${component}_LIBRARY)
set(what "library")
endif()
if(NOT FFMPEG_${component}_INCLUDE_DIR)
if(what)
string(APPEND what " or headers")
else()
set(what "headers")
endif()
endif()
set("FFMPEG_${component}_NOT_FOUND_MESSAGE"
"Could not find the ${what} for ${component}."
PARENT_SCOPE)
endif()
endif()
endfunction()
_ffmpeg_find(avutil libavutil avutil.h)
_ffmpeg_find(swresample libswresample swresample.h
avutil)
_ffmpeg_find(swscale libswscale swscale.h
avutil)
_ffmpeg_find(avcodec libavcodec avcodec.h
avutil)
_ffmpeg_find(avformat libavformat avformat.h
avcodec avutil)
_ffmpeg_find(avfilter libavfilter avfilter.h
avutil)
_ffmpeg_find(avdevice libavdevice avdevice.h
avformat avutil)
_ffmpeg_find(avresample libavresample avresample.h
avutil)
if(TARGET FFMPEG::avutil)
set(FFMPEG_VERSION "${FFMPEG_avutil_VERSION}")
endif()
set(FFMPEG_INCLUDE_DIRS)
set(FFMPEG_LIBRARIES)
set(_ffmpeg_required_vars)
foreach(_ffmpeg_component IN LISTS FFMPEG_FIND_COMPONENTS)
if(TARGET "FFMPEG::${_ffmpeg_component}")
set(FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS
"${FFMPEG_${_ffmpeg_component}_INCLUDE_DIR}")
set(FFMPEG_${_ffmpeg_component}_LIBRARIES
"${FFMPEG_${_ffmpeg_component}_LIBRARY}")
list(APPEND FFMPEG_INCLUDE_DIRS
"${FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS}")
list(APPEND FFMPEG_LIBRARIES
"${FFMPEG_${_ffmpeg_component}_LIBRARIES}")
if(FFMEG_FIND_REQUIRED_${_ffmpeg_component})
list(APPEND _ffmpeg_required_vars
"FFMPEG_${_ffmpeg_required_vars}_INCLUDE_DIRS"
"FFMPEG_${_ffmpeg_required_vars}_LIBRARIES")
endif()
endif()
endforeach()
unset(_ffmpeg_component)
if(FFMPEG_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFMPEG
REQUIRED_VARS
FFMPEG_INCLUDE_DIRS
FFMPEG_LIBRARIES
${_ffmpeg_required_vars}
VERSION_VAR
FFMPEG_VERSION
HANDLE_COMPONENTS)
unset(_ffmpeg_required_vars)

View File

@ -23,7 +23,7 @@ Result Variables
``LIBJWT_FOUND``
System has libjwt
``LIBJWT_INCLUDE_DIR``
``LIBJWT_INCLUDE_DIRS``
The libjwt include directory
``LIBJWT_LIBRARIES``
The libraries needed to use libjwt

View File

@ -80,6 +80,7 @@ target_link_libraries(zm
libbcrypt::bcrypt
RtspServer::RtspServer
martinmoene::span-lite
${ZM_BIN_LIBS}
PRIVATE
zm-core-interface)
@ -102,7 +103,6 @@ target_link_libraries(zmc
zm-core-interface
zm
${ZM_EXTRA_LIBS}
${ZM_BIN_LIBS}
${CMAKE_DL_LIBS})
target_link_libraries(zms
@ -110,7 +110,6 @@ target_link_libraries(zms
zm-core-interface
zm
${ZM_EXTRA_LIBS}
${ZM_BIN_LIBS}
${CMAKE_DL_LIBS})
target_link_libraries(zmu
@ -118,9 +117,7 @@ target_link_libraries(zmu
zm-core-interface
zm
${ZM_EXTRA_LIBS}
${ZM_BIN_LIBS}
${CMAKE_DL_LIBS}
bcrypt)
${CMAKE_DL_LIBS})
# Generate man files for the binaries destined for the bin folder
if(BUILD_MAN)
@ -141,8 +138,6 @@ if(HAVE_RTSP_SERVER)
zm-core-interface
zm
${ZM_EXTRA_LIBS}
${ZM_BIN_LIBS}
${CMAKE_DL_LIBS}
bcrypt)
${CMAKE_DL_LIBS})
install(TARGETS zm_rtsp_server RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()