Warning, /multimedia/amarok/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 in source and binary forms, with or without
0029 # modification, are permitted provided that the following conditions
0030 # are met:
0031 # 1. Redistributions of source code must retain the above copyright
0032 #    notice, this list of conditions and the following disclaimer.
0033 # 2. Redistributions in binary form must reproduce the above copyright
0034 #    notice, this list of conditions and the following disclaimer in the
0035 #    documentation and/or other materials provided with the distribution.
0036 # 3. Neither the name of the University nor the names of its contributors
0037 #    may be used to endorse or promote products derived from this software
0038 #    without specific prior written permission.
0039 #
0040 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0041 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0042 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0043 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0044 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0045 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0046 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0047 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0048 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0049 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0050 # SUCH DAMAGE.
0051 
0052 include(FindPackageHandleStandardArgs)
0053 
0054 # The default components were taken from a survey over other FindFFMPEG.cmake files
0055 if (NOT FFmpeg_FIND_COMPONENTS)
0056   set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
0057 endif ()
0058 
0059 #
0060 ### Macro: set_component_found
0061 #
0062 # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
0063 #
0064 macro(set_component_found _component )
0065   if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
0066     # message(STATUS "  - ${_component} found.")
0067     set(${_component}_FOUND TRUE)
0068   else ()
0069     # message(STATUS "  - ${_component} not found.")
0070   endif ()
0071 endmacro()
0072 
0073 #
0074 ### Macro: find_component
0075 #
0076 # Checks for the given component by invoking pkgconfig and then looking up the libraries and
0077 # include directories.
0078 #
0079 macro(find_component _component _pkgconfig _library _header)
0080 
0081   if (NOT WIN32)
0082      # use pkg-config to get the directories and then use these values
0083      # in the FIND_PATH() and FIND_LIBRARY() calls
0084      find_package(PkgConfig)
0085      if (PKG_CONFIG_FOUND)
0086        pkg_check_modules(PC_${_component} ${_pkgconfig})
0087      endif ()
0088   endif (NOT WIN32)
0089 
0090   find_path(${_component}_INCLUDE_DIRS ${_header}
0091     HINTS
0092       ${PC_LIB${_component}_INCLUDEDIR}
0093       ${PC_LIB${_component}_INCLUDE_DIRS}
0094     PATH_SUFFIXES
0095       ffmpeg
0096   )
0097 
0098   find_library(${_component}_LIBRARIES NAMES ${_library}
0099       HINTS
0100       ${PC_LIB${_component}_LIBDIR}
0101       ${PC_LIB${_component}_LIBRARY_DIRS}
0102   )
0103 
0104   set(${_component}_DEFINITIONS  ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
0105   set(${_component}_VERSION      ${PC_${_component}_VERSION}      CACHE STRING "The ${_component} version number.")
0106 
0107   set_component_found(${_component})
0108 
0109   mark_as_advanced(
0110     ${_component}_INCLUDE_DIRS
0111     ${_component}_LIBRARIES
0112     ${_component}_DEFINITIONS
0113     ${_component}_VERSION)
0114 
0115 endmacro()
0116 
0117 
0118 # Check for cached results. If there are skip the costly part.
0119 if (NOT FFMPEG_LIBRARIES)
0120 
0121   # Check for all possible component.
0122   find_component(AVCODEC  libavcodec  avcodec  libavcodec/avcodec.h)
0123   find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
0124   find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
0125   find_component(AVUTIL   libavutil   avutil   libavutil/avutil.h)
0126   find_component(SWSCALE  libswscale  swscale  libswscale/swscale.h)
0127   find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h)
0128 
0129   # Check if the required components were found and add their stuff to the FFMPEG_* vars.
0130   foreach (_component ${FFmpeg_FIND_COMPONENTS})
0131     if (${_component}_FOUND)
0132       # message(STATUS "Required component ${_component} present.")
0133       set(FFMPEG_LIBRARIES   ${FFMPEG_LIBRARIES}   ${${_component}_LIBRARIES})
0134       set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
0135       list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
0136     else ()
0137       # message(STATUS "Required component ${_component} missing.")
0138     endif ()
0139   endforeach ()
0140 
0141   # Build the include path with duplicates removed.
0142   if (FFMPEG_INCLUDE_DIRS)
0143     list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
0144   endif ()
0145 
0146   # cache the vars.
0147   set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
0148   set(FFMPEG_LIBRARIES    ${FFMPEG_LIBRARIES}    CACHE STRING "The FFmpeg libraries." FORCE)
0149   set(FFMPEG_DEFINITIONS  ${FFMPEG_DEFINITIONS}  CACHE STRING "The FFmpeg cflags." FORCE)
0150 
0151   mark_as_advanced(FFMPEG_INCLUDE_DIRS
0152                    FFMPEG_LIBRARIES
0153                    FFMPEG_DEFINITIONS)
0154 
0155 endif ()
0156 
0157 # Now set the noncached _FOUND vars for the components.
0158 foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
0159   set_component_found(${_component})
0160 endforeach ()
0161 
0162 # Compile the list of required vars
0163 set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
0164 foreach (_component ${FFmpeg_FIND_COMPONENTS})
0165   list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
0166 endforeach ()
0167 
0168 # Give a nice error message if some of the required vars are missing.
0169 find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})