From a0ab302b3cc62af8876c3bc9a42b48b3e386e32c Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Fri, 8 Oct 2021 19:55:11 -0400 Subject: [PATCH] MacOSX pipeline bundling library fix. --- pipelines/macOS_BundleFFmpegFix.pl | 42 ------------- pipelines/macOS_build.sh | 3 - scripts/macOSX_BundleFix.pl | 95 ++++++++++++++++++++++++++++++ src/CMakeLists.txt | 5 ++ 4 files changed, 100 insertions(+), 45 deletions(-) delete mode 100755 pipelines/macOS_BundleFFmpegFix.pl create mode 100755 scripts/macOSX_BundleFix.pl diff --git a/pipelines/macOS_BundleFFmpegFix.pl b/pipelines/macOS_BundleFFmpegFix.pl deleted file mode 100755 index 77bcb494..00000000 --- a/pipelines/macOS_BundleFFmpegFix.pl +++ /dev/null @@ -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"); - } - } - } -} diff --git a/pipelines/macOS_build.sh b/pipelines/macOS_build.sh index b2e1e974..1af19682 100755 --- a/pipelines/macOS_build.sh +++ b/pipelines/macOS_build.sh @@ -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: diff --git a/scripts/macOSX_BundleFix.pl b/scripts/macOSX_BundleFix.pl new file mode 100755 index 00000000..d40e7ac9 --- /dev/null +++ b/scripts/macOSX_BundleFix.pl @@ -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); + } + } + } +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 034e6cfa..3303e5aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 )