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