Skip to content

Commit

Permalink
MacOSX pipeline bundling library fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbudd77 committed Oct 8, 2021
1 parent cd4d22c commit a0ab302
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 45 deletions.
42 changes: 0 additions & 42 deletions pipelines/macOS_BundleFFmpegFix.pl

This file was deleted.

3 changes: 0 additions & 3 deletions pipelines/macOS_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ echo 'Install Optional Dependency ffmpeg'
echo '****************************************'
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

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:
Expand Down
95 changes: 95 additions & 0 deletions scripts/macOSX_BundleFix.pl
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,14 @@ if(NOT MACDEPLOYQT)
message(FATAL_ERROR "Could not find macdeployqt executable")
endif()

find_package(Perl REQUIRED)

install( CODE "
message(STATUS \"Deploying and fixing up dependencies in app: ${APP}\")
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
)
Expand Down

0 comments on commit a0ab302

Please sign in to comment.