Warning, /multimedia/haruna/cmake/FindFFmpeg.cmake is written in an unsupported language. File is not indexed.

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