cmake: Replace FFMpeg modules with single module

Now using components instead of one find_package call per module
This commit is contained in:
BtbN
2014-09-23 15:26:08 +02:00
committed by jp9000
parent c9d3c6c8c1
commit 599febcb54
10 changed files with 184 additions and 323 deletions

View File

@@ -25,22 +25,29 @@ find_package(Libfdk QUIET)
find_package(Qt5Core QUIET)
file(GLOB FFMPEG_BIN_FILES
"${FFMPEG_INCLUDE_DIR}/../bin${_bin_suffix}/av*-*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin${_bin_suffix}/sw*-*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin${_bin_suffix}/libbz2*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin${_bin_suffix}/zlib*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin/av*-*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin/sw*-*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin/libbz2*.dll"
"${FFMPEG_INCLUDE_DIR}/../bin/zlib*.dll"
"${FFMPEG_INCLUDE_DIR}/bin/av*-*.dll"
"${FFMPEG_INCLUDE_DIR}/bin/sw*-*.dll"
"${FFMPEG_INCLUDE_DIR}/bin/libbz2*.dll"
"${FFMPEG_INCLUDE_DIR}/bin/zlib*.dll"
"${FFMPEG_INCLUDE_DIR}/bin${_bin_suffix}/av*-*.dll"
"${FFMPEG_INCLUDE_DIR}/bin${_bin_suffix}/sw*-*.dll"
"${FFMPEG_INCLUDE_DIR}/bin${_bin_suffix}/libbz2*.dll"
"${FFMPEG_INCLUDE_DIR}/bin${_bin_suffix}/zlib*.dll")
"${FFMPEG_avutil_INCLUDE_DIR}/../bin${_bin_suffix}/avutil-*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/../bin${_bin_suffix}/avcodec-*.dll"
"${FFMPEG_avformat_INCLUDE_DIR}/../bin${_bin_suffix}/avformat-*.dll"
"${FFMPEG_swscale_INCLUDE_DIR}/../bin${_bin_suffix}/swscale-*.dll"
"${FFMPEG_swresample_INCLUDE_DIR}/../bin${_bin_suffix}/swresample-*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/../bin${_bin_suffix}/libbz2*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/../bin${_bin_suffix}/zlib*.dll"
"${FFMPEG_avutil_INCLUDE_DIR}/../bin/avutil-*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/../bin/avcodec-*.dll"
"${FFMPEG_avformat_INCLUDE_DIR}/../bin/avformat-*.dll"
"${FFMPEG_swscale_INCLUDE_DIR}/../bin/swscale-*.dll"
"${FFMPEG_swresample_INCLUDE_DIR}/../bin/swresample-*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/../bin/libbz2*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/../bin/zlib*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/bin/libbz2*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/bin/zlib*.dll"
"${FFMPEG_avutil_INCLUDE_DIR}/bin${_bin_suffix}/avutil-*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/bin${_bin_suffix}/avcodec-*.dll"
"${FFMPEG_avformat_INCLUDE_DIR}/bin${_bin_suffix}/avformat-*.dll"
"${FFMPEG_swscale_INCLUDE_DIR}/bin${_bin_suffix}/swscale-*.dll"
"${FFMPEG_swresample_INCLUDE_DIR}/bin${_bin_suffix}/swresample-*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/bin${_bin_suffix}/libbz2*.dll"
"${FFMPEG_avcodec_INCLUDE_DIR}/bin${_bin_suffix}/zlib*.dll")
file(GLOB X264_BIN_FILES
"${X264_INCLUDE_DIR}/../bin${_bin_suffix}/libx264-*.dll"

View File

@@ -0,0 +1,139 @@
#
# This module defines the following variables:
#
# FFMPEG_FOUND - All required components and the core library were found
# FFMPEG_INCLUDE_DIRS - Combined list of all components include dirs
# FFMPEG_LIBRARIES - Combined list of all componenets libraries
# FFMPEG_VERSION_STRING - Version of the first component requested
#
# For each requested component the following variables are defined:
#
# FFMPEG_<component>_FOUND - The component was found
# FFMPEG_<component>_INCLUDE_DIRS - The components include dirs
# FFMPEG_<component>_LIBRARIES - The components libraries
# FFMPEG_<component>_VERSION_STRING - The components version string
# FFMPEG_<component>_VERSION_MAJOR - The components major version
# FFMPEG_<component>_VERSION_MINOR - The components minor version
# FFMPEG_<component>_VERSION_MICRO - The components micro version
#
# <component> is the uppercase name of the component
find_package(PkgConfig QUIET)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()
function(find_ffmpeg_library component header)
string(TOUPPER "${component}" component_u)
set(FFMPEG_${component_u}_FOUND FALSE PARENT_SCOPE)
set(FFMpeg_${component}_FOUND FALSE PARENT_SCOPE)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_FFMPEG_${component} QUIET lib${component})
endif()
find_path(FFMPEG_${component}_INCLUDE_DIR
NAMES
"lib${component}/${header}" "lib${component}/version.h"
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${PC_FFMPEG_${component}_INCLUDE_DIRS}
PATH_SUFFIXES ffmpeg libav)
find_library(FFMPEG_${component}_LIBRARY
NAMES
"${component}" "lib${component}"
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${PC_FFMPEG_${component}_LIBRARY_DIRS}
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin
../lib${_lib_suffix} ../lib
../libs${_lib_suffix} ../libs
../bin${_lib_suffix} ../bin)
set(FFMPEG_${component_u}_INCLUDE_DIRS ${FFMPEG_${component}_INCLUDE_DIR} PARENT_SCOPE)
set(FFMPEG_${component_u}_LIBRARIES ${FFMPEG_${component}_LIBRARY} PARENT_SCOPE)
mark_as_advanced(FFMPEG_${component}_INCLUDE_DIR FFMPEG_${component}_LIBRARY)
if(FFMPEG_${component}_INCLUDE_DIR AND FFMPEG_${component}_LIBRARY)
set(FFMPEG_${component_u}_FOUND TRUE PARENT_SCOPE)
set(FFMpeg_${component}_FOUND TRUE PARENT_SCOPE)
list(APPEND FFMPEG_INCLUDE_DIRS ${FFMPEG_${component}_INCLUDE_DIR})
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
set(FFMPEG_INCLUDE_DIRS "${FFMPEG_INCLUDE_DIRS}" PARENT_SCOPE)
list(APPEND FFMPEG_LIBRARIES ${FFMPEG_${component}_LIBRARY})
list(REMOVE_DUPLICATES FFMPEG_LIBRARIES)
set(FFMPEG_LIBRARIES "${FFMPEG_LIBRARIES}" PARENT_SCOPE)
set(FFMPEG_${component_u}_VERSION_STRING "unknown" PARENT_SCOPE)
set(_vfile "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version.h")
if(EXISTS "${_vfile}")
file(STRINGS "${_vfile}" _version_parse REGEX "^.*VERSION_(MAJOR|MINOR|MICRO)[ \t]+[0-9]+[ \t]*$")
string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _major "${_version_parse}")
string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _minor "${_version_parse}")
string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" _micro "${_version_parse}")
set(FFMPEG_${component_u}_VERSION_MAJOR "${_major}" PARENT_SCOPE)
set(FFMPEG_${component_u}_VERSION_MINOR "${_minor}" PARENT_SCOPE)
set(FFMPEG_${component_u}_VERSION_MICRO "${_micro}" PARENT_SCOPE)
set(FFMPEG_${component_u}_VERSION_STRING "${_major}.${_minor}.${_micro}" PARENT_SCOPE)
else()
message(STATUS "Failed parsing FFMpeg ${component} version")
endif()
endif()
endfunction()
set(FFMPEG_INCLUDE_DIRS)
set(FFMPEG_LIBRARIES)
if(NOT FFMpeg_FIND_COMPONENTS)
message(FATAL_ERROR "No FFMpeg components requested")
endif()
list(GET FFMpeg_FIND_COMPONENTS 0 _first_comp)
string(TOUPPER "${_first_comp}" _first_comp)
foreach(component ${FFMpeg_FIND_COMPONENTS})
if(component STREQUAL "avcodec")
find_ffmpeg_library("${component}" "avcodec.h")
elseif(component STREQUAL "avdevice")
find_ffmpeg_library("${component}" "avdevice.h")
elseif(component STREQUAL "avfilter")
find_ffmpeg_library("${component}" "avfilter.h")
elseif(component STREQUAL "avformat")
find_ffmpeg_library("${component}" "avformat.h")
elseif(component STREQUAL "avresample")
find_ffmpeg_library("${component}" "avresample.h")
elseif(component STREQUAL "avutil")
find_ffmpeg_library("${component}" "avutil.h")
elseif(component STREQUAL "postproc")
find_ffmpeg_library("${component}" "postprocess.h")
elseif(component STREQUAL "swresample")
find_ffmpeg_library("${component}" "swresample.h")
elseif(component STREQUAL "swscale")
find_ffmpeg_library("${component}" "swscale.h")
else()
message(FATAL_ERROR "Unknown FFMpeg component requested: ${component}")
endif()
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFMpeg
FOUND_VAR FFMPEG_FOUND
REQUIRED_VARS FFMPEG_${_first_comp}_LIBRARIES FFMPEG_${_first_comp}_INCLUDE_DIRS
VERSION_VAR FFMPEG_${_first_comp}_VERSION_STRING
HANDLE_COMPONENTS)

