CMake: libav/ffmpeg cleanups

Use @Orphis's FindFFmpeg module from ppsspp:
2149d3db7f

From that commit:

> This new module should be able to handle both libraries in the regular
> paths and fallback to pkg-config.
> It is also able to find dynamic libraries, not just static libraries.
> It will generate imported targets with the name FFmpeg::<lib> that you
> can use in your scripts.
This commit is contained in:
Michael Maltese
2017-05-22 12:13:19 -07:00
parent d592bdd4d4
commit d951d2e4c4
4 changed files with 182 additions and 82 deletions

View File

@ -56,74 +56,3 @@ macro(check_lib var pc lib)
endif()
endmacro()
macro(check_libav)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBAV libavcodec>=54.35.0 libavformat>=54.20.4
libswscale>=2.1.1 libavutil>=52.3.0)
endif()
if(NOT LIBAV_FOUND)
if(WIN32)
add_library(avcodec STATIC IMPORTED)
set_target_properties(avcodec PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/avcodec.lib
)
add_library(avformat STATIC IMPORTED)
set_target_properties(avformat PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/avformat.lib
)
add_library(avutil STATIC IMPORTED)
set_target_properties(avutil PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/avutil.lib
)
add_library(swresample STATIC IMPORTED)
set_target_properties(swresample PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/swresample.lib
)
add_library(swscale STATIC IMPORTED)
set_target_properties(swscale PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/swscale.lib
)
set(LIBAV_FOUND ON)
set(LIBAV_LIBRARIES avcodec avformat avutil swresample swscale)
else()
# Attempt to find it through static means
set(LIBAV_LDFLAGS avformat avcodec swscale avutil)
set(CMAKE_REQUIRED_LIBRARIES ${LIBAV_LDFLAGS})
CHECK_CXX_SOURCE_COMPILES(
"extern \"C\" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/mathematics.h>
#include <libswscale/swscale.h>
}
int main(int argc, char **argv)
{
av_register_all();
return 0;
}"
LIBAV_FOUND)
unset(CMAKE_REQUIRED_LIBRARIES)
endif()
endif()
if(LIBAV_FOUND)
message(STATUS "libav/ffmpeg found, enabling AVI frame dumps")
add_definitions(-DHAVE_LIBAV)
if(LIBAV_INCLUDE_DIRS)
include_directories(${LIBAV_INCLUDE_DIRS})
endif()
else()
message(STATUS "libav/ffmpeg not found, disabling AVI frame dumps")
endif()
endmacro()