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