Skip to content

Commit

Permalink
Update macOS dependencies (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang authored Jun 29, 2024
1 parent e8b243b commit 3de6531
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 63 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ jobs:
- name: install deps
if: matrix.arch != 'Universal' || ( matrix.arch == 'Universal' && github.event.inputs.universal_macos == 'true')
run: |
brew install create-dmg dylibbundler boost
brew list webp boost
brew install create-dmg dylibbundler
brew tap xfangfang/wiliwili
brew install -v mpv-wiliwili
Expand Down
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ find_package(Threads REQUIRED)
list(APPEND APP_PLATFORM_LIB ${CMAKE_THREAD_LIBS_INIT})

# Find libmpv and libwebp
if (PLATFORM_DESKTOP)
if (MAC_DOWNLOAD_DYLIB)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_BINARY_DIR}/deps/lib/cmake)
elseif (PLATFORM_DESKTOP)
find_package(MPV REQUIRED)
message(STATUS "Found libmpv: ${MPV_VERSION} ${MPV_INCLUDE_DIR} ${MPV_LIBRARY}")
list(APPEND APP_PLATFORM_INCLUDE ${MPV_INCLUDE_DIR})
Expand Down Expand Up @@ -218,18 +222,16 @@ if (PLATFORM_DESKTOP)

if (APPLE)
if (MAC_DOWNLOAD_DYLIB)
# Download macos dylib dependencies if require
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
set(bundle_args1 "-nb")
set(bundle_args2 "${MACOS_DYLIB_DIR}")
set(bundle_args2 "${CMAKE_BINARY_DIR}/deps/lib")
else ()
# Use system provided dylib
set(bundle_args1 "-b")
set(bundle_args2 "system")
endif ()
add_custom_target(
${PROJECT_NAME}.app
COMMAND "bash" "${CMAKE_BINARY_DIR}/../scripts/build_mac.sh" "${bundle_args1}" "${bundle_args2}" "${APP_VERSION}"
COMMAND "bash" "${CMAKE_SOURCE_DIR}/scripts/build_mac.sh" "${bundle_args1}" "${bundle_args2}" "${APP_VERSION}"
)
add_dependencies(${PROJECT_NAME}.app ${PROJECT_NAME})
elseif (UNIX AND INSTALL)
Expand Down
47 changes: 27 additions & 20 deletions cmake/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# x86_64: 10.11
# universal: arm64 + x86_64

# header files: `brew tap xfangfang/wiliwili && brew install mpv-wiliwili webp boost`

if (APPLE)

if (MAC_IntelChip)
Expand All @@ -15,23 +13,32 @@ if (APPLE)
set(MAC_OS_ARCH universal)
endif ()

if (MAC_DOWNLOAD_DYLIB)
set(APP_PLATFORM_LIB
${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}/libmpv.2.dylib
${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}/libwebp.7.1.8.dylib
${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}/libboost_filesystem-mt.dylib)
if (NOT USE_SYSTEM_CURL)
list(APPEND APP_PLATFORM_LIB
${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}/libssl.3.dylib
${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}/libcrypto.3.dylib)
endif ()

# download deps
add_custom_target(
${PROJECT_NAME}.macos_${MAC_OS_ARCH}_deps
COMMAND "bash" "${CMAKE_BINARY_DIR}/../scripts/macos_dylib_downloader.sh" "${MAC_OS_ARCH}"
)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.macos_${MAC_OS_ARCH}_deps)
set(MACOS_DYLIB_DIR "${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}")
if (NOT DISABLE_WEBP)
list(APPEND APP_PLATFORM_OPTION -DUSE_WEBP)
list(APPEND APP_PLATFORM_LIB ${CMAKE_BINARY_DIR}/deps/lib/libwebp.7.1.9.dylib)
endif ()

list(APPEND APP_PLATFORM_LIB
${CMAKE_BINARY_DIR}/deps/lib/libmpv.2.dylib
${CMAKE_BINARY_DIR}/deps/lib/libboost_filesystem-mt.dylib
${CMAKE_BINARY_DIR}/deps/lib/libssl.3.dylib
${CMAKE_BINARY_DIR}/deps/lib/libcrypto.3.dylib)
list(APPEND APP_PLATFORM_INCLUDE
${CMAKE_BINARY_DIR}/deps/include)

# download deps
include(FetchContent)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(macos_prebuild
URL "https://github.com/xfangfang/wiliwili/releases/download/v0.1.0/macos_dylib_ffmpeg7_mpv38_${MAC_OS_ARCH}.tar.gz"
)
if (NOT macos_prebuild_POPULATED)
FetchContent_POPULATE(macos_prebuild)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/deps)
file(COPY ${macos_prebuild_SOURCE_DIR}/lib DESTINATION ${CMAKE_BINARY_DIR}/deps)
file(COPY ${macos_prebuild_SOURCE_DIR}/include DESTINATION ${CMAKE_BINARY_DIR}/deps)
endif()

