More macOS rpath fixes. Hopefully this is the last of them.

This commit is contained in:
casey langen 2022-02-13 11:26:17 -08:00
parent 6e3fe7fbc8
commit 7ec96630bc
8 changed files with 160 additions and 111 deletions

View File

@ -0,0 +1,9 @@
macro(find_vendor_library target_var library_name)
find_library(${target_var} NAMES ${library_name} PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
message(STATUS "[find-vendor-library] '${library_name}' resolved to '${${target_var}}'")
endmacro(find_vendor_library)
macro(add_vendor_includes target_project)
target_include_directories(${target_project} PRIVATE BEFORE ${VENDOR_INCLUDE_DIRECTORIES})
message(STATUS "[add-vendor-includes] adding vendor includes to '${target_project}'")
endmacro(add_vendor_includes)

View File

@ -25,6 +25,7 @@ include(AddLinuxSystemLibs)
include(ConfigureCurses)
include(ConfigureTaglib)
include(ConfigureCompilerFlags)
include(FindVendorLibrary)
message(STATUS "[vendor-link-directories] ${VENDOR_LINK_DIRECTORIES}")
message(STATUS "[vendor-include-directories] ${VENDOR_INCLUDE_DIRECTORIES}")
@ -45,9 +46,9 @@ message(STATUS "[boost] libs: " ${Boost_LIBRARIES})
message(STATUS "[boost] includes: " ${Boost_INCLUDE_DIRS})
if (${BUILD_STANDALONE} MATCHES "true")
find_library(LIBCURL NAMES curl PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(LIBSSL NAMES ssl PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(LIBCRYPTO NAMES crypto PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_vendor_library(LIBCURL curl)
find_vendor_library(LIBSSL ssl)
find_vendor_library(LIBCRYPTO crypto)
else()
find_library(LIBCURL NAMES curl)
find_library(LIBSSL NAMES ssl)

View File

@ -9,6 +9,8 @@
export CFLAGS="-fPIC"
export CXXFLAGS="-fPIC"
RPATH="@rpath"
OS=$(uname)
ARCH=$(uname -m)
BOOST_VERSION="1_76_0"
@ -148,70 +150,14 @@ function build_libmicrohttpd() {
# ffmpeg
#
function stage_opus_ogg_vorbis() {
if [ $OS == "Darwin" ]; then
# instead of building opus, ogg and vorbis from source we snag them
# from brew, update their dylib ids with @rpath, re-sign them, then create
# new pkg-config files to point towards this directory. that way ffmpeg
# will pick them up automatically.
rm -rf opus-ogg-vorbis
mkdir opus-ogg-vorbis
cd opus-ogg-vorbis
export PKG_CONFIG_PATH=$(pwd)
BREW=$(brew --prefix)
# create pkg-config files to point towards this dir
cp $BREW/opt/opus/lib/pkgconfig/opus.pc .
cp $BREW/opt/libogg/lib/pkgconfig/ogg.pc .
cp $BREW/opt/libvorbis/lib/pkgconfig/vorbis.pc .
cp $BREW/opt/libvorbis/lib/pkgconfig/vorbisenc.pc .
chmod 644 *.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" opus.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" ogg.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" vorbis.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" vorbisenc.pc
rm *.bak
# copy libs, update their ids, then resign
LIBOPUS="$BREW/opt/opus/lib/libopus.0.dylib"
LIBOGG="$BREW/opt/libogg/lib/libogg.0.dylib"
LIBVORBIS="$BREW/opt/libvorbis/lib/libvorbis.0.dylib"
LIBVORBISENC="$BREW/opt/libvorbis/lib/libvorbisenc.2.dylib"
cp ${LIBOPUS} ${LIBOGG} ${LIBVORBIS} ${LIBVORBISENC} .
chmod 755 *.dylib
install_name_tool -id "@rpath/libopus.0.dylib" ./libopus.0.dylib
install_name_tool -id "@rpath/libogg.0.dylib" ./libogg.0.dylib
install_name_tool -id "@rpath/libvorbis.0.dylib" ./libvorbis.0.dylib
install_name_tool -id "@rpath/libvorbisenc.2.dylib" ./libvorbisenc.2.dylib
codesign --remove-signature ./libopus.0.dylib
codesign --remove-signature ./libogg.0.dylib
codesign --remove-signature ./libvorbis.0.dylib
codesign --remove-signature ./libvorbisenc.2.dylib
codesign --sign=- ./libopus.0.dylib
codesign --sign=- ./libogg.0.dylib
codesign --sign=- ./libvorbis.0.dylib
codesign --sign=- ./libvorbisenc.2.dylib
# these links are required for pkg-config to be happy
ln -s libopus.0.dylib libopus.dylib
ln -s libogg.0.dylib libogg.dylib
ln -s libvorbis.0.dylib libvorbis.dylib
ln -s libvorbisenc.2.dylib libvorbisenc.dylib
cd ..
fi
}
function build_ffmpeg() {
rm -rf ffmpeg-${FFMPEG_VERSION} ffmpeg-bin
rm -rf ffmpeg-${FFMPEG_VERSION}
rm -rf ffmpeg-bin
mkdir -p ffmpeg-bin/lib
tar xvfj ffmpeg-${FFMPEG_VERSION}.tar.bz2
cd ffmpeg-${FFMPEG_VERSION}
./configure \
--prefix="@rpath" \
--prefix="$(pwd)/output/" \
--enable-rpath \
--disable-asm \
--enable-pic \
@ -388,7 +334,7 @@ function build_ffmpeg() {
make ${JOBS} || exit $?
make install
mkdir ../ffmpeg-bin
cp -rfp \@rpath/* ../ffmpeg-bin
cp -rfp output/* ../ffmpeg-bin
cd ..
}
@ -414,47 +360,140 @@ function build_lame() {
# macOS dylib rpaths
#
function stage_opus_ogg_vorbis() {
if [ $OS == "Darwin" ]; then
# instead of building opus, ogg and vorbis from source we snag them
# from brew, update their dylib ids with @rpath, re-sign them, then create
# new pkg-config files to point towards this directory. that way ffmpeg
# will pick them up automatically.
rm -rf opus-ogg-vorbis
mkdir opus-ogg-vorbis
cd opus-ogg-vorbis
export PKG_CONFIG_PATH=$(pwd)
BREW=$(brew --prefix)
# create pkg-config files to point towards this dir
cp $BREW/opt/opus/lib/pkgconfig/opus.pc .
cp $BREW/opt/libogg/lib/pkgconfig/ogg.pc .
cp $BREW/opt/libvorbis/lib/pkgconfig/vorbis.pc .
cp $BREW/opt/libvorbis/lib/pkgconfig/vorbisenc.pc .
chmod 644 *.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" opus.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" ogg.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" vorbis.pc
perl -i.bak -0pe "s|libdir.*\n|libdir=$(pwd)\n|" vorbisenc.pc
rm *.bak
# copy libs, update their ids, then resign
LIBOPUS="$BREW/opt/opus/lib/libopus.0.dylib"
LIBOGG="$BREW/opt/libogg/lib/libogg.0.dylib"
LIBVORBIS="$BREW/opt/libvorbis/lib/libvorbis.0.dylib"
LIBVORBISENC="$BREW/opt/libvorbis/lib/libvorbisenc.2.dylib"
cp ${LIBOPUS} ${LIBOGG} ${LIBVORBIS} ${LIBVORBISENC} .
chmod 755 *.dylib
install_name_tool -id "$RPATH/libopus.0.dylib" ./libopus.0.dylib
codesign --remove-signature ./libopus.0.dylib
codesign --sign=- ./libopus.0.dylib
ln -s libopus.0.dylib libopus.dylib
install_name_tool -id "$RPATH/libogg.0.dylib" ./libogg.0.dylib
codesign --remove-signature ./libogg.0.dylib
codesign --sign=- ./libogg.0.dylib
ln -s libogg.0.dylib libogg.dylib
install_name_tool -id "$RPATH/libvorbis.0.dylib" ./libvorbis.0.dylib
install_name_tool -change "${LIBOGG}" "$RPATH/libogg.0.dylib" ./libvorbis.0.dylib
ln -s libvorbis.0.dylib libvorbis.dylib
install_name_tool -id "$RPATH/libvorbisenc.2.dylib" ./libvorbisenc.2.dylib
install_name_tool -change "${LIBOGG}" "$RPATH/libogg.0.dylib" ./libvorbisenc.2.dylib
install_name_tool -change "${LIBVORBIS}" "$RPATH/libvorbis.0.dylib" ./libvorbisenc.2.dylib
# odd man out... not sure why this is this way...
LIBVORBIS_CELLAR="$BREW/Cellar/libvorbis/1.3.7/lib/libvorbis.0.dylib"
install_name_tool -change "${LIBVORBIS_CELLAR}" "$RPATH/libvorbis.0.dylib" ./libvorbisenc.2.dylib
#end weird hack
ln -s libvorbisenc.2.dylib libvorbisenc.dylib
codesign --remove-signature ./libvorbis.0.dylib
codesign --remove-signature ./libvorbisenc.2.dylib
codesign --sign=- ./libvorbis.0.dylib
codesign --sign=- ./libvorbisenc.2.dylib
cd ..
fi
}
function patch_dylib_rpaths() {
if [ $OS == "Darwin" ]; then
OPENSSL_LIB_PATH="$(pwd)/openssl-${OPENSSL_VERSION}/output/lib"
FFMPEG_LIB_PATH="$(pwd)/ffmpeg-${FFMPEG_VERSION}/output/lib"
cd ffmpeg-bin/lib
install_name_tool -id "$RPATH/libavutil-musikcube.57.dylib" libavutil-musikcube.57.dylib
rm libavutil-musikcube.dylib
ln -s libavutil-musikcube.57.dylib libavutil-musikcube.dylib
install_name_tool -id "$RPATH/libavformat-musikcube.59.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libswresample-musikcube.4.dylib" "$RPATH/libswresample-musikcube.4.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libavcodec-musikcube.59.dylib" "$RPATH/libavcodec-musikcube.59.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libavutil-musikcube.57.dylib" "$RPATH/libavutil-musikcube.57.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBOPUS}" "$RPATH/libopus.0.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBOGG}" "$RPATH/libogg.0.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBVORBIS}" "$RPATH/libvorbis.0.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBVORBISENC}" "$RPATH/libvorbisenc.2.dylib" libavformat-musikcube.59.dylib
rm libavformat-musikcube.dylib
ln -s libavformat-musikcube.59.dylib libavformat-musikcube.dylib
install_name_tool -id "$RPATH/libavcodec-musikcube.59.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libswresample-musikcube.4.dylib" "$RPATH/libswresample-musikcube.4.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libavcodec-musikcube.59.dylib" "$RPATH/libavcodec-musikcube.59.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libavutil-musikcube.57.dylib" "$RPATH/libavutil-musikcube.57.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBOPUS}" "$RPATH/libopus.0.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBOGG}" "$RPATH/libogg.0.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBVORBIS}" "$RPATH/libvorbis.0.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBVORBISENC}" "$RPATH/libvorbisenc.2.dylib" libavcodec-musikcube.59.dylib
rm libavcodec-musikcube.dylib
ln -s libavcodec-musikcube.59.dylib libavcodec-musikcube.dylib
install_name_tool -id "$RPATH/libswresample-musikcube.4.dylib" libswresample-musikcube.4.dylib
install_name_tool -change "$FFMPEG_LIB_PATH/libavutil-musikcube.57.dylib" "$RPATH/libavutil-musikcube.57.dylib" libswresample-musikcube.4.dylib
rm libswresample-musikcube.dylib
ln -s libswresample-musikcube.4.dylib libswresample-musikcube.dylib
cd ../../
cd openssl-bin/lib
install_name_tool -id "@rpath/libcrypto.1.1.dylib" libcrypto.1.1.dylib
install_name_tool -id "@rpath/libcrypto.dylib" libcrypto.dylib
install_name_tool -id "@rpath/libssl.1.1.dylib" libssl.1.1.dylib
install_name_tool -id "@rpath/libssl.dylib" libssl.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libcrypto.1.1.dylib" "@rpath/libcrypto.1.1.dylib" libssl.1.1.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libcrypto.1.1.dylib" "@rpath/libcrypto.dylib" libssl.dylib
install_name_tool -id "$RPATH/libcrypto.1.1.dylib" libcrypto.1.1.dylib
rm libcrypto.dylib
ln -s libcrypto.1.1.dylib libcrypto.dylib
install_name_tool -id "$RPATH/libssl.1.1.dylib" libssl.1.1.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libcrypto.1.1.dylib" "$RPATH/libcrypto.1.1.dylib" libssl.1.1.dylib
rm libssl.dylib
ln -s libssl.1.1.dylib libssl.dylib
cd ../../
cd curl-bin/lib
install_name_tool -id "@rpath/libcurl.dylib" libcurl.dylib
install_name_tool -id "@rpath/libcurl.4.dylib" libcurl.4.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libcrypto.1.1.dylib" "@rpath/libcrypto.1.1.dylib" libcurl.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libcrypto.1.1.dylib" "@rpath/libcrypto.1.1.dylib" libcurl.4.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libssl.1.1.dylib" "@rpath/libssl.1.1.dylib" libcurl.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libssl.1.1.dylib" "@rpath/libssl.1.1.dylib" libcurl.4.dylib
cd ../../
cd ffmpeg-bin/lib/
install_name_tool -change "${LIBOPUS}" "@rpath/libopus.0.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBOPUS}" "@rpath/libopus.0.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBOGG}" "@rpath/libogg.0.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBOGG}" "@rpath/libogg.0.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBVORBIS}" "@rpath/libvorbis.0.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBVORBIS}" "@rpath/libvorbis.0.dylib" libavformat-musikcube.59.dylib
install_name_tool -change "${LIBVORBISENC}" "@rpath/libvorbisenc.2.dylib" libavcodec-musikcube.59.dylib
install_name_tool -change "${LIBVORBISENC}" "@rpath/libvorbisenc.2.dylib" libavformat-musikcube.59.dylib
install_name_tool -id "$RPATH/libcurl.4.dylib" libcurl.4.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libcrypto.1.1.dylib" "$RPATH/libcrypto.1.1.dylib" libcurl.4.dylib
install_name_tool -change "${OPENSSL_LIB_PATH}/libssl.1.1.dylib" "$RPATH/libssl.1.1.dylib" libcurl.4.dylib
rm libcurl.dylib
ln -s libcurl.4.dylib libcurl.dylib
cd ../../
cd libmicrohttpd-bin/lib/
install_name_tool -id "@rpath/libmicrohttpd.dylib" libmicrohttpd.dylib
install_name_tool -id "@rpath/libmicrohttpd.12.dylib" libmicrohttpd.12.dylib
install_name_tool -id "$RPATH/libmicrohttpd.12.dylib" libmicrohttpd.12.dylib
rm libmicrohttpd.dylib
ln -s libmicrohttpd.12.dylib libmicrohttpd.dylib
cd ../../
cd lame-bin/lib/
install_name_tool -id "@rpath/libmp3lame.dylib" libmp3lame.dylib
install_name_tool -id "@rpath/libmp3lame.0.dylib" libmp3lame.0.dylib
install_name_tool -id "$RPATH/libmp3lame.0.dylib" libmp3lame.0.dylib
rm libmp3lame.dylib
ln -s libmp3lame.0.dylib libmp3lame.dylib
cd ../../
fi
}

View File

@ -51,4 +51,4 @@ popd
ditto -c -k --keepParent $DIR $ARCHIVE
xcrun notarytool submit $ARCHIVE --keychain-profile "$KEYCHAIN_PROFILE" --wait
# xcrun notarytool submit $ARCHIVE --keychain-profile "$KEYCHAIN_PROFILE" --wait

View File

@ -1,5 +1,7 @@
#!/bin/bash
rm -rf bin/lib/ 2> /dev/null
mkdir -p bin/lib/
mkdir -p bin/plugins/
pushd bin/plugins
@ -28,17 +30,14 @@ if [[ "$PLATFORM" == 'Darwin' ]]; then
cp vendor/boost-bin/lib/libboost_system.dylib ./bin/lib
cp vendor/boost-bin/lib/libboost_thread.dylib ./bin/lib
cp vendor/openssl-bin/lib/libcrypto.dylib ./bin/lib
cp vendor/openssl-bin/lib/libssl.dylib ./bin/lib
cp vendor/openssl-bin/lib/libcrypto.1.1.dylib ./bin/lib
cp vendor/openssl-bin/lib/libssl.1.1.dylib ./bin/lib
cp vendor/curl-bin/lib/libcurl.dylib ./bin/lib
cp vendor/curl-bin/lib/libcurl.4.dylib ./bin/lib
cp vendor/libmicrohttpd-bin/lib/libmicrohttpd.dylib ./bin/lib
cp vendor/libmicrohttpd-bin/lib/libmicrohttpd.12.dylib ./bin/lib
cd bin/lib/
ln -s libcrypto.dylib libcrypto.1.1.dylib
ln -s libssl.dylib libssl.1.1.dylib
cd ../../
cp vendor/lame-bin/lib/libmp3lame.0.dylib ./bin/lib
elif [[ "$PLATFORM" == 'Linux' ]]; then
echo "[stage-static-vendor-libraries] staging Linux .so files..."

View File

@ -5,11 +5,11 @@ set (ffmpegdecoder_SOURCES
add_library(ffmpegdecoder SHARED ${ffmpegdecoder_SOURCES})
if (${BUILD_STANDALONE} MATCHES "true")
target_include_directories(ffmpegdecoder PRIVATE BEFORE ${VENDOR_INCLUDE_DIRECTORIES})
find_library(AVCODEC NAMES avcodec-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(AVUTIL NAMES avutil-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(AVFORMAT NAMES avformat-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(SWRESAMPLE NAMES swresample-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
add_vendor_includes(ffmpegdecoder)
find_vendor_library(AVCODEC avcodec-musikcube)
find_vendor_library(AVUTIL avutil-musikcube)
find_vendor_library(AVFORMAT avformat-musikcube)
find_vendor_library(SWRESAMPLE swresample-musikcube)
else()
# fedora (and probably other RPM-based distros) put ffmpeg includes here...
include_directories("/usr/include/ffmpeg")

View File

@ -14,7 +14,7 @@ target_include_directories(server BEFORE PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/3r
target_include_directories(server BEFORE PRIVATE ${VENDOR_INCLUDE_DIRECTORIES})
if (${BUILD_STANDALONE} MATCHES "true")
find_library(LIBMICROHTTPD NAMES microhttpd PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH NO_CACHE)
find_vendor_library(LIBMICROHTTPD microhttpd)
else()
if (APPLE)
find_library(LIBGNUTLS NAMES gnutls)

View File

@ -6,11 +6,12 @@ set (stockencoders_SOURCES
add_library(stockencoders SHARED ${stockencoders_SOURCES})
if (${BUILD_STANDALONE} MATCHES "true")
target_include_directories(stockencoders BEFORE PRIVATE ${VENDOR_INCLUDE_DIRECTORIES})
find_library(AVCODEC NAMES avcodec-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(AVUTIL NAMES avutil-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(AVFORMAT NAMES avformat-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
find_library(SWRESAMPLE NAMES swresample-musikcube PATHS ${VENDOR_LINK_DIRECTORIES} NO_DEFAULT_PATH)
add_vendor_includes(stockencoders)
find_vendor_library(AVCODEC avcodec-musikcube)
find_vendor_library(AVUTIL avutil-musikcube)
find_vendor_library(AVFORMAT avformat-musikcube)
find_vendor_library(SWRESAMPLE swresample-musikcube)
find_vendor_library(MP3LAME mp3lame)
else()
# fedora (and probably other RPM-based distros) put ffmpeg includes here...
include_directories("/usr/include/ffmpeg")
@ -19,7 +20,7 @@ else()
find_library(AVUTIL NAMES avutil)
find_library(AVFORMAT NAMES avformat)
find_library(SWRESAMPLE NAMES swresample)
find_library(MP3LAME NAMES mp3lame)
endif()
find_library(MP3LAME NAMES mp3lame)
target_link_libraries(stockencoders ${AVCODEC} ${AVUTIL} ${AVFORMAT} ${SWRESAMPLE} ${MP3LAME})