From 6eb355e15f9841d84d47c8403b9e7db1fff5e444 Mon Sep 17 00:00:00 2001 From: Alexandre Bouvier Date: Fri, 16 Aug 2024 15:56:47 +0000 Subject: [PATCH] cmake: prefer system ffmpeg library (#451) --- CMakeLists.txt | 3 ++- cmake/FindFFmpeg.cmake | 23 +++++++++++++++++++++++ externals/CMakeLists.txt | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 cmake/FindFFmpeg.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ff03befc..009006a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp.in" "${CMAKE_ find_package(Boost 1.84.0 CONFIG) find_package(cryptopp 8.9.0 MODULE) +find_package(FFmpeg 5.1.2 MODULE) find_package(fmt 10.2.1 CONFIG) find_package(glslang 14.2.0 CONFIG) find_package(magic_enum 0.9.6 CONFIG) @@ -607,7 +608,7 @@ endif() create_target_directory_groups(shadps4) -target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API ffmpeg) +target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API FFmpeg::ffmpeg) target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::SPIRV glslang::glslang SDL3::SDL3) if (APPLE) diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake new file mode 100644 index 00000000..9c45844b --- /dev/null +++ b/cmake/FindFFmpeg.cmake @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + +find_package(PkgConfig QUIET) +pkg_check_modules(FFMPEG QUIET IMPORTED_TARGET libavcodec libavfilter libavformat libavutil libswresample libswscale) + +find_file(FFMPEG_VERSION_FILE libavutil/ffversion.h HINTS "${FFMPEG_libavutil_INCLUDEDIR}") +if (FFMPEG_VERSION_FILE) + file(STRINGS "${FFMPEG_VERSION_FILE}" FFMPEG_VERSION_LINE REGEX "FFMPEG_VERSION") + string(REGEX MATCH "[0-9.]+" FFMPEG_VERSION "${FFMPEG_VERSION_LINE}") + unset(FFMPEG_VERSION_LINE) + unset(FFMPEG_VERSION_FILE) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FFmpeg + REQUIRED_VARS FFMPEG_LINK_LIBRARIES + VERSION_VAR FFMPEG_VERSION +) + +if (FFmpeg_FOUND AND NOT TARGET FFmpeg::ffmpeg) + add_library(FFmpeg::ffmpeg ALIAS PkgConfig::FFMPEG) +endif() diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index bc313232..0b19034d 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -47,9 +47,10 @@ else() endif() endif() -if (NOT TARGET ffmpeg) +if (NOT TARGET FFmpeg::ffmpeg) set(ARCHITECTURE "x86_64") add_subdirectory(ffmpeg-core) + add_library(FFmpeg::ffmpeg ALIAS ffmpeg) endif() # Zlib-Ng