]> git.sesse.net Git - vlc/blob - extras/buildsystem/cmake/include/FindFFmpeg.cmake
cmake: Source code clean up, fix how CFLAGS are saved, and compensate for latest...
[vlc] / extras / buildsystem / cmake / include / FindFFmpeg.cmake
1 # - Find library containing FFmpeg()
2 # The following variables are set if FFmpeg is found. If FFmpeg is not
3 # found, FFmpeg_FOUND is set to false.
4 #  FFmpeg_FOUND     - System has FFmpeg.
5 #  FFmpeg_LIBRARIES - Link these to use FFmpeg.
6 #  FFmpeg_CFLAGS - Link these to use FFmpeg.
7
8 if (NOT FFmpeg_SEARCHED)
9     include(CheckLibraryExists)
10
11     set(FFmpeg_SEARCHED TRUE CACHE INTERNAL "")
12     set(FFmpeg_FOUND FALSE CACHE INTERNAL "")
13
14     pkg_check_modules(FFmpeg libffmpeg)
15
16     if (NOT FFmpeg_FOUND)
17         set(FFmpeg_LIBRARIES "")
18         foreach (library ffmpeg avcodec avformat avutil postproc swscale)
19             find_library( ${library}_LIBRARY ${library} )
20             if (${library}_LIBRARY)
21                 pkg_check_modules(${library}_LIBRARY lib${library})
22                 set(FFmpeg_LIBRARIES "${library};${FFmpeg_LIBRARIES}")
23
24                 if (${library}_LIBRARY_CFLAGS)
25                     set(FFmpeg_CFLAGS ${FFmpeg_CFLAGS} ${${library}_LIBRARY_CFLAGS})
26                 endif (${library}_LIBRARY_CFLAGS)
27                 set(FFmpeg_FOUND TRUE CACHE INTERNAL "")
28             endif (${library}_LIBRARY)
29         endforeach (library)
30         foreach (library a52 faac lame z png mp3lame twolame)
31             find_library( ${library}_LIBRARY ${library} )
32             if (${library}_LIBRARY)
33                 pkg_check_modules(${library}_LIBRARY lib${library})
34                 set(FFmpeg_LIBRARIES "${library};${FFmpeg_LIBRARIES}")
35
36                 if (${library}_LIBRARY_CFLAGS)
37                     set(FFmpeg_CFLAGS ${FFmpeg_CFLAGS} ${${library}_LIBRARY_CFLAGS})
38                 endif (${library}_LIBRARY_CFLAGS)
39             endif (${library}_LIBRARY)
40         endforeach (library)
41         set(FFmpeg_LIBRARIES "${FFmpeg_LIBRARIES}" CACHE INTERNAL STRING)
42     endif (NOT FFmpeg_FOUND)
43
44     if (FFmpeg_FOUND)
45         if (NOT FFmpeg_FIND_QUIETLY)
46             message(STATUS "Found FFmpeg in: ${FFmpeg_LIBRARIES}")
47         endif (NOT FFmpeg_FIND_QUIETLY)
48     else (FFmpeg_FOUND)
49         if (FFmpeg_FIND_REQUIRED)
50             message(FATAL_ERROR "Could not find the library containing FFmpeg")
51         endif (FFmpeg_FIND_REQUIRED)
52     endif (FFmpeg_FOUND)
53
54     mark_as_advanced(FFmpeg_LIBRARIES)
55 endif(NOT FFmpeg_SEARCHED)