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

Revision 10414, 5.1 kB (checked in by robert, 5 years ago)

Fixed warnings and refactored FindFFmpeg.cmake and ffmpeg plugin CMakeLists.txt scripts to better handle different instation combinations

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
[9948]12
13#In ffmpeg code, old version use "#include <header.h>" and newer use "#include <libname/header.h>"
14#In OSG ffmpeg plugin, we use "#include <header.h>" for compatibility with old version of ffmpeg
15
16#We have to search the path which contain the header.h (usefull for old version)
17#and search the path which contain the libname/header.h (usefull for new version)
18
19#Then we need to include ${FFMPEG_libname_INCLUDE_DIRS} (in old version case, use by ffmpeg header and osg plugin code)
20#                                                       (in new version case, use by ffmpeg header)
21#and ${FFMPEG_libname_INCLUDE_DIRS/libname}             (in new version case, use by osg plugin code)
22
23
[9863]24# Macro to find header and lib directories
25# example: FFMPEG_FIND(AVFORMAT avformat avformat.h)
26MACRO(FFMPEG_FIND varname shortname headername)
[9948]27    # old version of ffmpeg put header in $prefix/include/[ffmpeg]
28    # so try to find header in include directory
[10414]29
30    FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername}
[9948]31        PATHS
[10414]32        ${FFMPEG_ROOT}/include
33        $ENV{FFMPEG_DIR}/include
34        ~/Library/Frameworks
35        /Library/Frameworks
36        /usr/local/include
37        /usr/include
38        /sw/include # Fink
39        /opt/local/include # DarwinPorts
40        /opt/csw/include # Blastwave
41        /opt/include
42        /usr/freeware/include
[10395]43        PATH_SUFFIXES ffmpeg
44        DOC "Location of FFMPEG Headers"
45    )
46
47    FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS ${headername}
48        PATHS
[9863]49        ${FFMPEG_ROOT}/include
50        $ENV{FFMPEG_DIR}/include
51        ~/Library/Frameworks
52        /Library/Frameworks
53        /usr/local/include
[9948]54        /usr/include
[9863]55        /sw/include # Fink
56        /opt/local/include # DarwinPorts
57        /opt/csw/include # Blastwave
58        /opt/include
59        /usr/freeware/include
[9948]60        PATH_SUFFIXES ffmpeg
61        DOC "Location of FFMPEG Headers"
[9863]62    )
[9817]63
[9863]64    FIND_LIBRARY(FFMPEG_${varname}_LIBRARIES
65        NAMES ${shortname}
66        PATHS
67        ${FFMPEG_ROOT}/lib
68        $ENV{FFMPEG_DIR}/lib
69        ~/Library/Frameworks
70        /Library/Frameworks
71        /usr/local/lib
72        /usr/local/lib64
73        /usr/lib
74        /usr/lib64
75        /sw/lib
76        /opt/local/lib
77        /opt/csw/lib
78        /opt/lib
79        /usr/freeware/lib64
[9948]80        DOC "Location of FFMPEG Libraries"
[9863]81    )
[9817]82
[9948]83    IF (FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
[9863]84        SET(FFMPEG_${varname}_FOUND 1)
[9866]85    ENDIF(FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
[9817]86
[9863]87ENDMACRO(FFMPEG_FIND)
[9817]88
[9863]89SET(FFMPEG_ROOT "$ENV{FFMPEG_DIR}" CACHE PATH "Location of FFMPEG")
90
[10391]91# find stdint.h
[10395]92IF(WIN32)
[10391]93
[10395]94    FIND_PATH(FFMPEG_STDINT_INCLUDE_DIR stdint.h
95        PATHS
96        ${FFMPEG_ROOT}/include
97        $ENV{FFMPEG_DIR}/include
98        ~/Library/Frameworks
99        /Library/Frameworks
100        /usr/local/include
101        /usr/include
102        /sw/include # Fink
103        /opt/local/include # DarwinPorts
104        /opt/csw/include # Blastwave
105        /opt/include
106        /usr/freeware/include
107        PATH_SUFFIXES ffmpeg
108        DOC "Location of FFMPEG stdint.h Header"
109    )
110
111    IF (FFMPEG_STDINT_INCLUDE_DIR)
112        SET(STDINT_OK TRUE)
113    ENDIF()
114
115ELSE()
116
[10398]117    SET(STDINT_OK TRUE)
[10395]118
119ENDIF()
120
[9863]121FFMPEG_FIND(LIBAVFORMAT avformat avformat.h)
122FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h)
123FFMPEG_FIND(LIBAVCODEC  avcodec  avcodec.h)
124FFMPEG_FIND(LIBAVUTIL   avutil   avutil.h)
125FFMPEG_FIND(LIBSWSCALE  swscale  swscale.h)  # not sure about the header to look for here.
126
[9817]127SET(FFMPEG_FOUND "NO")
[9863]128# Note we don't check FFMPEG_LIBSWSCALE_FOUND here, it's optional.
[10395]129IF   (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND AND STDINT_OK)
[9863]130
[9817]131    SET(FFMPEG_FOUND "YES")
132
133    SET(FFMPEG_INCLUDE_DIRS ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})
[9840]134
[10414]135    SET(FFMPEG_INCLUDE_DIRS
136        ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/libavformat
137        ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/libavdevice
138        ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS} ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/libavcodec
139        ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS} ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/libavutil
140    )
141
142    IF (${FFMPEG_STDINT_INCLUDE_DIR})
143        SET(FFMPEG_INCLUDE_DIRS
144            $PFFMPEG_INCLUDE_DIRS}
145            ${FFMPEG_STDINT_INCLUDE_DIR}/libavformat
146            ${FFMPEG_STDINT_INCLUDE_DIR}/libavdevice
147            ${FFMPEG_STDINT_INCLUDE_DIR}/libavcodec
148            ${FFMPEG_STDINT_INCLUDE_DIR}/libavutil
149        )
150    ENDIF()
151
152
[9840]153    SET(FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBAVFORMAT_LIBRARY_DIRS})
154
[9863]155    # Note we don't add FFMPEG_LIBSWSCALE_LIBRARIES here, it will be added if found later.
[9817]156    SET(FFMPEG_LIBRARIES
157        ${FFMPEG_LIBAVFORMAT_LIBRARIES}
158        ${FFMPEG_LIBAVDEVICE_LIBRARIES}
159        ${FFMPEG_LIBAVCODEC_LIBRARIES}
160        ${FFMPEG_LIBAVUTIL_LIBRARIES})
161
[10391]162ELSE ()
[9817]163
[9866]164#    MESSAGE(STATUS "Could not find FFMPEG")
[9863]165
[10391]166ENDIF()
Note: See TracBrowser for help on using the browser.