Atlas - FindFFmpeg.cmake
Home / ext / SDL / cmake Lines: 1 | Size: 5429 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC) 2# 3# Once done this will define 4# FFMPEG_FOUND - System has the all required components. 5# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components. 6# 7# For each of the components it will additionally set. 8# - AVCODEC 9# - AVDEVICE 10# - AVFORMAT 11# - AVFILTER 12# - AVUTIL 13# - POSTPROC 14# - SWSCALE 15# the following target will be defined 16# FFmpeg::SDL::<component> - link to this target to 17# the following variables will be defined 18# FFmpeg_<component>_FOUND - System has <component> 19# FFmpeg_<component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers 20# FFmpeg_<component>_LIBRARIES - Link these to use <component> 21# FFmpeg_<component>_DEFINITIONS - Compiler switches required for using <component> 22# FFmpeg_<component>_VERSION - The components version 23# 24# Copyright (c) 2006, Matthias Kretz, <[email protected]> 25# Copyright (c) 2008, Alexander Neundorf, <[email protected]> 26# Copyright (c) 2011, Michael Jansen, <[email protected]> 27# Copyright (c) 2023, Sam lantinga, <[email protected]> 28# 29# Redistribution and use is allowed according to the terms of the BSD license. 30# For details see the accompanying COPYING-CMAKE-SCRIPTS file. 31 32include(FindPackageHandleStandardArgs) 33include("${CMAKE_CURRENT_LIST_DIR}/PkgConfigHelper.cmake") 34 35# The default components were taken from a survey over other FindFFMPEG.cmake files 36if(NOT FFmpeg_FIND_COMPONENTS) 37 set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) 38 foreach(_component IN LISTS FFmpeg_FIND_COMPONENTS) 39 set(FFmpeg_FIND_REQUIRED_${_component} TRUE) 40 endforeach() 41endif() 42 43find_package(PkgConfig QUIET) 44 45# 46### Macro: find_component 47# 48# Checks for the given component by invoking pkgconfig and then looking up the libraries and 49# include directories. 50# 51macro(find_component _component _pkgconfig _library _header) 52 53 # use pkg-config to get the directories and then use these values 54 # in the FIND_PATH() and FIND_LIBRARY() calls 55 if(PKG_CONFIG_FOUND) 56 pkg_check_modules(PC_${_component} QUIET ${_pkgconfig}) 57 endif() 58 59 find_path(FFmpeg_${_component}_INCLUDE_DIRS 60 NAMES ${_header} 61 HINTS 62 ${PC_${_component}_INCLUDE_DIRS} 63 PATH_SUFFIXES 64 ffmpeg 65 ) 66 67 find_library(FFmpeg_${_component}_LIBRARY 68 NAMES ${_library} 69 HINTS 70 ${PC_${_component}_LIBRARY_DIRS} 71 ) 72 73 if(FFmpeg_${_component}_INCLUDE_DIRS AND FFmpeg_${_component}_LIBRARY) 74 set(FFmpeg_${_component}_FOUND TRUE) 75 endif() 76 77 if(PC_${_component}_FOUND) 78 get_flags_from_pkg_config("${FFmpeg_${_component}_LIBRARY}" "PC_${_component}" "${_component}") 79 endif() 80 81 set(FFmpeg_${_component}_VERSION "${PC_${_component}_VERSION}") 82 83 set(FFmpeg_${_component}_COMPILE_OPTIONS "${${_component}_options}" CACHE STRING "Extra compile options of FFmpeg ${_component}") 84 85 set(FFmpeg_${_component}_LIBRARIES "${${_component}_link_libraries}" CACHE STRING "Extra link libraries of FFmpeg ${_component}") 86 87 set(FFmpeg_${_component}_LINK_OPTIONS "${${_component}_link_options}" CACHE STRING "Extra link flags of FFmpeg ${_component}") 88 89 set(FFmpeg_${_component}_LINK_DIRECTORIES "${${_component}_link_directories}" CACHE PATH "Extra link directories of FFmpeg ${_component}") 90 91 mark_as_advanced( 92 FFmpeg_${_component}_INCLUDE_DIRS 93 FFmpeg_${_component}_LIBRARY 94 FFmpeg_${_component}_COMPILE_OPTIONS 95 FFmpeg_${_component}_LIBRARIES 96 FFmpeg_${_component}_LINK_OPTIONS 97 FFmpeg_${_component}_LINK_DIRECTORIES 98 ) 99endmacro() 100 101# Check for all possible component. 102find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) 103find_component(AVFORMAT libavformat avformat libavformat/avformat.h) 104find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) 105find_component(AVUTIL libavutil avutil libavutil/avutil.h) 106find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h) 107find_component(SWSCALE libswscale swscale libswscale/swscale.h) 108find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h) 109find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h) 110 111# Compile the list of required vars 112set(_FFmpeg_REQUIRED_VARS) 113foreach(_component ${FFmpeg_FIND_COMPONENTS}) 114 list(APPEND _FFmpeg_REQUIRED_VARS FFmpeg_${_component}_INCLUDE_DIRS FFmpeg_${_component}_LIBRARY) 115endforeach () 116 117# Give a nice error message if some of the required vars are missing. 118find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) 119 120set(FFMPEG_LIBRARIES) 121if(FFmpeg_FOUND) 122 foreach(_component IN LISTS FFmpeg_FIND_COMPONENTS) 123 if(FFmpeg_${_component}_FOUND) 124 list(APPEND FFMPEG_LIBRARIES FFmpeg::SDL::${_component}) 125 if(NOT TARGET FFmpeg::SDL::${_component}) 126 add_library(FFmpeg::SDL::${_component} UNKNOWN IMPORTED) 127 set_target_properties(FFmpeg::SDL::${_component} PROPERTIES 128 IMPORTED_LOCATION "${FFmpeg_${_component}_LIBRARY}" 129 INTERFACE_INCLUDE_DIRECTORIES "${FFmpeg_${_component}_INCLUDE_DIRS}" 130 INTERFACE_COMPILE_OPTIONS "${FFmpeg_${_component}_COMPILE_OPTIONS}" 131 INTERFACE_LINK_LIBRARIES "${FFmpeg_${_component}_LIBRARIES}" 132 INTERFACE_LINK_OPTIONS "${FFmpeg_${_component}_LINK_OPTIONS}" 133 INTERFACE_LINK_DIRECTORIES "${FFmpeg_${_component}_LINK_DIRECTORIES}" 134 ) 135 endif() 136 endif() 137 endforeach() 138endif() 139[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.