From f48d3b4636ee3e184d727c383523a145c5393159 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 12 Aug 2024 22:16:15 +1000 Subject: [PATCH] CMake: Copy FFmpeg dylibs into Mac bundle --- CMakeModules/FindFFMPEG.cmake | 18 +++++++++++++++++- src/util/CMakeLists.txt | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CMakeModules/FindFFMPEG.cmake b/CMakeModules/FindFFMPEG.cmake index 4c6da416b..1f8a31351 100644 --- a/CMakeModules/FindFFMPEG.cmake +++ b/CMakeModules/FindFFMPEG.cmake @@ -97,7 +97,23 @@ function (_ffmpeg_find component headername) PARENT_SCOPE) set(version_header_path "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version.h") - if (EXISTS "${version_header_path}") + set(major_version_header_path "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version_major.h") + if (EXISTS "${major_version_header_path}") + string(TOUPPER "${component}" component_upper) + file(STRINGS "${major_version_header_path}" major_version + REGEX "#define *LIB${component_upper}_VERSION_MAJOR ") + file(STRINGS "${version_header_path}" version + REGEX "#define *LIB${component_upper}_VERSION_(MINOR|MICRO) ") + string(REGEX REPLACE ".*_MAJOR *\([0-9]*\).*" "\\1" major "${major_version}") + string(REGEX REPLACE ".*_MINOR *\([0-9]*\).*" "\\1" minor "${version}") + string(REGEX REPLACE ".*_MICRO *\([0-9]*\).*" "\\1" micro "${version}") + if (NOT major STREQUAL "" AND + NOT minor STREQUAL "" AND + NOT micro STREQUAL "") + set("FFMPEG_${component}_VERSION" "${major}.${minor}.${micro}" + PARENT_SCOPE) + endif () + elseif (EXISTS "${version_header_path}") string(TOUPPER "${component}" component_upper) file(STRINGS "${version_header_path}" version REGEX "#define *LIB${component_upper}_VERSION_(MAJOR|MINOR|MICRO) ") diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 7e8eb4405..41115bdcd 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -294,7 +294,15 @@ function(add_util_resources target) # Copy shaderc into the bundle get_target_property(SPIRV_CROSS_LIBRARY spirv-cross-c-shared IMPORTED_SONAME_RELEASE) - target_sources(duckstation-qt PRIVATE "${SHADERC_LIBRARY}" "${SPIRV_CROSS_LIBRARY}") + target_sources(${target} PRIVATE "${SHADERC_LIBRARY}" "${SPIRV_CROSS_LIBRARY}") set_source_files_properties("${SHADERC_LIBRARY}" "${SPIRV_CROSS_LIBRARY}" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks) + + # Copy FFmpeg libraries into the bundle + foreach(component avcodec avformat avutil swresample swscale) + string(REGEX REPLACE "\([0-9]+\)\.[0-9]+\.[0-9]+" "\\1" major "${FFMPEG_${component}_VERSION}") + string(REPLACE "lib${component}.dylib" "lib${component}.${major}.dylib" version_lib "${FFMPEG_${component}_LIBRARIES}") + target_sources(${target} PRIVATE ${version_lib}) + set_source_files_properties(${target} PRIVATE ${version_lib} PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks) + endforeach() endif() endfunction()