Implement dynamical ffmpeg linking on macOS

* fix dependencies and install names (absolute => relative)
* fix compilation build of dylib on xcode 15.
* add matching build instructions to yaml.
* old macos versions don't have 'realpath', workaround is used.

Task-number: QTBUG-120989
Pick-to: 6.7 6.6 6.5
Change-Id: I22e413d8f6d05c8c7d6d09a5926691216e781fd3
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
This commit is contained in:
Artem Dyomin
2024-01-23 13:29:27 +01:00
parent a84104df1c
commit a53b63019f
3 changed files with 58 additions and 18 deletions

View File

@@ -16,7 +16,7 @@ Configurations:
Configure arguments: '-nomake examples -release -force-debug-info -separate-debug-info -headersclean -framework'
Environment variables: [
'CMAKE_ARGS=-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DODBC_ROOT=/usr/local/opt/libiodbc -DPostgreSQL_ROOT={{.Env.POSTGRESQLBINPATH}}/.. -DOPENSSL_ROOT_DIR={{.Env.OPENSSL_DIR}}',
'NON_QTBASE_CMAKE_ARGS=-DFEATURE_gds=OFF -DFFMPEG_DIR={{.Env.FFMPEG_DIR}} -DFEATURE_native_grpc=OFF',
'NON_QTBASE_CMAKE_ARGS=-DFEATURE_gds=OFF -DFFMPEG_DIR={{.Env.FFMPEG_DIR}} -DQT_DEPLOY_FFMPEG=TRUE -DFEATURE_native_grpc=OFF',
'Protobuf_ROOT=/usr/local/lib/cmake/protobuf'
]
@@ -30,7 +30,7 @@ Configurations:
Environment variables: [
'CMAKE_ARGS=-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"',
'Protobuf_ROOT=/usr/local/lib/cmake/protobuf',
'NON_QTBASE_CMAKE_ARGS=-DFFMPEG_DIR={{.Env.FFMPEG_DIR}}',
'NON_QTBASE_CMAKE_ARGS=-DFFMPEG_DIR={{.Env.FFMPEG_DIR}} -DQT_DEPLOY_FFMPEG=TRUE',
]
# Test on all supported macOS versions (deployment targets)
@@ -124,7 +124,7 @@ Configurations:
Configure arguments: '-developer-build -release -force-debug-info -no-pch -no-framework -qtnamespace TestNamespace -make examples'
Environment variables: [
'CMAKE_ARGS=-DOPENSSL_ROOT_DIR={{.Env.OPENSSL_DIR}}',
'NON_QTBASE_CMAKE_ARGS=-DFFMPEG_DIR={{.Env.FFMPEG_DIR}}',
'NON_QTBASE_CMAKE_ARGS=-DFFMPEG_DIR={{.Env.FFMPEG_DIR}} -DQT_DEPLOY_FFMPEG=TRUE',
'Protobuf_ROOT=/usr/local/lib/cmake/protobuf',
]
-
@@ -136,7 +136,7 @@ Configurations:
Environment variables: [
'CMAKE_ARGS=-DOPENSSL_ROOT_DIR={{.Env.OPENSSL_DIR}}',
'Protobuf_ROOT=/usr/local/lib/cmake/protobuf',
'NON_QTBASE_CMAKE_ARGS=-DFFMPEG_DIR={{.Env.FFMPEG_DIR}}',
'NON_QTBASE_CMAKE_ARGS=-DFFMPEG_DIR={{.Env.FFMPEG_DIR}} -DQT_DEPLOY_FFMPEG=TRUE',
]
# Test on all supported macOS versions (deployment targets)

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
set -e
# realpath is not included to macOS <= 12.
# dir=$(realpath "$1")
dir=$(cd "$1" && pwd)
dir_length=${#dir}
dylib_regex="^$dir/.*\.dylib$"
find "$dir" -type f -name '*.dylib' | while read -r library_path; do
install_name=$(otool -D "$library_path" | sed -n '2p' | egrep "$dylib_regex" )
if [ -n "$install_name" ]; then
fixed_install_name="@rpath${install_name:dir_length}"
install_name_tool -id "$fixed_install_name" "$library_path"
fi
otool -L "$library_path" | awk '/\t/ {print $1}' | egrep "$dylib_regex" | while read -r dependency_path; do
fixed_dependency_path="@loader_path${dependency_path:dir_length}"
install_name_tool -change "$dependency_path" "$fixed_dependency_path" "$library_path"
done
done

View File

@@ -46,7 +46,6 @@ install_ff_nvcodec_headers() {
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
}
build_ffmpeg() {
local arch="$1"
local prefix="$2"
@@ -79,20 +78,36 @@ if [ "$os" == "linux" ]; then
sudo mv "$ffmpeg_source_dir/build/installed/usr/local/$ffmpeg_name" "/usr/local"
SetEnvVar "FFMPEG_DIR" "/usr/local/$ffmpeg_name"
elif [ "$os" == "macos" ]; then
elif [ "$os" == "macos" ] || [ "$os" == "macos-universal" ]; then
ffmpeg_config_options+=" --enable-shared --disable-static"
brew install yasm
export MACOSX_DEPLOYMENT_TARGET=12
build_ffmpeg
sudo mv "$ffmpeg_source_dir/build/installed/usr/local/$ffmpeg_name" "/usr/local"
fix_relative_dependencies="${BASH_SOURCE%/*}/../macos/fix_relative_dependencies.sh"
xcode_major_version=$(xcodebuild -version | awk 'NR==1 {split($2, a, "."); print a[1]}')
if [ $xcode_major_version -ge 15 ]; then
# fix the error: duplicate symbol '_av_ac3_parse_header'
ffmpeg_config_options+=" --extra-ldflags=-Wl,-ld_classic"
fi
if [ "$os" == "macos" ]; then
build_ffmpeg
install_dir="$ffmpeg_source_dir/build/installed"
"$fix_relative_dependencies" "$install_dir/usr/local/$ffmpeg_name/lib"
sudo mv "$install_dir/usr/local/$ffmpeg_name" "/usr/local"
else
build_ffmpeg "arm64"
build_ffmpeg "x86_64"
arm64_install_dir="$ffmpeg_source_dir/build/arm64/installed"
x86_64_install_dir="$ffmpeg_source_dir/build/x86_64/installed"
"$fix_relative_dependencies" "$arm64_install_dir/usr/local/$ffmpeg_name/lib"
"$fix_relative_dependencies" "$x86_64_install_dir/usr/local/$ffmpeg_name/lib"
sudo "${BASH_SOURCE%/*}/../macos/makeuniversal.sh" "$arm64_install_dir" "$x86_64_install_dir"
fi
SetEnvVar "FFMPEG_DIR" "/usr/local/$ffmpeg_name"
elif [ "$os" == "macos-universal" ]; then
brew install yasm
export MACOSX_DEPLOYMENT_TARGET=12
build_ffmpeg "arm64"
build_ffmpeg "x86_64"
sudo "${BASH_SOURCE%/*}/../macos/makeuniversal.sh" "$ffmpeg_source_dir/build/arm64/installed" "$ffmpeg_source_dir/build/x86_64/installed"
SetEnvVar "FFMPEG_DIR" "/usr/local/$ffmpeg_name"
fi