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