FindFFmpeg.cmake: Perform the ffmpeg search only once. (That's probably not the cmake...
[vlc.git] / 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
9 if (NOT FFmpeg_SEARCHED)
10     include(CheckLibraryExists)
11
12     set(FFmpeg_SEARCHED TRUE CACHE INTERNAL "")
13     set(FFmpeg_FOUND FALSE CACHE INTERNAL "")
14
15     pkg_check_modules(FFmpeg libffmpeg)
16
17     if (NOT FFmpeg_FOUND)
18         set(FFmpeg_LIBRARIES "")
19         foreach (library ffmpeg avcodec avformat avutil postproc)
20             find_library( ${library}_LIBRARY ${library} )
21             set( ${library}_LIBRARY_FOUND NOT ${${library}_LIBRARY} )
22             if (${library}_LIBRARY_FOUND)
23               set(FFmpeg_LIBRARIES "${library};${FFmpeg_LIBRARIES}")
24               set(FFmpeg_FOUND TRUE CACHE INTERNAL "")
25             endif (${library}_LIBRARY_FOUND)
26         endforeach (library)
27         foreach (library a52 faac lame z png mp3lame twolame)
28             find_library( ${library}_LIBRARY ${library} )
29             set( ${library}_LIBRARY_FOUND NOT ${${library}_LIBRARY} )
30             if (${library}_LIBRARY_FOUND)
31               set(FFmpeg_LIBRARIES "${library};${FFmpeg_LIBRARIES}")
32             endif (${library}_LIBRARY_FOUND)
33         endforeach (library)
34         set(FFmpeg_LIBRARIES "${FFmpeg_LIBRARIES}" CACHE INTERNAL STRING)
35     endif (NOT FFmpeg_FOUND)
36
37     if (FFmpeg_FOUND)
38       if (NOT FFmpeg_FIND_QUIETLY)
39         message(STATUS "Found FFmpeg in: ${FFmpeg_LIBRARIES}")
40       endif (NOT FFmpeg_FIND_QUIETLY)
41     else (FFmpeg_FOUND)
42       if (FFmpeg_FIND_REQUIRED)
43         message(FATAL_ERROR "Could not find the library containing FFmpeg")
44       endif (FFmpeg_FIND_REQUIRED)
45     endif (FFmpeg_FOUND)
46
47     mark_as_advanced(FFmpeg_LIBRARIES)
48 endif(NOT FFmpeg_SEARCHED)