Release version 0.1.1
[libam7xxx.git] / cmake_modules / FindFFmpeg.cmake
1 # Locate ffmpeg
2 # This module defines
3 # FFMPEG_LIBRARIES
4 # FFMPEG_FOUND, if false, do not try to link to ffmpeg
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 #
10 # Created by Robert Osfield.
11
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
24 # Macro to find header and lib directories
25 # example: FFMPEG_FIND(AVFORMAT avformat avformat.h)
26 MACRO(FFMPEG_FIND varname shortname headername)
27     # old version of ffmpeg put header in $prefix/include/[ffmpeg]
28     # so try to find header in include directory
29     FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS ${headername}
30         PATHS
31         ${FFMPEG_ROOT}/include
32         $ENV{FFMPEG_DIR}/include
33         $ENV{OSGDIR}/include
34         $ENV{OSG_ROOT}/include
35         ~/Library/Frameworks
36         /Library/Frameworks
37         /usr/local/include
38         /usr/include
39         /sw/include # Fink
40         /opt/local/include # DarwinPorts
41         /opt/csw/include # Blastwave
42         /opt/include
43         /usr/freeware/include
44         PATH_SUFFIXES ffmpeg
45         DOC "Location of FFMPEG Headers"
46     )
47
48     # newer version of ffmpeg put header in $prefix/include/[ffmpeg/]lib${shortname}
49     # so try to find lib${shortname}/header in include directory
50     IF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
51         FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername}
52             ${FFMPEG_ROOT}/include
53             $ENV{FFMPEG_DIR}/include
54             $ENV{OSGDIR}/include
55             $ENV{OSG_ROOT}/include
56             ~/Library/Frameworks
57             /Library/Frameworks
58             /usr/local/include
59             /usr/include/
60             /sw/include # Fink
61             /opt/local/include # DarwinPorts
62             /opt/csw/include # Blastwave
63             /opt/include
64             /usr/freeware/include
65             PATH_SUFFIXES ffmpeg
66             DOC "Location of FFMPEG Headers"
67         )
68     ENDIF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
69
70     FIND_LIBRARY(FFMPEG_${varname}_LIBRARIES
71         NAMES ${shortname}
72         PATHS
73         ${FFMPEG_ROOT}/lib
74         $ENV{FFMPEG_DIR}/lib
75         $ENV{OSGDIR}/lib
76         $ENV{OSG_ROOT}/lib
77         ~/Library/Frameworks
78         /Library/Frameworks
79         /usr/local/lib
80         /usr/local/lib64
81         /usr/lib
82         /usr/lib64
83         /sw/lib
84         /opt/local/lib
85         /opt/csw/lib
86         /opt/lib
87         /usr/freeware/lib64
88         DOC "Location of FFMPEG Libraries"
89     )
90
91     IF (FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
92         SET(FFMPEG_${varname}_FOUND 1)
93     ENDIF(FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS)
94
95 ENDMACRO(FFMPEG_FIND)
96
97 SET(FFMPEG_ROOT "$ENV{FFMPEG_DIR}" CACHE PATH "Location of FFMPEG")
98
99 FFMPEG_FIND(LIBAVFORMAT avformat avformat.h)
100 FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h)
101 FFMPEG_FIND(LIBAVCODEC  avcodec  avcodec.h)
102 FFMPEG_FIND(LIBAVUTIL   avutil   avutil.h)
103 FFMPEG_FIND(LIBSWSCALE  swscale  swscale.h)  # not sure about the header to look for here.
104
105 SET(FFMPEG_FOUND "NO")
106 # Note we don't check FFMPEG_LIBSWSCALE_FOUND here, it's optional.
107 IF   (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND)
108
109     SET(FFMPEG_FOUND "YES")
110
111     SET(FFMPEG_INCLUDE_DIRS ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})
112
113     SET(FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBAVFORMAT_LIBRARY_DIRS})
114
115     # Note we don't add FFMPEG_LIBSWSCALE_LIBRARIES here, it will be added if found later.
116     SET(FFMPEG_LIBRARIES
117         ${FFMPEG_LIBAVFORMAT_LIBRARIES}
118         ${FFMPEG_LIBAVDEVICE_LIBRARIES}
119         ${FFMPEG_LIBAVCODEC_LIBRARIES}
120         ${FFMPEG_LIBAVUTIL_LIBRARIES})
121
122 ELSE (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND)
123
124 #    MESSAGE(STATUS "Could not find FFMPEG")
125
126 ENDIF(FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBAVUTIL_FOUND)