Skip to content

Commit 7c44857

Browse files
committed
iOS, FFmpeg: Modify FindFFmpeg.cmake to look for .xcframework files
Currently the FindFFmpeg.cmake script looks for the presence only of .dylib files in order to determine the validity of the FFmpeg installation. On iOS, we no longer deploy these file-types directly for shared libraries. We only deploy .xcframework files, which in turn contain the .dylibs. This creates a situation where FindFFmpeg can succeed even when .xcframework files are missing from the FFmpeg installation. This patch allows FindFFmpeg.cmake to look for .xcframework files when on iOS. This will also allow us to stop installing raw .dylibs as part of FFmpeg builds. Fixes: QTBUG-135172 Pick-to: 6.9 6.8 Change-Id: I215700dea7e2f8ee7e513c8dbaa0c850d4f41a03 Reviewed-by: Timur Pocheptsov <[email protected]>
1 parent 1c6488e commit 7c44857

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

cmake/FindFFmpeg.cmake

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ if (QT_DEPLOY_FFMPEG AND BUILD_SHARED_LIBS)
7070
set(shared_libs_desired TRUE)
7171
endif()
7272

73+
if(IOS)
74+
set(QT_FFMPEG_SHARED_LIBRARY_SUFFIX ".xcframework")
75+
else()
76+
set(QT_FFMPEG_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
77+
endif()
78+
7379
# finds FFmpeg libs, including symlinks, for the specified component.
7480
macro(find_shared_libs_for_component _component)
7581
# the searching pattern is pretty rough but it seems to be sufficient to gather dynamic libs
@@ -82,13 +88,13 @@ macro(find_shared_libs_for_component _component)
8288
# only them even though the folder bin/ contains proper *.dll and *.lib.
8389

8490
string(REGEX REPLACE "^lib" "" name_we "${name_we}")
85-
set(shared_lib_pattern "../bin/${name_we}*${CMAKE_SHARED_LIBRARY_SUFFIX}")
91+
set(shared_lib_pattern "../bin/${name_we}*${QT_FFMPEG_SHARED_LIBRARY_SUFFIX}")
8692
else()
87-
set(shared_lib_pattern "${name_we}*${CMAKE_SHARED_LIBRARY_SUFFIX}")
93+
set(shared_lib_pattern "${name_we}*${QT_FFMPEG_SHARED_LIBRARY_SUFFIX}")
8894
endif()
8995

9096
else()
91-
set(shared_lib_pattern "${name_we}*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
97+
set(shared_lib_pattern "${name_we}*${QT_FFMPEG_SHARED_LIBRARY_SUFFIX}*")
9298
endif()
9399

94100
file(GLOB ${_component}_SHARED_LIBRARIES "${${_component}_LIBRARY_DIR}/${shared_lib_pattern}")
@@ -155,25 +161,41 @@ macro(find_component _component _pkgconfig _library _header)
155161
)
156162

157163
if (shared_libs_desired AND NOT WIN32)
158-
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX};${CMAKE_STATIC_LIBRARY_SUFFIX}")
164+
set(CMAKE_FIND_LIBRARY_SUFFIXES "${QT_FFMPEG_SHARED_LIBRARY_SUFFIX};${CMAKE_STATIC_LIBRARY_SUFFIX}")
159165
endif()
160166

161167
if (${_component}_LIBRARY AND NOT EXISTS ${${_component}_LIBRARY})
162168
message(STATUS "Cached library ${${_component}_LIBRARY} doesn't exist")
163169
unset(${_component}_LIBRARY CACHE)
164170
endif()
165171

166-
find_library(${_component}_LIBRARY
167-
NAMES ${PC_${_component}_LIBRARIES} ${_library}
168-
HINTS
169-
${PC_${_component}_LIBDIR}
170-
${PC_${_component}_LIBRARY_DIRS}
171-
${PC_FFMPEG_LIBRARY_DIRS}
172-
PATHS
173-
${FFMPEG_DIR}
174-
PATH_SUFFIXES
175-
lib bin
176-
)
172+
# Search for the relevant libraries. On iOS we deploy .xcframeworks, which aren't found by
173+
# find_library, so we rely on find_path.
174+
if (APPLE AND IOS)
175+
find_path(${_component}_LIBRARY
176+
NAMES lib${_library}${QT_FFMPEG_SHARED_LIBRARY_SUFFIX}
177+
PATHS
178+
${FFMPEG_DIR}
179+
PATH_SUFFIXES
180+
lib bin framework
181+
)
182+
# If found, append the path with the file we were looking for.
183+
if (${_component}_LIBRARY)
184+
set(${_component}_LIBRARY "${${_component}_LIBRARY}/lib${_library}${QT_FFMPEG_SHARED_LIBRARY_SUFFIX}")
185+
endif()
186+
else()
187+
find_library(${_component}_LIBRARY
188+
NAMES ${PC_${_component}_LIBRARIES} ${_library}
189+
HINTS
190+
${PC_${_component}_LIBDIR}
191+
${PC_${_component}_LIBRARY_DIRS}
192+
${PC_FFMPEG_LIBRARY_DIRS}
193+
PATHS
194+
${FFMPEG_DIR}
195+
PATH_SUFFIXES
196+
lib bin
197+
)
198+
endif()
177199

178200
if(FFMPEG_DIR OR FFMPEG_ROOT)
179201
set(CMAKE_FIND_ROOT_PATH "${__find_ffmpeg_backup_root_dir}")
@@ -185,7 +207,7 @@ macro(find_component _component _pkgconfig _library _header)
185207

186208
# On Windows, shared linking goes through 'integration' static libs, so we should look for shared ones anyway
187209
# On Unix, we gather symlinks as well so that we could install them.
188-
if (WIN32 OR ${${_component}_LIBRARY_NAME} MATCHES "\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
210+
if (WIN32 OR ${${_component}_LIBRARY_NAME} MATCHES "\\${QT_FFMPEG_SHARED_LIBRARY_SUFFIX}$")
189211
find_shared_libs_for_component(${_component})
190212
endif()
191213

0 commit comments

Comments
 (0)