PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 1ms

/strigi-0.7.7/libstreamanalyzer/cmake/FindFFmpeg.cmake

#
CMake | 148 lines | 71 code | 22 blank | 55 comment | 9 complexity | 93ff3d9f38b9e022e4f806adaca54e0a MD5 | raw file
Possible License(s): LGPL-2.0
  1# vim: ts=2 sw=2
  2# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
  3#
  4# Once done this will define
  5#  FFMPEG_FOUND         - System has the all required components.
  6#  FFMPEG_INCLUDE_DIRS  - Include directory necessary for using the required components headers.
  7#  FFMPEG_LIBRARIES     - Link these to use the required ffmpeg components.
  8#  FFMPEG_DEFINITIONS   - Compiler switches required for using the required ffmpeg components.
  9#
 10# For each of the components it will additionaly set.
 11#   - AVCODEC
 12#   - AVDEVICE
 13#   - AVFORMAT
 14#   - AVUTIL
 15#   - POSTPROCESS
 16#   - SWSCALE
 17# the following variables will be defined
 18#  <component>_FOUND        - System has <component>
 19#  <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
 20#  <component>_LIBRARIES    - Link these to use <component>
 21#  <component>_DEFINITIONS  - Compiler switches required for using <component>
 22#  <component>_VERSION      - The components version
 23#
 24# Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
 25# Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
 26# Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
 27#
 28# Redistribution and use is allowed according to the terms of the BSD license.
 29# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 30
 31include(FindPackageHandleStandardArgs)
 32
 33# The default components were taken from a survey over other FindFFMPEG.cmake files
 34if (NOT FFmpeg_FIND_COMPONENTS)
 35  set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
 36endif ()
 37
 38#
 39### Macro: set_component_found
 40#
 41# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
 42#
 43macro(set_component_found _component )
 44  if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
 45    # message(STATUS "  - ${_component} found.")
 46    set(${_component}_FOUND TRUE)
 47  else ()
 48    # message(STATUS "  - ${_component} not found.")
 49  endif ()
 50endmacro()
 51
 52#
 53### Macro: find_component
 54#
 55# Checks for the given component by invoking pkgconfig and then looking up the libraries and
 56# include directories.
 57#
 58macro(find_component _component _pkgconfig _library _header)
 59
 60  if (NOT WIN32)
 61     # use pkg-config to get the directories and then use these values
 62     # in the FIND_PATH() and FIND_LIBRARY() calls
 63     find_package(PkgConfig)
 64     if (PKG_CONFIG_FOUND)
 65       pkg_check_modules(PC_${_component} ${_pkgconfig})
 66     endif ()
 67  endif (NOT WIN32)
 68
 69  find_path(${_component}_INCLUDE_DIRS ${_header}
 70    HINTS
 71      ${PC_LIB${_component}_INCLUDEDIR}
 72      ${PC_LIB${_component}_INCLUDE_DIRS}
 73    PATH_SUFFIXES
 74      ffmpeg
 75  )
 76
 77  find_library(${_component}_LIBRARIES NAMES ${_library}
 78      HINTS
 79      ${PC_LIB${_component}_LIBDIR}
 80      ${PC_LIB${_component}_LIBRARY_DIRS}
 81  )
 82
 83  set(${_component}_DEFINITIONS  ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
 84  set(${_component}_VERSION      ${PC_${_component}_VERSION}      CACHE STRING "The ${_component} version number.")
 85
 86  set_component_found(${_component})
 87
 88  mark_as_advanced(
 89    ${_component}_INCLUDE_DIRS
 90    ${_component}_LIBRARIES
 91    ${_component}_DEFINITIONS
 92    ${_component}_VERSION)
 93
 94endmacro()
 95
 96
 97# Check for cached results. If there are skip the costly part.
 98if (NOT FFMPEG_LIBRARIES)
 99
100  # Check for all possible component.
101  find_component(AVCODEC  libavcodec  avcodec  libavcodec/avcodec.h)
102  find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
103  find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
104  find_component(AVUTIL   libavutil   avutil   libavutil/avutil.h)
105  find_component(SWSCALE  libswscale  swscale  libswscale/swscale.h)
106  find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
107
108  # Check if the required components were found and add their stuff to the FFMPEG_* vars.
109  foreach (_component ${FFmpeg_FIND_COMPONENTS})
110    if (${_component}_FOUND)
111      # message(STATUS "Required component ${_component} present.")
112      set(FFMPEG_LIBRARIES   ${FFMPEG_LIBRARIES}   ${${_component}_LIBRARIES})
113      set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
114      list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
115    else ()
116      # message(STATUS "Required component ${_component} missing.")
117    endif ()
118  endforeach ()
119
120  # Build the include path with duplicates removed.
121  if (FFMPEG_INCLUDE_DIRS)
122    list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
123  endif ()
124
125  # cache the vars.
126  set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
127  set(FFMPEG_LIBRARIES    ${FFMPEG_LIBRARIES}    CACHE STRING "The FFmpeg libraries." FORCE)
128  set(FFMPEG_DEFINITIONS  ${FFMPEG_DEFINITIONS}  CACHE STRING "The FFmpeg cflags." FORCE)
129
130  mark_as_advanced(FFMPEG_INCLUDE_DIRS
131                   FFMPEG_LIBRARIES
132                   FFMPEG_DEFINITIONS)
133
134endif ()
135
136# Now set the noncached _FOUND vars for the components.
137foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
138  set_component_found(${_component})
139endforeach ()
140
141# Compile the list of required vars
142set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
143foreach (_component ${FFmpeg_FIND_COMPONENTS})
144  list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
145endforeach ()
146
147# Give a nice error message if some of the required vars are missing.
148find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})