From eb868055b78ad68357eb8ef9c4d8c7dd23bdec32 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 10 May 2021 21:58:14 +0200 Subject: [PATCH] Replaced the CMake find module for FFmpeg. --- CMake/Packages/FindFFmpeg.cmake | 178 ++++++++++++++++++-------------- CMakeLists.txt | 2 +- 2 files changed, 100 insertions(+), 80 deletions(-) diff --git a/CMake/Packages/FindFFmpeg.cmake b/CMake/Packages/FindFFmpeg.cmake index b97210742..be87f7b25 100644 --- a/CMake/Packages/FindFFmpeg.cmake +++ b/CMake/Packages/FindFFmpeg.cmake @@ -1,88 +1,108 @@ -# Copyright (c) 2014 Matt Coffin +# Locate ffmpeg +# This module defines +# FFMPEG_LIBRARIES +# FFMPEG_FOUND, if false, do not try to link to ffmpeg +# FFMPEG_INCLUDE_DIR, where to find the headers # -# This software is provided 'as-is', without any express or implied -# warranty. In no event will the authors be held liable for any damages -# arising from the use of this software. +# $FFMPEG_DIR is an environment variable that would +# correspond to the ./configure --prefix=$FFMPEG_DIR # -# Permission is granted to anyone to use this software for any purpose, -# including commercial applications, and to alter it and redistribute it -# freely, subject to the following restrictions: -# -# 1. The origin of this software must not be misrepresented; you must not -# claim that you wrote the original software. If you use this software -# in a product, an acknowledgment in the product documentation would be -# appreciated but is not required. -# 2. Altered source versions must be plainly marked as such, and must not be -# misrepresented as being the original software. -# 3. This notice may not be removed or altered from any source distribution. +# Created by Robert Osfield. +# Modified by Lukas Lalinsky. -# - Try to find FFmpeg -# Once done this will define -# FFmpeg_FOUND -# FFmpeg_INCLUDE_DIRS -# FFmpeg_LIBRARIES -# FFmpeg_INCLUDE_FILES -# Author: Matt Coffin +# In ffmpeg code, old version use "#include " and newer use "#include " +# In OSG ffmpeg plugin, we use "#include " for compatibility with old version of ffmpeg -include(FindPackageHandleStandardArgs) +# We have to search the path which contain the header.h (usefull for old version) +# and search the path which contain the libname/header.h (usefull for new version) -if (NOT FFmpeg_FIND_COMPONENTS) - set(FFmpeg_FIND_COMPONENTS avcodec avformat avutil swresample swscale) -endif(NOT FFmpeg_FIND_COMPONENTS) +# Then we need to include ${FFMPEG_libname_INCLUDE_DIRS} +# (in old version case, use by ffmpeg header and osg plugin code) +# (in new version case, use by ffmpeg header) +# and ${FFMPEG_libname_INCLUDE_DIRS/libname} +# (in new version case, use by osg plugin code) -# Generate component include files and requirements -foreach(comp ${FFmpeg_FIND_COMPONENTS}) - if(FFmpeg_FIND_REQUIRED_${comp}) - list(APPEND required "FFmpeg_${comp}_FOUND") - endif() -endforeach(comp) +# Macro to find header and lib directories +# example: FFMPEG_FIND(AVFORMAT avformat avformat.h) +MACRO(FFMPEG_FIND varname shortname headername) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(_lib_suffix 64) -else() - set(_lib_suffix 32) -endif() + FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername} + PATHS + ${FFMPEG_ROOT}/include + $ENV{FFMPEG_DIR}/include + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include + /usr/include/ + /sw/include # Fink + /opt/local/include # DarwinPorts + /opt/csw/include # Blastwave + /opt/include + /usr/freeware/include + NO_DEFAULT_PATH + PATH_SUFFIXES ffmpeg + DOC "Location of FFMPEG Headers" + ) + FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername} + PATH_SUFFIXES ffmpeg + DOC "Location of FFMPEG Headers" + ) -set(FFMPEG_PATH_ARCH FFmpegPath${_lib_suffix}) -# Find libraries -find_package(PkgConfig QUIET) -foreach(comp ${FFmpeg_FIND_COMPONENTS}) - if(PKG_CONFIG_FOUND) - pkg_check_modules(_${comp} QUIET lib${comp}) - endif() - find_path(FFmpeg_${comp}_INCLUDE_DIR - NAMES "lib${comp}/${comp}.h" - HINTS - ${_${comp}_INCLUDE_DIRS} - ENV FFmpegPath - ENV ${FFMPEG_PATH_ARCH} - PATHS - /usr/include /usr/local/include /opt/local/include /sw/include - PATH_SUFFIXES ffmpeg libav - DOC "FFmpeg include directory") - find_library(FFmpeg_${comp}_LIBRARY - NAMES ${comp} ${comp}-ffmpeg ${_${comp}_LIBRARIES} - HINTS - ${_${comp}_LIBRARY_DIRS} - "${FFmpeg_${comp}_INCLUDE_DIR}/../lib" - "${FFmpeg_${comp}_INCLUDE_DIR}/../lib${_lib_suffix}" - "${FFmpeg_${comp}_INCLUDE_DIR}/../libs${_lib_suffix}" - "${FFmpeg_${comp}_INCLUDE_DIR}/lib" - "${FFmpeg_${comp}_INCLUDE_DIR}/lib${_lib_suffix}" - PATHS - /usr/lib /usr/local/lib /opt/local/lib /sw/lib - PATH_SUFFIXES ${comp} lib${comp} - DOC "FFmpeg ${comp} library") - find_package_handle_standard_args(FFmpeg_${comp} - FOUND_VAR FFmpeg_${comp}_FOUND - REQUIRED_VARS FFmpeg_${comp}_LIBRARY FFmpeg_${comp}_INCLUDE_DIR) - if(${FFmpeg_${comp}_FOUND}) - list(APPEND FFmpeg_INCLUDE_DIRS ${FFmpeg_${comp}_INCLUDE_DIR}) - list(APPEND FFmpeg_LIBRARIES ${FFmpeg_${comp}_LIBRARY}) - endif() -endforeach(comp) + pkg_check_modules(FFMPEG_${varname} lib${shortname}) -# Run checks via find_package_handle_standard_args -find_package_handle_standard_args(FFmpeg - FOUND_VAR FFmpeg_FOUND - REQUIRED_VARS ${required} FFmpeg_INCLUDE_DIRS FFmpeg_LIBRARIES) \ No newline at end of file + IF (FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS) + SET(FFMPEG_${varname}_FOUND 1) + ENDIF(FFMPEG_${varname}_LIBRARIES AND FFMPEG_${varname}_INCLUDE_DIRS) + +ENDMACRO(FFMPEG_FIND) + +SET(FFMPEG_ROOT "$ENV{FFMPEG_DIR}" CACHE PATH "Location of FFMPEG") + +# find stdint.h +FIND_PATH(FFMPEG_STDINT_INCLUDE_DIR stdint.h + PATHS + ${FFMPEG_ROOT}/include + $ENV{FFMPEG_DIR}/include + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include + /usr/include + /sw/include # Fink + /opt/local/include # DarwinPorts + /opt/csw/include # Blastwave + /opt/include + /usr/freeware/include + PATH_SUFFIXES ffmpeg + DOC "Location of FFMPEG stdint.h Header" +) + +FFMPEG_FIND(LIBAVFORMAT avformat avformat.h) +FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h) +FFMPEG_FIND(LIBAVCODEC avcodec avcodec.h) +FFMPEG_FIND(LIBAVCODEC_FFT avcodec avfft.h) +FFMPEG_FIND(LIBAVUTIL avutil avutil.h) +FFMPEG_FIND(LIBSWRESAMPLE swresample swresample.h) +FFMPEG_FIND(LIBSWSCALE swscale swscale.h) # Not sure about the header to look for here. + +SET(FFMPEG_FOUND "NO") + +IF (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVDEVICE_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND + FFMPEG_LIBAVUTIL_FOUND AND FFMPEG_LIBSWRESAMPLE_FOUND AND FFMPEG_LIBSWSCALE_FOUND AND + FFMPEG_STDINT_INCLUDE_DIR) + + SET(FFMPEG_FOUND "YES") + SET(FFMPEG_INCLUDE_DIRS ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}) + SET(FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBAVFORMAT_LIBRARY_DIRS}) + + SET(FFMPEG_LIBRARIES + ${FFMPEG_LIBAVFORMAT_LIBRARIES} + ${FFMPEG_LIBAVDEVICE_LIBRARIES} + ${FFMPEG_LIBAVCODEC_LIBRARIES} + ${FFMPEG_LIBAVUTIL_LIBRARIES} + ${FFMPEG_LIBSWRESAMPLE_LIBRARIES} + ${FFMPEG_LIBSWSCALE_LIBRARIES}) +ELSE () + +# MESSAGE(STATUS "Could not find FFMPEG") + +ENDIF() diff --git a/CMakeLists.txt b/CMakeLists.txt index 98cc1fbf2..e365f7952 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,7 +282,7 @@ endif() if(NOT WIN32) set(COMMON_LIBRARIES ${CURL_LIBRARIES} - ${FFmpeg_LIBRARIES} + ${FFMPEG_LIBRARIES} ${FreeImage_LIBRARIES} ${FREETYPE_LIBRARIES} ${PUGIXML_LIBRARIES}