Files
EchoionCore/cmake/BundleFFmpeg.cmake
T
2026-02-03 05:07:15 +03:00

49 lines
1.5 KiB
CMake

# BundleFFmpeg.cmake - Helper to bundle FFmpeg libraries on install
function(bundle_ffmpeg_libraries target)
if(NOT TARGET ${target})
return()
endif()
if(UNIX AND NOT APPLE)
# Create post-install script to copy FFmpeg libs
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/bundle_ffmpeg_$<CONFIG>.sh
CONTENT "#!/bin/bash
# Bundle FFmpeg libraries
set -e
dest_dir=\"$1\"
mkdir -p \"\$dest_dir\"
# Find FFmpeg libraries
ffmpeg_libs=($(pkg-config --libs-only-L libavformat libavcodec libswresample libavutil 2>/dev/null | sed 's/-L//g'))
for libdir in \"\${ffmpeg_libs[@]}\" /usr/lib /usr/local/lib; do
if [ -d \"\$libdir\" ]; then
for lib in avformat avcodec swresample avutil; do
# Try different naming conventions
for pattern in \"lib\${lib}.so*\" \"lib\${lib}-*.so*\"; do
for file in \$libdir/\$pattern; do
if [ -f \"\$file\" ] && [ ! -L \"\$file\" ]; then
cp -v \"\$file\" \"\$dest_dir/\" 2>/dev/null || true
fi
done
done
done
fi
done
echo \"FFmpeg libraries bundled to \$dest_dir\"
"
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
)
install(CODE "
execute_process(
COMMAND ${CMAKE_BINARY_DIR}/bundle_ffmpeg_$<CONFIG>.sh \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\"
ERROR_QUIET
)
")
endif()
endfunction()