summaryrefslogtreecommitdiff
path: root/cmake/Findffmpeg.cmake
blob: eca94a3d60c82d3c588773a0d2c737a40e06e1f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# A Simple FFMPEG Finder.
# (c) Tuomas Virtanen 2016 (Licensed under MIT license)
# Usage:
# find_package(ffmpeg COMPONENTS avcodec avutil ...)
#
# Declares:
#  * FFMPEG_FOUND
#  * FFMPEG_INCLUDE_DIRS
#  * FFMPEG_LIBRARIES
#
# Also declares ${component}_FOUND for each component, eg. avcodec_FOUND etc.
#

set(FFMPEG_SEARCH_PATHS
    /usr/local
    /usr
    /opt
)

set(FFMPEG_COMPONENTS 
    avcodec
    avformat
    avdevice
    avfilter
    avresample
    avutil
    swresample
    swscale
)

set(FFMPEG_INCLUDE_DIRS)
set(FFMPEG_LIBRARIES)
set(FFMPEG_FOUND TRUE)

# Walk through all components declared above, and try to find the ones that have been asked
foreach(comp ${FFMPEG_COMPONENTS})
    list(FIND ffmpeg_FIND_COMPONENTS ${comp} _index)
    if(${_index} GREATER -1)
        # Component requested, try to look up the library and header for it.
        find_path(${comp}_INCLUDE_DIR lib${comp}/${comp}.h 
            HINTS
            PATH_SUFFIXES include
            PATHS ${FFMPEG_SEARCH_PATHS}
        )
        find_library(${comp}_LIBRARY ${comp}
            HINTS
            PATH_SUFFIXES lib
            PATHS ${FFMPEG_SEARCH_PATHS}
        )

        # If library and header was found, set proper variables
        # Otherwise print out a warning!
        if(${comp}_LIBRARY AND ${comp}_INCLUDE_DIR)
            set(${comp}_FOUND TRUE)
            list(APPEND FFMPEG_INCLUDE_DIRS ${${comp}_INCLUDE_DIR})
            list(APPEND FFMPEG_LIBRARIES ${${comp}_LIBRARY})
        else()
            set(FFMPEG_FOUND FALSE)
            set(${comp}_FOUND FALSE)
            MESSAGE(WARNING "Could not find component: ${comp}")
        endif()

        # Mark the temporary variables as hidden in the ui
        mark_as_advanced(${${comp}_LIBRARY} ${${comp}_INCLUDE_DIR})
    endif()
endforeach()

if(FFMPEG_FOUND)
    MESSAGE(STATUS "Found FFMPEG: ${FFMPEG_LIBRARIES}")
else()
    MESSAGE(WARNING "Could not find FFMPEG")
endif()

mark_as_advanced(FFMPEG_COMPONENTS FFMPEG_SEARCH_PATHS)