View File

@@ -1,52 +0,0 @@
# Once done these will be defined:
#
# LIBAVCODEC_FOUND
# LIBAVCODEC_INCLUDE_DIRS
# LIBAVCODEC_LIBRARIES
#
# For use in OBS:
#
# FFMPEG_INCLUDE_DIR
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_AVCODEC QUIET libavcodec)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()
find_path(FFMPEG_INCLUDE_DIR
NAMES libavcodec/avcodec.h
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_AVCODEC_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include /sw/include
PATH_SUFFIXES ffmpeg libav)
find_library(AVCODEC_LIB
NAMES ${_AVCODEC_LIBRARIES} avcodec-ffmpeg avcodec
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_AVCODEC_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libavcodec DEFAULT_MSG AVCODEC_LIB FFMPEG_INCLUDE_DIR)
mark_as_advanced(FFMPEG_INCLUDE_DIR AVCODEC_LIB)
if(LIBAVCODEC_FOUND)
set(LIBAVCODEC_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR})
set(LIBAVCODEC_LIBRARIES ${AVCODEC_LIB})
endif()

View File

@@ -1,48 +0,0 @@
# Once done these will be defined:
#
# LIBAVFORMAT_FOUND
# LIBAVFORMAT_INCLUDE_DIRS
# LIBAVFORMAT_LIBRARIES
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_AVFORMAT QUIET libavformat)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()
find_path(FFMPEG_INCLUDE_DIR
NAMES libavformat/avformat.h
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_AVFORMAT_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include /sw/include
PATH_SUFFIXES ffmpeg libav)
find_library(AVFORMAT_LIB
NAMES ${_AVFORMAT_LIBRARIES} avformat-ffmpeg avformat
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_AVFORMAT_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libavformat DEFAULT_MSG AVFORMAT_LIB FFMPEG_INCLUDE_DIR)
mark_as_advanced(FFMPEG_INCLUDE_DIR AVFORMAT_LIB)
if(LIBAVFORMAT_FOUND)
set(LIBAVFORMAT_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR})
set(LIBAVFORMAT_LIBRARIES ${AVFORMAT_LIB})
endif()

