cmake_modules/FindFFMPEG.cmake
branchhedgeroid
changeset 7855 ddcdedd3330b
parent 7816 a25e943dd4b0
child 8279 c03d64969112
equal deleted inserted replaced
6350:41b0a9955c47 7855:ddcdedd3330b
       
     1 # - Try to find ffmpeg libraries (libavcodec, libavformat and libavutil)
       
     2 # Once done this will define
       
     3 #
       
     4 #  FFMPEG_FOUND - system has ffmpeg or libav
       
     5 #  FFMPEG_INCLUDE_DIR - the ffmpeg include directory
       
     6 #  FFMPEG_LIBRARIES - Link these to use ffmpeg
       
     7 #  FFMPEG_LIBAVCODEC
       
     8 #  FFMPEG_LIBAVFORMAT
       
     9 #  FFMPEG_LIBAVUTIL
       
    10 #
       
    11 #  Copyright (c) 2008 Andreas Schneider <mail@cynapses.org>
       
    12 #  Modified for other libraries by Lasse Kärkkäinen <tronic>
       
    13 #  Modified for Hedgewars by Stepik777
       
    14 #
       
    15 #  Redistribution and use is allowed according to the terms of the New
       
    16 #  BSD license.
       
    17 #
       
    18 
       
    19 if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
       
    20   # in cache already
       
    21   set(FFMPEG_FOUND TRUE)
       
    22 else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
       
    23   # use pkg-config to get the directories and then use these values
       
    24   # in the FIND_PATH() and FIND_LIBRARY() calls
       
    25   find_package(PkgConfig)
       
    26   if (PKG_CONFIG_FOUND)
       
    27     pkg_check_modules(_FFMPEG_AVCODEC libavcodec)
       
    28     pkg_check_modules(_FFMPEG_AVFORMAT libavformat)
       
    29     pkg_check_modules(_FFMPEG_AVUTIL libavutil)
       
    30   endif (PKG_CONFIG_FOUND)
       
    31 
       
    32   find_path(FFMPEG_AVCODEC_INCLUDE_DIR
       
    33     NAMES libavcodec/avcodec.h
       
    34     PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS}
       
    35         /usr/include /usr/local/include #system level
       
    36         /opt/local/include #macports
       
    37         /sw/include #fink
       
    38     PATH_SUFFIXES ffmpeg libav
       
    39   )
       
    40 
       
    41   find_library(FFMPEG_LIBAVCODEC
       
    42     NAMES avcodec
       
    43     PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS}
       
    44         /usr/lib /usr/local/lib #system level
       
    45         /opt/local/lib #macports
       
    46         /sw/lib #fink
       
    47   )
       
    48 
       
    49   find_library(FFMPEG_LIBAVFORMAT
       
    50     NAMES avformat
       
    51     PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS}
       
    52         /usr/lib /usr/local/lib #system level
       
    53         /opt/local/lib #macports
       
    54         /sw/lib #fink
       
    55   )
       
    56 
       
    57   find_library(FFMPEG_LIBAVUTIL
       
    58     NAMES avutil
       
    59     PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
       
    60         /usr/lib /usr/local/lib #system level
       
    61         /opt/local/lib #macports
       
    62         /sw/lib #fink
       
    63   )
       
    64 
       
    65   if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT)
       
    66     set(FFMPEG_FOUND TRUE)
       
    67   endif()
       
    68 
       
    69   if (FFMPEG_FOUND)
       
    70     set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
       
    71 
       
    72     set(FFMPEG_LIBRARIES
       
    73       ${FFMPEG_LIBAVCODEC}
       
    74       ${FFMPEG_LIBAVFORMAT}
       
    75       ${FFMPEG_LIBAVUTIL}
       
    76     )
       
    77     if (APPLE)
       
    78       set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} "bz2" "-framework CoreVideo" "-framework VideoDecodeAcceleration")
       
    79     endif(APPLE)
       
    80 
       
    81   endif (FFMPEG_FOUND)
       
    82 
       
    83   if (FFMPEG_FOUND)
       
    84     if (NOT FFMPEG_FIND_QUIETLY)
       
    85       message(STATUS "Found FFMPEG/LibAV: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}")
       
    86     endif (NOT FFMPEG_FIND_QUIETLY)
       
    87   else (FFMPEG_FOUND)
       
    88     if (FFMPEG_FIND_REQUIRED)
       
    89       message(FATAL_ERROR "Could NOT find libavcodec or libavformat or libavutil")
       
    90     endif (FFMPEG_FIND_REQUIRED)
       
    91   endif (FFMPEG_FOUND)
       
    92 
       
    93 endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
       
    94