MacOSX pipeline bundling library fix.

This commit is contained in:
mjbudd77 2021-10-08 19:55:11 -04:00
parent cd4d22cc6a
commit a0ab302b3c
4 changed files with 100 additions and 45 deletions

View File

@ -1,42 +0,0 @@
#!/usr/bin/perl
use strict;
# MacOSX homebrew version of ffmpeg comes with 5 libraries. These libraries depend on each other
# and it seems that macdeployqt doesn't fix all the library paths when bundling them.
# This script fixes those bundling issues.
my $i; my $j; my $k;
my $LIBPATH=`brew --prefix ffmpeg`;
my @libList = ( "libavutil", "libavcodec", "libavformat", "libswscale", "libswresample" );
my $lib; my $otool;
my @lines;
for ($i=0; $i<=$#libList; $i++)
{
#print "LIB: $libList[$i]\n";
$lib="$LIBPATH/lib/$libList[$i].dylib";
$lib=~s/\n//;
print "Fixing lib: '$lib'\n";
$otool=`otool -L $lib`;
#print "otool: '$otool'\n";
@lines = split /\n/, $otool;
for ($j=0; $j<=$#lines; $j++)
{
for ($k=0; $k<=$#libList; $k++)
{
if ( $lines[$j] =~ m/\s+(\/.*\/($libList[$k].*\.dylib))/ )
{
#print "$1 $2\n";
print("install_name_tool -change $1 \@executable_path/../Frameworks/$2 $lib\n");
system("install_name_tool -change $1 \@executable_path/../Frameworks/$2 $lib");
}
}
}
}

View File

@ -77,9 +77,6 @@ echo 'Install Optional Dependency ffmpeg'
echo '****************************************' echo '****************************************'
brew install ffmpeg brew install ffmpeg
# Fix homebrew ffmpeg libraries so that they work in the bundle.
sudo $SCRIPT_DIR/macOS_BundleFFmpegFix.pl
#brew install zlib # Already installed in appveyor macOS #brew install zlib # Already installed in appveyor macOS
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig: export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:

95
scripts/macOSX_BundleFix.pl Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/perl
use strict;
my $i; my $findResult;
my $INSTALL_PREFIX="/tmp/fceux";
if ( $#ARGV >= 0 )
{
$INSTALL_PREFIX=$ARGV[0];
}
if ( ! -d "$INSTALL_PREFIX")
{
die "Error Invalid install prefix: $INSTALL_PREFIX\n";
}
print "INSTALL PREFIX: $INSTALL_PREFIX\n";
$findResult = `find $INSTALL_PREFIX -d -name fceux.app`;
if ( $findResult ne "")
{
$findResult =~ s/\n.*//;
$INSTALL_PREFIX=$findResult;
}
else
{
$INSTALL_PREFIX="$INSTALL_PREFIX/fceux.app";
}
print "INSTALL PREFIX: $INSTALL_PREFIX\n";
# MacOSX homebrew version of ffmpeg comes with 5 libraries. These libraries depend on each other
# and it seems that macdeployqt doesn't fix all the library paths when bundling them.
# This script fixes those bundling issues.
my $LIBPATH="$INSTALL_PREFIX/Contents/Frameworks";
#my @libList = ( "libavutil", "libavcodec", "libavformat", "libswscale", "libswresample" );
my $lsList = `ls $LIBPATH/*.dylib`;
my @libList = split /\n/, $lsList;
my $lib;
my %libsDone;
for ($i=0; $i<=$#libList; $i++)
{
$lib="$libList[$i]";
$lib=~s/\n//;
#
fixLib($lib);
}
sub fixLib
{
my $j;
my $lib = $_[0];
my $otool;
my $depPath; my $depName;
my @lines;
my $cmd;
if ( defined($libsDone{$lib}))
{
#print "Lib Done: $lib\n";
return;
}
print "CHECKING LIB DEPS: '$libList[$i]'\n";
#
$libsDone{$lib} = 1;
#print "Checking lib: '$lib'\n";
$otool=`otool -L $lib`;
#print "otool: '$otool'\n";
@lines = split /\n/, $otool;
for ($j=1; $j<=$#lines; $j++)
{
if ( $lines[$j] =~ m/\s+(\/usr\/local\/.*(lib.*\.dylib))/ )
{
$depPath = $1;
$depName = $2;
#print "$1 $2\n";
if (-e "$LIBPATH/$depName")
{
#print "Found Packaged $depName...\n";
$cmd = "install_name_tool -change $depPath \@executable_path/../Frameworks/$depName $lib";
print "\tFIXING LIB LINK: '$depPath'\n";
#print("$cmd\n");
system($cmd);
}
}
}
}

View File

@ -605,9 +605,14 @@ if(NOT MACDEPLOYQT)
message(FATAL_ERROR "Could not find macdeployqt executable") message(FATAL_ERROR "Could not find macdeployqt executable")
endif() endif()
find_package(Perl REQUIRED)
install( CODE " install( CODE "
message(STATUS \"Deploying and fixing up dependencies in app: ${APP}\") message(STATUS \"Deploying and fixing up dependencies in app: ${APP}\")
execute_process(COMMAND \"${MACDEPLOYQT}\" \"${APP}\" -verbose=1) execute_process(COMMAND \"${MACDEPLOYQT}\" \"${APP}\" -verbose=1)
execute_process(COMMAND \"${PERL_EXECUTABLE}\"
\"${CMAKE_SOURCE_DIR}/scripts/macOSX_BundleFix.pl\"
\"${CMAKE_BINARY_DIR}/_CPack_Packages\")
" "
COMPONENT Runtime COMPONENT Runtime
) )