Warning, /multimedia/ffmpegthumbs/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 it will additionally set.
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 # SPDX-FileCopyrightText: 2006 Matthias Kretz <kretz@kde.org>
0025 # SPDX-FileCopyrightText: 2008 Alexander Neundorf <neundorf@kde.org>
0026 # SPDX-FileCopyrightText: 2011 Michael Jansen <kde@michael-jansen.biz>
0027 #
0028 # SPDX-License-Identifier: BSD-3-Clause
0029
0030 include(FindPackageHandleStandardArgs)
0031
0032 # The default components were taken from a survey over other FindFFMPEG.cmake files
0033 if (NOT FFmpeg_FIND_COMPONENTS)
0034 set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
0035 endif ()
0036
0037 #
0038 ### Macro: set_component_found
0039 #
0040 # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
0041 #
0042 macro(set_component_found _component )
0043 if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
0044 # message(STATUS " - ${_component} found.")
0045 set(${_component}_FOUND TRUE)
0046 else ()
0047 # message(STATUS " - ${_component} not found.")
0048 endif ()
0049 endmacro()
0050
0051 #
0052 ### Macro: find_component
0053 #
0054 # Checks for the given component by invoking pkgconfig and then looking up the libraries and
0055 # include directories.
0056 #
0057 macro(find_component _component _pkgconfig _library _header)
0058
0059 if (NOT WIN32)
0060 # use pkg-config to get the directories and then use these values
0061 # in the FIND_PATH() and FIND_LIBRARY() calls
0062 find_package(PkgConfig)
0063 if (PKG_CONFIG_FOUND)
0064 pkg_check_modules(PC_${_component} ${_pkgconfig})
0065 endif ()
0066 endif (NOT WIN32)
0067
0068 find_path(${_component}_INCLUDE_DIRS ${_header}
0069 HINTS
0070 ${PC_${_component}_INCLUDEDIR}
0071 ${PC_${_component}_INCLUDE_DIRS}
0072 PATH_SUFFIXES
0073 ffmpeg
0074 )
0075
0076 find_library(${_component}_LIBRARIES NAMES ${_library}
0077 HINTS
0078 ${PC_${_component}_LIBDIR}
0079 ${PC_${_component}_LIBRARY_DIRS}
0080 )
0081
0082 set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
0083 set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
0084
0085 set_component_found(${_component})
0086
0087 mark_as_advanced(
0088 ${_component}_INCLUDE_DIRS
0089 ${_component}_LIBRARIES
0090 ${_component}_DEFINITIONS
0091 ${_component}_VERSION)
0092
0093 endmacro()
0094
0095
0096 # Check for cached results. If there are skip the costly part.
0097 if (NOT FFMPEG_LIBRARIES)
0098
0099 # Check for all possible component.
0100 find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
0101 find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
0102 find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
0103 find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
0104 find_component(AVUTIL libavutil avutil libavutil/avutil.h)
0105 find_component(SWSCALE libswscale swscale libswscale/swscale.h)
0106 find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
0107
0108 # Check if the required components were found and add their stuff to the FFMPEG_* vars.
0109 foreach (_component ${FFmpeg_FIND_COMPONENTS})
0110 if (${_component}_FOUND)
0111 # message(STATUS "Required component ${_component} present.")
0112 set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
0113 set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
0114 list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
0115 else ()
0116 # message(STATUS "Required component ${_component} missing.")
0117 endif ()
0118 endforeach ()
0119
0120 # Build the include path with duplicates removed.
0121 if (FFMPEG_INCLUDE_DIRS)
0122 list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
0123 endif ()
0124
0125 # cache the vars.
0126 set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
0127 set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
0128 set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
0129
0130 mark_as_advanced(FFMPEG_INCLUDE_DIRS
0131 FFMPEG_LIBRARIES
0132 FFMPEG_DEFINITIONS)
0133
0134 endif ()
0135
0136 # Now set the noncached _FOUND vars for the components.
0137 foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
0138 set_component_found(${_component})
0139 endforeach ()
0140
0141 # Compile the list of required vars
0142 set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
0143 foreach (_component ${FFmpeg_FIND_COMPONENTS})
0144 list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
0145 endforeach ()
0146
0147 # Give a nice error message if some of the required vars are missing.
0148 find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})