-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFindffmpeg.cmake
183 lines (139 loc) · 5.81 KB
/
Findffmpeg.cmake
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# TODO: version checking
cmake_minimum_required (VERSION 3.25 FATAL_ERROR)
include (FeatureSummary)
set_package_properties (ffmpeg PROPERTIES
URL "https://www.ffmpeg.org/"
DESCRIPTION "FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata.")
set (${CMAKE_FIND_PACKAGE_NAME}_FOUND TRUE)
set (ffmpeg_valid_components
ffmpeg ffplay ffprobe
libavcodec libavdevice libavfilter libavformat libavutil libswresample libswscale
)
# check for invalid component names
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
unset (ffmpeg_actual_component_list)
list (REMOVE_DUPLICATES ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
foreach(ffmpeg_requested_component IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
string (TOLOWER "${ffmpeg_requested_component}" ffmpeg_requested_component)
if("${ffmpeg_requested_component}" IN_LIST ffmpeg_valid_components)
list (APPEND ffmpeg_actual_component_list "${ffmpeg_requested_component}")
else()
if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message (AUTHOR_WARNING "${CMAKE_FIND_PACKAGE_NAME}: Invalid component requested: '${ffmpeg_requested_component}'")
endif()
set (${CMAKE_FIND_PACKAGE_NAME}_${ffmpeg_requested_component}_FOUND FALSE)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${ffmpeg_requested_component})
list (APPEND ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "Invalid component requested: '${ffmpeg_requested_component}'")
set (${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
set (${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${ffmpeg_actual_component_list})
else()
set (${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${ffmpeg_valid_components})
endif()
# component dependencies
set (ffmpeg_libavcodec_deps libavutil libswresample)
set (ffmpeg_libavdevice_deps libavfilter libswscale libavformat libavcodec libswresample libavutil)
set (ffmpeg_libavfilter_deps libswscale libavformat libavcodec libswresample libavutil)
set (ffmpeg_libavformat_deps libavcodec libswresample libavutil)
set (ffmpeg_libswresample_deps libavutil)
set (ffmpeg_libswscale_deps libavutil)
foreach(ffmpeg_component IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
foreach(ffmpeg_comp_dep IN LISTS ffmpeg_${ffmpeg_component}_deps)
if(NOT "${ffmpeg_comp_dep}" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
list (APPEND ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS "${ffmpeg_comp_dep}")
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${ffmpeg_component})
set (${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${ffmpeg_comp_dep} TRUE)
endif()
endif()
endforeach()
endforeach()
# search for each component, create imported targets
unset (ffmpeg_found_components)
macro(__ffmpeg_find_program name)
if(${name} IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
string (TOUPPER "${name}" ffmpeg_program_var)
set (ffmpeg_program_var "FFMPEG_${ffmpeg_program_var}_PROGRAM")
find_program (${ffmpeg_program_var} ${name} DOC "${name} command line tool")
if(${ffmpeg_program_var})
add_executable (ffmpeg::${name} IMPORTED)
set_target_properties (ffmpeg::${name} PROPERTIES IMPORTED_LOCATION "${${ffmpeg_program_var}}")
set (${CMAKE_FIND_PACKAGE_NAME}_${name}_FOUND TRUE)
list (APPEND ffmpeg_found_components ${name})
else()
set (${CMAKE_FIND_PACKAGE_NAME}_${name}_FOUND FALSE)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${name})
list (APPEND ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${name} not found")
set (${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
endif()
endif()
endif()
endmacro()
__ffmpeg_find_program (ffmpeg)
__ffmpeg_find_program (ffplay)
__ffmpeg_find_program (ffprobe)
function(__ffmpeg_find_library_internal name)
if(TARGET ffmpeg::${name})
return()
endif()
foreach(dep_lib IN LISTS ffmpeg_${name}_deps)
__ffmpeg_find_library ("${dep_lib}")
if(NOT TARGET ffmpeg::${dep_lib})
return()
endif()
endforeach()
string (TOUPPER "${name}" upper_name)
set (lib_var "FFMPEG_${upper_name}_LIBRARY")
set (inc_var "FFMPEG_${upper_name}_INCLUDES")
find_library (${lib_var} ${name} DOC "${name} library")
string (SUBSTRING "${name}" 3 -1 header_name)
find_file (${inc_var} "${header_name}.h"
PATH_SUFFIXES ${name}
DOC "${name} include directory")
if(NOT (${lib_var} AND ${inc_var}))
return()
endif()
add_library (ffmpeg::${name} UNKNOWN IMPORTED)
set_target_properties (ffmpeg::${name} PROPERTIES
IMPORTED_LOCATION "${${lib_var}}"
INTERFACE_INCLUDE_DIRECTORIES "${${inc_var}}")
foreach(dep_lib IN LISTS ffmpeg_${name}_deps)
target_link_libraries (ffmpeg::${name} INTERFACE ffmpeg::${dep_lib})
endforeach()
endfunction()
macro(__ffmpeg_find_library name)
if(${name} IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
__ffmpeg_find_library_internal ("${name}")
if(TARGET ffmpeg::${name})
set (${CMAKE_FIND_PACKAGE_NAME}_${name}_FOUND TRUE)
list (APPEND ffmpeg_found_components ${name})
else()
set (${CMAKE_FIND_PACKAGE_NAME}_${name}_FOUND FALSE)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${name})
list (APPEND ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${name} not found")
set (${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
endif()
endif()
endif()
endmacro()
__ffmpeg_find_library (libavcodec)
__ffmpeg_find_library (libavdevice)
__ffmpeg_find_library (libavfilter)
__ffmpeg_find_library (libavformat)
__ffmpeg_find_library (libavutil)
__ffmpeg_find_library (libswresample)
__ffmpeg_find_library (libswscale)
#
include (FindPackageMessage)
if(${CMAKE_FIND_PACKAGE_NAME}_FOUND)
list (JOIN ffmpeg_found_components " " ffmpeg_comp_display_list)
set (ffmpeg_pkg_msg "Found ${CMAKE_FIND_PACKAGE_NAME} (components ${ffmpeg_comp_display_list})")
else()
set (ffmpeg_pkg_msg "${CMAKE_FIND_PACKAGE_NAME} - not found")
endif()
find_package_message (
"${CMAKE_FIND_PACKAGE_NAME}"
"${ffmpeg_pkg_msg}"
"${ffmpeg_found_components}"
)