Warning, /frameworks/kfilemetadata/cmake/FindFFmpeg.cmake is written in an unsupported language. File is not indexed.
0001 # vim: ts=2 sw=2
0002 # - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
0003 #
0004 # Once done this will define
0005 # FFMPEG_FOUND - System has the all required components.
0006 # FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
0007 # FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
0008 # FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
0009 #
0010 # For each of the components
0011 # - AVCODEC
0012 # - AVDEVICE
0013 # - AVFORMAT
0014 # - AVUTIL
0015 # - POSTPROCESS
0016 # - SWSCALE
0017 # the following variables will be defined:
0018 # <component>_FOUND - System has <component>
0019 # <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
0020 # <component>_LIBRARIES - Link these to use <component>
0021 # <component>_DEFINITIONS - Compiler switches required for using <component>
0022 # <component>_VERSION - The components version
0023 #
0024 # As the versions of the various FFmpeg components differ for a given release,
0025 # and CMake supports only one common version for all components, use the
0026 # following to specify required versions for multiple components:
0027 #
0028 # find_package(FFmpeg 57.48 COMPONENTS AVCODEC)
0029 # find_package(FFmpeg 57.40 COMPONENTS AVFORMAT)
0030 # find_package(FFmpeg 55.27 COMPONENTS AVUTIL)
0031 #
0032 # SPDX-FileCopyrightText: 2006 Matthias Kretz <kretz@kde.org>
0033 # SPDX-FileCopyrightText: 2008 Alexander Neundorf <neundorf@kde.org>
0034 # SPDX-FileCopyrightText: 2011 Michael Jansen <kde@michael-jansen.biz>
0035 # SPDX-FileCopyrightText: 2021 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0036 # SPDX-License-Identifier: BSD-3-Clause
0037
0038 include(FindPackageHandleStandardArgs)
0039
0040 if (NOT FFmpeg_FIND_COMPONENTS)
0041 # The default components were taken from a survey over other FindFFMPEG.cmake files
0042 set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
0043 endif ()
0044
0045 list(LENGTH FFmpeg_FIND_COMPONENTS _numComponents)
0046 if ((${_numComponents} GREATER 1) AND DEFINED ${FFmpeg_FIND_VERSION})
0047 message(WARNING "Using a required version in combination with multiple COMPONENTS is not supported")
0048 set(_FFmpeg_REQUIRED_VERSION 0)
0049 elseif (DEFINED FFmpeg_FIND_VERSION)
0050 set(_FFmpeg_REQUIRED_VERSION ${FFmpeg_FIND_VERSION})
0051 else ()
0052 set(_FFmpeg_REQUIRED_VERSION 0)
0053 endif ()
0054 set(_FFmpeg_ALL_COMPONENTS AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
0055
0056 #
0057 ### Macro: set_component_found
0058 #
0059 # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
0060 #
0061 macro(set_component_found _component )
0062 if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
0063 set(${_component}_FOUND TRUE)
0064 set(FFmpeg_${_component}_FOUND TRUE)
0065 endif ()
0066 endmacro()
0067
0068 #
0069 ### Macro: find_component
0070 #
0071 # Checks for the given component by invoking pkgconfig and then looking up the libraries and
0072 # include directories.
0073 #
0074 macro(find_component _component _pkgconfig _library _header)
0075
0076 if (NOT WIN32)
0077 # use pkg-config to get the directories and then use these values
0078 # in the FIND_PATH() and FIND_LIBRARY() calls
0079 find_package(PkgConfig)
0080 if (PKG_CONFIG_FOUND)
0081 pkg_check_modules(PC_${_component} QUIET ${_pkgconfig})
0082 endif ()
0083 endif (NOT WIN32)
0084
0085 find_path(${_component}_INCLUDE_DIRS ${_header}
0086 HINTS
0087 ${PC_LIB${_component}_INCLUDEDIR}
0088 ${PC_LIB${_component}_INCLUDE_DIRS}
0089 PATH_SUFFIXES
0090 ffmpeg
0091 )
0092
0093 find_library(${_component}_LIBRARIES NAMES ${_library}
0094 HINTS
0095 ${PC_LIB${_component}_LIBDIR}
0096 ${PC_LIB${_component}_LIBRARY_DIRS}
0097 )
0098
0099 set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
0100 set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
0101
0102 set_component_found(${_component})
0103
0104 mark_as_advanced(
0105 ${_component}_INCLUDE_DIRS
0106 ${_component}_LIBRARIES
0107 ${_component}_DEFINITIONS
0108 ${_component}_VERSION)
0109
0110 endmacro()
0111
0112 # Check for cached results. If there are skip the costly part.
0113 if (NOT FFMPEG_LIBRARIES)
0114
0115 # Check for all possible component.
0116 find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
0117 find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
0118 find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
0119 find_component(AVUTIL libavutil avutil libavutil/avutil.h)
0120 find_component(SWSCALE libswscale swscale libswscale/swscale.h)
0121 find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h)
0122
0123 # Check if the required components were found and add their stuff to the FFMPEG_* vars.
0124 foreach (_component ${_FFmpeg_ALL_COMPONENTS})
0125 if (${_component}_FOUND)
0126 set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
0127 set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
0128 list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
0129 endif ()
0130 endforeach ()
0131
0132 # Build the include path with duplicates removed.
0133 if (FFMPEG_INCLUDE_DIRS)
0134 list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
0135 endif ()
0136
0137 # cache the vars.
0138 set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
0139 set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
0140 set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
0141
0142 mark_as_advanced(FFMPEG_INCLUDE_DIRS
0143 FFMPEG_LIBRARIES
0144 FFMPEG_DEFINITIONS)
0145
0146 else ()
0147 # Set the noncached _FOUND vars for the components.
0148 foreach (_component ${_FFmpeg_ALL_COMPONENTS})
0149 set_component_found(${_component})
0150 endforeach ()
0151 endif ()
0152
0153 # Compile the list of required vars
0154 unset(_FFmpeg_REQUIRED_VARS)
0155 set(_FFmpeg_FOUND_LIBRARIES "")
0156 foreach (_component ${FFmpeg_FIND_COMPONENTS})
0157 if (${_component}_FOUND)
0158 if (${_component}_VERSION VERSION_LESS _FFmpeg_REQUIRED_VERSION)
0159 message(STATUS "${_component}: ${${_component}_VERSION} < ${_FFmpeg_REQUIRED_VERSION}")
0160 unset(${_component}_FOUND)
0161 endif ()
0162 list(APPEND _FFmpeg_FOUND_LIBRARIES ${${_component}_LIBRARIES})
0163 endif ()
0164 list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS ${_component}_FOUND)
0165 endforeach ()
0166 list(INSERT _FFmpeg_REQUIRED_VARS 0 _FFmpeg_FOUND_LIBRARIES)
0167
0168 # Give a nice error message if some of the required vars are missing.
0169 find_package_handle_standard_args(FFmpeg
0170 REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS}
0171 HANDLE_COMPONENTS)