68
68
# Sample usage in the Toolchain file:
69
69
# find_program(PKG_CONFIG_EXECUTABLE NAMES ${COMPILER_PREFIX}-pkg-config)
70
70
#
71
- # It also can be pointed via ENV:
71
+ # It also can be pointed via ENV:
72
72
# export PKG_CONFIG=...
73
73
#
74
74
# Env variables of the pkg-config:
@@ -98,7 +98,7 @@ endif ()
98
98
#
99
99
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
100
100
#
101
- macro (set_component_found _component )
101
+ macro (set_component_found _component)
102
102
if (${_component} _LIBRARIES AND ${_component} _INCLUDE_DIRS)
103
103
# message(STATUS " - ${_component} found.")
104
104
set (${_component} _FOUND TRUE )
@@ -123,54 +123,72 @@ macro(find_component _component _pkgconfig _library _header)
123
123
endif ()
124
124
125
125
find_path (${_component} _INCLUDE_DIRS ${_header}
126
- HINTS
127
- ${PC_${_component} _INCLUDEDIR}
128
- ${PC_${_component} _INCLUDE_DIRS}
129
- ${PC_FFMPEG_INCLUDE_DIRS}
130
- PATH_SUFFIXES
131
- ffmpeg
126
+ HINTS
127
+ ${PC_${_component} _INCLUDEDIR}
128
+ ${PC_${_component} _INCLUDE_DIRS}
129
+ ${PC_FFMPEG_INCLUDE_DIRS}
130
+ PATH_SUFFIXES
131
+ ffmpeg
132
132
)
133
133
134
- find_library (${_component} _LIBRARY NAMES ${PC_${_component} _LIBRARIES} ${_library}
135
- HINTS
136
- ${PC_${_component} _LIBDIR}
137
- ${PC_${_component} _LIBRARY_DIRS}
138
- ${PC_FFMPEG_LIBRARY_DIRS}
139
- )
134
+ if (NOT ("${PC_FFMPEG_LIBRARY_DIRS} " STREQUAL "" ))
135
+ find_library (${_component} _LIBRARY NAMES ${_library}
136
+ HINTS
137
+ ${PC_FFMPEG_LIBRARY_DIRS}
138
+ NO_DEFAULT_PATH # not sure whether this is needed or not
139
+ )
140
+ set (${_component} _LIBRARY_DIRS ${PC_FFMPEG_LIBRARY_DIRS} CACHE STRING "The ${_component} library dirs." )
141
+ set (${_component} _LIBRARIES ${_library} CACHE STRING "The ${_component} libraries." )
142
+ else ()
143
+ find_library (${_component} _LIBRARY NAMES ${PC_${_component} _LIBRARIES} ${_library}
144
+ HINTS
145
+ ${PC_${_component} _LIBDIR}
146
+ ${PC_${_component} _LIBRARY_DIRS}
147
+ ${PC_FFMPEG_LIBRARY_DIRS}
148
+ )
140
149
141
- #message(STATUS "L0: ${${_component}_LIBRARIES}")
142
- #message(STATUS "L1: ${PC_${_component}_LIBRARIES}")
143
- #message(STATUS "L2: ${_library}")
150
+ #message(STATUS "L0: ${${_component}_LIBRARIES}")
151
+ #message(STATUS "L1: ${PC_${_component}_LIBRARIES}")
152
+ #message(STATUS "L2: ${_library}")
144
153
145
- set (${_component} _DEFINITIONS ${PC_${_component} _CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS." )
146
- set (${_component} _VERSION ${PC_${_component} _VERSION} CACHE STRING "The ${_component} version number." )
147
- set (${_component} _LIBRARY_DIRS ${PC_${_component} _LIBRARY_DIRS} CACHE STRING "The ${_component} library dirs." )
148
- set (${_component} _LIBRARIES ${PC_${_component} _LIBRARIES} CACHE STRING "The ${_component} libraries." )
154
+ set (${_component} _DEFINITIONS ${PC_${_component} _CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS." )
155
+ set (${_component} _VERSION ${PC_${_component} _VERSION} CACHE STRING "The ${_component} version number." )
156
+ set (${_component} _LIBRARY_DIRS ${PC_${_component} _LIBRARY_DIRS} CACHE STRING "The ${_component} library dirs." )
157
+ set (${_component} _LIBRARIES ${PC_${_component} _LIBRARIES} CACHE STRING "The ${_component} libraries." )
158
+ endif ()
149
159
150
160
set_component_found(${_component} )
151
161
152
162
mark_as_advanced (
153
- ${_component} _LIBRARY
154
- ${_component} _INCLUDE_DIRS
155
- ${_component} _LIBRARY_DIRS
156
- ${_component} _LIBRARIES
157
- ${_component} _DEFINITIONS
158
- ${_component} _VERSION)
163
+ ${_component} _LIBRARY
164
+ ${_component} _INCLUDE_DIRS
165
+ ${_component} _LIBRARY_DIRS
166
+ ${_component} _LIBRARIES
167
+ ${_component} _DEFINITIONS
168
+ ${_component} _VERSION)
159
169
160
170
endmacro ()
161
171
162
172
163
173
# Check for cached results. If there are skip the costly part.
164
174
if (NOT FFMPEG_LIBRARIES)
165
175
176
+ if (NOT (${PC_FFMPEG_LIBRARY_DIRS} STREQUAL "" ))
177
+ set (FFMPEG_LIBRARY_DIRS ${PC_FFMPEG_LIBRARY_DIRS} )
178
+ endif ()
179
+
180
+ if (NOT (${PC_FFMPEG_INCLUDE_DIRS} STREQUAL "" ))
181
+ set (FFMPEG_INCLUDE_DIRS ${PC_FFMPEG_INCLUDE_DIRS} )
182
+ endif ()
183
+
166
184
# Check for all possible component.
167
- find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
168
- find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
169
- find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
170
- find_component(AVUTIL libavutil avutil libavutil/avutil.h)
171
- find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
172
- find_component(SWSCALE libswscale swscale libswscale/swscale.h)
173
- find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
185
+ find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
186
+ find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
187
+ find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
188
+ find_component(AVUTIL libavutil avutil libavutil/avutil.h)
189
+ find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
190
+ find_component(SWSCALE libswscale swscale libswscale/swscale.h)
191
+ find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
174
192
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
175
193
176
194
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
@@ -179,25 +197,31 @@ if (NOT FFMPEG_LIBRARIES)
179
197
message (STATUS "Libs: ${${_component} _LIBRARIES} | ${PC_${_component} _LIBRARIES}" )
180
198
181
199
# message(STATUS "Required component ${_component} present.")
182
- set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component} _LIBRARY} ${${_component} _LIBRARIES})
183
- set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component} _DEFINITIONS})
200
+ set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component} _LIBRARY} ${${_component} _LIBRARIES})
201
+ set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component} _DEFINITIONS})
202
+
203
+ if (${PC_FFMPEG_LIBRARY_DIRS} STREQUAL "" )
204
+ list (APPEND FFMPEG_LIBRARY_DIRS ${${_component} _LIBRARY_DIRS})
205
+ endif ()
206
+
207
+ if (${PC_FFMPEG_INCLUDE_DIRS} STREQUAL "" )
208
+ list (APPEND FFMPEG_INCLUDE_DIRS ${${_component} _INCLUDE_DIRS})
209
+ endif ()
184
210
185
- list (APPEND FFMPEG_INCLUDE_DIRS ${${_component} _INCLUDE_DIRS})
186
- list (APPEND FFMPEG_LIBRARY_DIRS ${${_component} _LIBRARY_DIRS})
187
211
188
212
string (TOLOWER ${_component} _lowerComponent)
189
213
if (NOT TARGET FFmpeg::${_lowerComponent} )
190
214
add_library (FFmpeg::${_lowerComponent} INTERFACE IMPORTED )
191
215
set_target_properties (FFmpeg::${_lowerComponent} PROPERTIES
192
- INTERFACE_COMPILE_OPTIONS "${${_component} _DEFINITIONS}"
193
- INTERFACE_INCLUDE_DIRECTORIES ${${_component} _INCLUDE_DIRS}
194
- INTERFACE_LINK_LIBRARIES "${${_component} _LIBRARY} ${${_component} _LIBRARIES} ${PC_${_component} _LIBRARIES}"
195
- INTERFACE_LINK_DIRECTORIES "${PC_${_component} _LIBDIR} ${PC_${_component} _LIBRARY_DIRS} ${PC_FFMPEG_LIBRARY_DIRS} "
196
- IMPORTED_LINK_INTERFACE_MULTIPLICITY 3)
197
- endif ()
198
- else ()
216
+ INTERFACE_COMPILE_OPTIONS "${${_component} _DEFINITIONS}"
217
+ INTERFACE_INCLUDE_DIRECTORIES ${${_component} _INCLUDE_DIRS}
218
+ INTERFACE_LINK_LIBRARIES "${${_component} _LIBRARY} ${${_component} _LIBRARIES} ${PC_${_component} _LIBRARIES}"
219
+ INTERFACE_LINK_DIRECTORIES "${PC_${_component} _LIBDIR} ${PC_${_component} _LIBRARY_DIRS} ${PC_FFMPEG_LIBRARY_DIRS} "
220
+ IMPORTED_LINK_INTERFACE_MULTIPLICITY 3)
221
+ endif ()
222
+ else ()
199
223
# message(STATUS "Required component ${_component} missing.")
200
- endif ()
224
+ endif ()
201
225
endforeach ()
202
226
203
227
# Build the include path with duplicates removed.
@@ -207,26 +231,26 @@ if (NOT FFMPEG_LIBRARIES)
207
231
208
232
# cache the vars.
209
233
set (FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
210
- set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
211
- set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
234
+ set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
235
+ set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
212
236
set (FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBRARY_DIRS} CACHE STRING "The FFmpeg library dirs." FORCE)
213
237
214
238
mark_as_advanced (FFMPEG_INCLUDE_DIRS
215
- FFMPEG_LIBRARIES
216
- FFMPEG_DEFINITIONS
217
- FFMPEG_LIBRARY_DIRS)
239
+ FFMPEG_LIBRARIES
240
+ FFMPEG_DEFINITIONS
241
+ FFMPEG_LIBRARY_DIRS)
218
242
219
243
endif ()
220
244
221
245
if (NOT TARGET FFmpeg::FFmpeg)
222
246
add_library (FFmpeg INTERFACE )
223
247
set_target_properties (FFmpeg PROPERTIES
224
- INTERFACE_COMPILE_OPTIONS "${FFMPEG_DEFINITIONS} "
225
- INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIRS}
226
- INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES} "
227
- INTERFACE_LINK_DIRECTORIES "${FFMPEG_LIBRARY_DIRS} " )
248
+ INTERFACE_COMPILE_OPTIONS "${FFMPEG_DEFINITIONS} "
249
+ INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIRS}
250
+ INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES} "
251
+ INTERFACE_LINK_DIRECTORIES "${FFMPEG_LIBRARY_DIRS} " )
228
252
add_library (FFmpeg::FFmpeg ALIAS FFmpeg)
229
- endif ()
253
+ endif ()
230
254
231
255
# Now set the noncached _FOUND vars for the components.
232
256
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
0 commit comments