endif ()
3 changes: 2 additions & 1 deletion scripts/build_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ else
bundle_deps="-b"
else
echo "bundle deps: $2"
cp -r "$2" "${APP_PATH}"/Contents/MacOS/lib
mkdir -p "${APP_PATH}"/Contents/MacOS/lib
cp "$2"/*.dylib "${APP_PATH}"/Contents/MacOS/lib
fi
dylibbundler -cd ${bundle_deps} -x "${APP_PATH}"/Contents/MacOS/wiliwili \
-d "${APP_PATH}"/Contents/MacOS/lib/ -p @executable_path/lib/
Expand Down
20 changes: 0 additions & 20 deletions scripts/macos_dylib_downloader.sh

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/macos_dylib_include.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

boost_version="1.85.0"
webp_version="1.4.0"
mpv_version="0.38.0"

# cd to wiliwili" "
cd "$(dirname "$0")/.." || exit

rm -rf include
mkdir -p include

boost_item=("filesystem" "system" "config" "assert" "iterator" "type_traits" "mpl" "preprocessor" "static_assert" "core" "detail" "io" "functional" "container_hash" "smart_ptr")
for item in "${boost_item[@]}"
do
url="https://github.com/boostorg/$item/archive/refs/tags/boost-$boost_version.zip"
curl -L -o boost.zip "$url"
unzip -q boost.zip
dir_name=$(unzip -Z -1 boost.zip | head -1 | cut -d " " -f 1)
echo "$dir_name"
cp -r "$dir_name"/include/boost include
rm boost.zip
rm -r "$dir_name"
done

curl -L -o webp.zip "https://github.com/webmproject/libwebp/archive/refs/tags/v$webp_version.zip"
unzip -q webp.zip
dir_name=$(unzip -Z -1 webp.zip | head -1 | cut -d " " -f 1)
echo "$dir_name"
cp -r "$dir_name"/src/webp include
rm webp.zip
rm -r "$dir_name"

curl -L -o mpv.zip "https://github.com/mpv-player/mpv/archive/refs/tags/v$mpv_version.zip"
unzip -q mpv.zip
dir_name=$(unzip -Z -1 mpv.zip | head -1 | cut -d " " -f 1)
echo "$dir_name"
cp -r "$dir_name"/libmpv include
mv include/libmpv include/mpv
rm mpv.zip
rm -r "$dir_name"
39 changes: 24 additions & 15 deletions scripts/macos_dylib_merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
set -e

files=(libass.9.dylib
libavcodec.60.31.102.dylib
libavdevice.60.3.100.dylib
libavfilter.9.12.100.dylib
libavformat.60.16.100.dylib
libavutil.58.29.100.dylib
libavcodec.61.3.100.dylib
libavdevice.61.1.100.dylib
libavfilter.10.1.100.dylib
libavformat.61.1.100.dylib
libavutil.59.8.100.dylib
libboost_atomic-mt.dylib
libboost_filesystem-mt.dylib
libcrypto.3.dylib
libdav1d.6.dylib
libdav1d.7.dylib
libfontconfig.1.dylib
libfreetype.6.dylib
libfribidi.0.dylib
Expand All @@ -19,22 +19,27 @@ files=(libass.9.dylib
libgnutls.30.dylib
libgraphite2.3.2.1.dylib
libharfbuzz.0.dylib
libhogweed.6.8.dylib
libhogweed.6.9.dylib
libidn2.0.dylib
libintl.8.dylib
libjpeg.8.3.2.dylib
liblcms2.2.dylib
libmpv.2.dylib
libnettle.8.8.dylib
libnettle.8.9.dylib
libp11-kit.0.dylib
libpcre2-8.0.dylib
libplacebo.338.dylib
libpng16.16.dylib
libsharpyuv.0.0.1.dylib
libshaderc_shared.1.dylib
libsharpyuv.0.1.0.dylib
libssl.3.dylib
libswresample.4.12.100.dylib
libswscale.7.5.100.dylib
libswresample.5.1.100.dylib
libswscale.8.1.100.dylib
libtasn1.6.dylib
libunibreak.5.dylib
libunibreak.6.dylib
libunistring.5.dylib
libwebp.7.1.8.dylib)
libvulkan.1.3.280.dylib
libwebp.7.1.9.dylib)

rm -rf ./universal
mkdir -p ./universal
Expand All @@ -57,12 +62,16 @@ for file in "${files[@]}"; do
((i++))
done

output_name="macos_dylib_ffmpeg61_mpv36"
cp -r ./arm64/cmake ./universal/

output_name="macos_dylib_ffmpeg7_mpv38"
arch_list=("arm64" "x86_64" "universal")
for i in "${arch_list[@]}";
do
echo "$i";
mv "${i}" lib
package_name="${output_name}_${i}.tar.gz"
rm -rf "$package_name"
tar -czvf "$package_name" "${i}"
tar -czvf "$package_name" lib include
mv lib "${i}"
done

0 comments on commit 3de6531

Please sign in to comment.