root/OpenSceneGraph/trunk/CMakeModules/FindFFmpeg.cmake @ 9866

Revision 9866, 4.4 kB (checked in by robert, 5 years ago)

Cleaned up FindFFmpeg.cmake

RevLine 
[9840]1# Locate ffmpeg
[9817]2# This module defines
3# FFMPEG_LIBRARIES
[9863]4# FFMPEG_FOUND, if false, do not try to link to ffmpeg
[9817]5# FFMPEG_INCLUDE_DIR, where to find the headers
6#
7# $FFMPEG_DIR is an environment variable that would
8# correspond to the ./configure --prefix=$FFMPEG_DIR
9#
[9863]10# Created by Robert Osfield.
[9817]11
[9863]12# Macro to find header and lib directories
13# example: FFMPEG_FIND(AVFORMAT avformat avformat.h)
[9864]14
[9863]15MACRO(FFMPEG_FIND varname shortname headername)
16    # First try to find header directly in include directory
17    FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS ${headername}
18        ${FFMPEG_ROOT}/include
19        $ENV{FFMPEG_DIR}/include
20        $ENV{OSGDIR}/include
21        $ENV{OSG_ROOT}/include
22        ~/Library/Frameworks
23        /Library/Frameworks
24        /usr/local/include
25        /usr/include/
26        /sw/include # Fink
27        /opt/local/include # DarwinPorts
28        /opt/csw/include # Blastwave
29        /opt/include
30        /usr/freeware/include
31    )
[9817]32
[9863]33    # If not found, try to find it in a subdirectory. Tanguy's build has
34    # avformat.h in include/libavformat, so this catches that case. If that's
35    # standard, perhaps we can keep just this case.
36    IF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
37        FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername}
38            ${FFMPEG_ROOT}/include
39            $ENV{FFMPEG_DIR}/include
40            $ENV{OSGDIR}/include
41            $ENV{OSG_ROOT}/include
42            ~/Library/Frameworks
43            /Library/Frameworks
44            /usr/local/include
45            /usr/include/
46            /sw/include # Fink
47            /opt/local/include # DarwinPorts
48            /opt/csw/include # Blastwave
49            /opt/include
50            /usr/freeware/include
51        )
52    ENDIF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
[9817]53
[9864]54
55    # If not found, try to find it in a subdirectory. Tanguy's build has
56    # avformat.h in include/libavformat, so this catches that case. If that's
57    # standard, perhaps we can keep just this case.
58    IF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
59        FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS ffmpeg/${headername}
60            ${FFMPEG_ROOT}/include
61            $ENV{FFMPEG_DIR}/include
62            $ENV{OSGDIR}/include
63            $ENV{OSG_ROOT}/include
64            ~/Library/Frameworks
65            /Library/Frameworks
66            /usr/local/include
67            /usr/include/
68            /sw/include # Fink
69            /opt/local/include # DarwinPorts
70            /opt/csw/include # Blastwave
71            /opt/include
72            /usr/freeware/include
73        )
74    ENDIF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
75
[9863]76    FIND_LIBRARY(FFMPEG_${varname}_LIBRARIES
77        NAMES ${shortname}
78        PATHS
79        ${FFMPEG_ROOT}/lib
80        $ENV{FFMPEG_DIR}/lib
81        $ENV{OSGDIR}/lib
82        $ENV{OSG_ROOT}/lib
83        ~/Library/Frameworks
84        /Library/Frameworks
85        /usr/local/lib
86        /usr/local/lib64
87        /usr/lib
88        /usr/lib64
89        /sw/lib
90        /opt/local/lib
91        /opt/csw/lib
92        /opt/lib
93        /usr/freeware/lib64
94    )
[9817]95
[9866]96    IF   (FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
[9863]97        SET(FFMPEG_${varname}_FOUND 1)
[9866]98    ENDIF(FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
[9817]99
[9863]100ENDMACRO(FFMPEG_FIND)
[9817]101
[9863]102SET(FFMPEG_ROOT "$ENV{FFMPEG_DIR}" CACHE PATH "Location of FFMPEG")
103
104FFMPEG_FIND(LIBAVFORMAT avformat avformat.h)
105FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h)
106FFMPEG_FIND(LIBAVCODEC  avcodec  avcodec.h)
107FFMPEG_FIND(LIBAVUTIL   avutil   avutil.h)
108FFMPEG_FIND(LIBSWSCALE  swscale  swscale.h)  # not sure about the header to look for here.
109
[9817]110SET(FFMPEG_FOUND "NO")
[9863]111# Note we don't check FFMPEG_LIBSWSCALE_FOUND here, it's optional.
[9817]112IF   (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND)
[9863]113
[9817]114    SET(FFMPEG_FOUND "YES")
115
116    SET(FFMPEG_INCLUDE_DIRS ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})
[9840]117
118    SET(FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBAVFORMAT_LIBRARY_DIRS})
119
[9863]120    # Note we don't add FFMPEG_LIBSWSCALE_LIBRARIES here, it will be added if found later.
[9817]121    SET(FFMPEG_LIBRARIES
122        ${FFMPEG_LIBAVFORMAT_LIBRARIES}
123        ${FFMPEG_LIBAVDEVICE_LIBRARIES}
124        ${FFMPEG_LIBAVCODEC_LIBRARIES}
125        ${FFMPEG_LIBAVUTIL_LIBRARIES})
126
[9863]127ELSE (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND)
[9817]128
[9866]129#    MESSAGE(STATUS "Could not find FFMPEG")
[9863]130
131ENDIF(FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND)
Note: See TracBrowser for help on using the browser.