Warning, /frameworks/kdelibs4support/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 #   - 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 # Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
0025 # Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
0026 # Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
0027 #
0028 # Redistribution and use is allowed according to the terms of the BSD license.
0029 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
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(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})