View File

@@ -1,48 +0,0 @@
# Once done these will be defined:
#
# LIBAVUTIL_FOUND
# LIBAVUTIL_INCLUDE_DIRS
# LIBAVUTIL_LIBRARIES
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_AVUTIL QUIET libavutil)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()
find_path(FFMPEG_INCLUDE_DIR
NAMES libavutil/avutil.h
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_AVUTIL_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include /sw/include
PATH_SUFFIXES ffmpeg libav)
find_library(AVUTIL_LIB
NAMES ${_AVUTIL_LIBRARIES} avutil-ffmpeg avutil
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_AVUTIL_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libavutil DEFAULT_MSG AVUTIL_LIB FFMPEG_INCLUDE_DIR)
mark_as_advanced(FFMPEG_INCLUDE_DIR AVUTIL_LIB)
if(LIBAVUTIL_FOUND)
set(LIBAVUTIL_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR})
set(LIBAVUTIL_LIBRARIES ${AVUTIL_LIB})
endif()

View File

@@ -1,48 +0,0 @@
# Once done these will be defined:
#
# LIBSWRESAMPLE_FOUND
# LIBSWRESAMPLE_INCLUDE_DIRS
# LIBSWRESAMPLE_LIBRARIES
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_SWRESAMPLE QUIET libswresample)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()
find_path(FFMPEG_INCLUDE_DIR
NAMES libswresample/swresample.h
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_SWRESAMPLE_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include /sw/include
PATH_SUFFIXES ffmpeg libav)
find_library(SWRESAMPLE_LIB
NAMES ${_SWRESAMPLE_LIBRARIES} swresample-ffmpeg swresample
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_SWRESAMPLE_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libswresample DEFAULT_MSG SWRESAMPLE_LIB FFMPEG_INCLUDE_DIR)
mark_as_advanced(FFMPEG_INCLUDE_DIR SWRESAMPLE_LIB)
if(LIBSWRESAMPLE_FOUND)
set(LIBSWRESAMPLE_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR})
set(LIBSWRESAMPLE_LIBRARIES ${SWRESAMPLE_LIB})
endif()

View File

@@ -1,48 +0,0 @@
# Once done these will be defined:
#
# LIBSWSCALE_FOUND
# LIBSWSCALE_INCLUDE_DIRS
# LIBSWSCALE_LIBRARIES
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_SWSCALE QUIET libswscale)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()
find_path(FFMPEG_INCLUDE_DIR
NAMES libswscale/swscale.h
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_SWSCALE_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include /sw/include
PATH_SUFFIXES ffmpeg libav)
find_library(SWSCALE_LIB
NAMES ${_SWSCALE_LIBRARIES} swscale-ffmpeg swscale
HINTS
ENV FFmpegPath${_lib_suffix}
ENV FFmpegPath
${_SWSCALE_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libswscale DEFAULT_MSG SWSCALE_LIB FFMPEG_INCLUDE_DIR)
mark_as_advanced(FFMPEG_INCLUDE_DIR SWSCALE_LIB)
if(LIBSWSCALE_FOUND)
set(LIBSWSCALE_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIR})
set(LIBSWSCALE_LIBRARIES ${SWSCALE_LIB})
endif()