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,79 @@ 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}
134
+ find_path (${_component} _INCLUDE_DIRS ${_header }
135
+ PATHS
136
+ ${PC_FFMPEG_INCLUDE_DIRS }
137
+ NO_DEFAULT_PATH
138
+ REQUIRED # perhaps?
139
139
)
140
140
141
- #message(STATUS "L0: ${${_component}_LIBRARIES}")
142
- #message(STATUS "L1: ${PC_${_component}_LIBRARIES}")
143
- #message(STATUS "L2: ${_library}")
141
+ if (NOT ("${PC_FFMPEG_LIBRARY_DIRS} " STREQUAL "" ))
142
+ find_library (${_component} _LIBRARY NAMES ${_library}
143
+ HINTS
144
+ ${PC_FFMPEG_LIBRARY_DIRS}
145
+ NO_DEFAULT_PATH # not sure whether this is needed or not
146
+ )
147
+ set (${_component} _LIBRARY_DIRS ${PC_FFMPEG_LIBRARY_DIRS} CACHE STRING "The ${_component} library dirs." )
148
+ set (${_component} _LIBRARIES ${_library} CACHE STRING "The ${_component} libraries." )
149
+ else ()
150
+ find_library (${_component} _LIBRARY NAMES ${PC_${_component} _LIBRARIES} ${_library}
151
+ HINTS
152
+ ${PC_${_component} _LIBDIR}
153
+ ${PC_${_component} _LIBRARY_DIRS}
154
+ ${PC_FFMPEG_LIBRARY_DIRS}
155
+ )
156
+
157
+ #message(STATUS "L0: ${${_component}_LIBRARIES}")
158
+ #message(STATUS "L1: ${PC_${_component}_LIBRARIES}")
159
+ #message(STATUS "L2: ${_library}")
144
160
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." )
161
+ set (${_component} _DEFINITIONS ${PC_${_component} _CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS." )
162
+ set (${_component} _VERSION ${PC_${_component} _VERSION} CACHE STRING "The ${_component} version number." )
163
+ set (${_component} _LIBRARY_DIRS ${PC_${_component} _LIBRARY_DIRS} CACHE STRING "The ${_component} library dirs." )
164
+ set (${_component} _LIBRARIES ${PC_${_component} _LIBRARIES} CACHE STRING "The ${_component} libraries." )
165
+ endif ()
149
166
150
167
set_component_found(${_component} )
151
168
152
169
mark_as_advanced (
153
- ${_component} _LIBRARY
154
- ${_component} _INCLUDE_DIRS
155
- ${_component} _LIBRARY_DIRS
156
- ${_component} _LIBRARIES
157
- ${_component} _DEFINITIONS
158
- ${_component} _VERSION)
170
+ ${_component} _LIBRARY
171
+ ${_component} _INCLUDE_DIRS
172
+ ${_component} _LIBRARY_DIRS
173
+ ${_component} _LIBRARIES
174
+ ${_component} _DEFINITIONS
175
+ ${_component} _VERSION)
159
176
160
177
endmacro ()
161
178
162
179
163
180
# Check for cached results. If there are skip the costly part.
164
181
if (NOT FFMPEG_LIBRARIES)
165
182
183
+ if (DEFINED PC_FFMPEG_LIBRARY_DIRS AND NOT "${PC_FFMPEG_LIBRARY_DIRS} " STREQUAL "" )
184
+ set (FFMPEG_LIBRARY_DIRS "${PC_FFMPEG_LIBRARY_DIRS} " )
185
+ endif ()
186
+
187
+ if (DEFINED PC_FFMPEG_INCLUDE_DIRS AND NOT "${PC_FFMPEG_INCLUDE_DIRS} " STREQUAL "" )
188
+ set (FFMPEG_INCLUDE_DIRS "${PC_FFMPEG_INCLUDE_DIRS} " )
189
+ endif ()
190
+
166
191
# 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)
192
+ find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
193
+ find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
194
+ find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
195
+ find_component(AVUTIL libavutil avutil libavutil/avutil.h)
196
+ find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
197
+ find_component(SWSCALE libswscale swscale libswscale/swscale.h)
198
+ find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
174
199
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
175
200
176
201
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
@@ -179,25 +204,30 @@ if (NOT FFMPEG_LIBRARIES)
179
204
message (STATUS "Libs: ${${_component} _LIBRARIES} | ${PC_${_component} _LIBRARIES}" )
180
205
181
206
# message(STATUS "Required component ${_component} present.")
182
- set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component} _LIBRARY} ${${_component} _LIBRARIES})
183
- set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component} _DEFINITIONS})
207
+ set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component} _LIBRARY} ${${_component} _LIBRARIES})
208
+ set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component} _DEFINITIONS})
184
209
185
- list (APPEND FFMPEG_INCLUDE_DIRS ${${_component} _INCLUDE_DIRS})
186
- list (APPEND FFMPEG_LIBRARY_DIRS ${${_component} _LIBRARY_DIRS})
210
+ if (NOT DEFINED PC_FFMPEG_LIBRARY_DIRS OR "${PC_FFMPEG_LIBRARY_DIRS} " STREQUAL "" )
211
+ list (APPEND FFMPEG_LIBRARY_DIRS ${${_component} _LIBRARY_DIRS})
212
+ endif ()
213
+
214
+ if (NOT DEFINED PC_FFMPEG_INCLUDE_DIRS OR "${PC_FFMPEG_INCLUDE_DIRS} " STREQUAL "" )
215
+ list (APPEND FFMPEG_INCLUDE_DIRS ${${_component} _INCLUDE_DIRS})
216
+ endif ()
187
217
188
218
string (TOLOWER ${_component} _lowerComponent)
189
219
if (NOT TARGET FFmpeg::${_lowerComponent} )
190
220
add_library (FFmpeg::${_lowerComponent} INTERFACE IMPORTED )
191
221
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 ()
222
+ INTERFACE_COMPILE_OPTIONS "${${_component} _DEFINITIONS}"
223
+ INTERFACE_INCLUDE_DIRECTORIES ${${_component} _INCLUDE_DIRS}
224
+ INTERFACE_LINK_LIBRARIES "${${_component} _LIBRARY} ${${_component} _LIBRARIES} ${PC_${_component} _LIBRARIES}"
225
+ INTERFACE_LINK_DIRECTORIES "${PC_${_component} _LIBDIR} ${PC_${_component} _LIBRARY_DIRS} ${PC_FFMPEG_LIBRARY_DIRS} "
226
+ IMPORTED_LINK_INTERFACE_MULTIPLICITY 3)
227
+ endif ()
228
+ else ()
199
229
# message(STATUS "Required component ${_component} missing.")
200
- endif ()
230
+ endif ()
201
231
endforeach ()
202
232
203
233
# Build the include path with duplicates removed.
@@ -207,26 +237,26 @@ if (NOT FFMPEG_LIBRARIES)
207
237
208
238
# cache the vars.
209
239
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)
240
+ set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
241
+ set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
212
242
set (FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBRARY_DIRS} CACHE STRING "The FFmpeg library dirs." FORCE)
213
243
214
244
mark_as_advanced (FFMPEG_INCLUDE_DIRS
215
- FFMPEG_LIBRARIES
216
- FFMPEG_DEFINITIONS
217
- FFMPEG_LIBRARY_DIRS)
245
+ FFMPEG_LIBRARIES
246
+ FFMPEG_DEFINITIONS
247
+ FFMPEG_LIBRARY_DIRS)
218
248
219
249
endif ()
220
250
221
251
if (NOT TARGET FFmpeg::FFmpeg)
222
252
add_library (FFmpeg INTERFACE )
223
253
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} " )
254
+ INTERFACE_COMPILE_OPTIONS "${FFMPEG_DEFINITIONS} "
255
+ INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIRS}
256
+ INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES} "
257
+ INTERFACE_LINK_DIRECTORIES "${FFMPEG_LIBRARY_DIRS} " )
228
258
add_library (FFmpeg::FFmpeg ALIAS FFmpeg)
229
- endif ()
259
+ endif ()
230
260
231
261
# Now set the noncached _FOUND vars for the components.
232
262
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
0 commit comments