diff --git a/CMakeLists.txt b/CMakeLists.txt index d3bc63b6..98dba069 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,24 @@ else() option(BUILD_AUDACIOUS "Build Audacious plugin" ON) endif() +if(USE_FFMPEG) + find_package(FFmpeg) + if(NOT FFMPEG_LIBRARIES) + set(USE_FFMPEG OFF) + else() + if(${AVCODEC_VERSION} VERSION_LESS 57) + set(USE_FFMPEG OFF) + message("libavcodec version mismatch ${AVCODEC_VERSION} expected >=57") + elseif(${AVUTIL_VERSION} VERSION_LESS 55) + set(USE_FFMPEG OFF) + message("libavutil version mismatch ${AVUTIL_VERSION} expected >=55") + elseif(${SWRESAMPLE_VERSION} VERSION_LESS 2) + set(USE_FFMPEG OFF) + message("libswresample version mismatch ${SWRESAMPLE_VERSION} expected >=2") + endif() + endif() +endif() + if(WIN32) # Enable support for the resource compiler when using MinGW if(MINGW) @@ -91,23 +109,6 @@ else() set(USE_VORBIS OFF) endif() endif() - if(USE_FFMPEG) - find_package(FFmpeg) - if(NOT FFMPEG_LIBRARIES) - set(USE_FFMPEG OFF) - else() - if(${AVCODEC_VERSION} VERSION_LESS 57) - set(USE_FFMPEG OFF) - message("libavcodec version mismatch ${AVCODEC_VERSION} expected >=57") - elseif(${AVUTIL_VERSION} VERSION_LESS 55) - set(USE_FFMPEG OFF) - message("libavutil version mismatch ${AVUTIL_VERSION} expected >=55") - elseif(${SWRESAMPLE_VERSION} VERSION_LESS 2) - set(USE_FFMPEG OFF) - message("libswresample version mismatch ${SWRESAMPLE_VERSION} expected >=2") - endif() - endif() - endif() # If building the CLI, we need to include AO as well if(BUILD_CLI) diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake index c424e2a7..cd581ea2 100644 --- a/cmake/FindFFmpeg.cmake +++ b/cmake/FindFFmpeg.cmake @@ -72,16 +72,24 @@ macro(find_component _component _pkgconfig _library _header) HINTS ${PC_LIB${_component}_INCLUDEDIR} ${PC_LIB${_component}_INCLUDE_DIRS} + ${FFMPEG_PATH}/include PATH_SUFFIXES ffmpeg) find_library(${_component}_LIBRARIES NAMES ${_library} HINTS ${PC_LIB${_component}_LIBDIR} - ${PC_LIB${_component}_LIBRARY_DIRS}) + ${PC_LIB${_component}_LIBRARY_DIRS} + ${FFMPEG_PATH}/lib) set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.") set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.") + if(WIN32 AND NOT ${_component}_VERSION) + file(GLOB FOUND_DLL_ ${FFMPEG_PATH}/bin/${_library}*.dll) + string(REGEX MATCH ".*${_library}-(.+).dll" FOUND_DLL_ ${FOUND_DLL_}) + set(${_component}_VERSION ${CMAKE_MATCH_1} CACHE STRING "The ${_component} version number." FORCE) + endif() + set_component_found(${_component}) mark_as_advanced( diff --git a/cmake/vgmstream.cmake b/cmake/vgmstream.cmake index 5aae4704..8c89abf0 100644 --- a/cmake/vgmstream.cmake +++ b/cmake/vgmstream.cmake @@ -56,7 +56,7 @@ macro(setup_target TARGET) if(USE_FFMPEG) target_compile_definitions(${TARGET} PRIVATE VGM_USE_FFMPEG) - if(WIN32) + if(WIN32 AND NOT FFMPEG_LIBRARIES) target_include_directories(${TARGET} PRIVATE ${VGM_SOURCE_DIR}/ext_includes/ffmpeg) if(LINK) add_dependencies(${TARGET} ffmpeg) diff --git a/doc/CMAKE.md b/doc/CMAKE.md index 00730617..2cd7e8b2 100644 --- a/doc/CMAKE.md +++ b/doc/CMAKE.md @@ -95,7 +95,7 @@ All of these options are of type BOOL and can be set to either `ON` or `OFF`. Mo - **USE_FDKAAC**: Chooses if you wish to use FDK-AAC/QAAC for support of MP4 AAC. Note that this requires `QAAC_PATH` and `FDK_AAC_PATH` to also be given if the option is `ON`. The default for is `ON`. See the foobar2000 plugin section of [BUILD.md](BUILD.md) for more information on this. - **USE_MPEG**: Chooses if you wish to use libmpg123 for support of MP1/MP2/MP3. The default is `ON`. - **USE_VORBIS**: Chooses if you wish to use libvorbis for support of Vorbis. The default is `ON`. -- **USE_FFMPEG**: Chooses if you wish to use FFmpeg for support of many codecs. The default is `ON`. +- **USE_FFMPEG**: Chooses if you wish to use FFmpeg for support of many codecs. The default is `ON`. `FFMPEG_PATH` can also be given, so it can use official/external SDK instead of the one used in vgmstream project. - **USE_MAIATRAC3PLUS**: Chooses if you wish to use MAIATRAC3+ for support of ATRAC3+. The default is `OFF`. It is not recommended to enable. - **USE_G7221**: Chooses if you wish to use G7221 for support of ITU-T G.722.1 annex C. The default is `ON`. diff --git a/ext_libs/CMakeLists.txt b/ext_libs/CMakeLists.txt index 61d6c892..8e6fad52 100644 --- a/ext_libs/CMakeLists.txt +++ b/ext_libs/CMakeLists.txt @@ -37,7 +37,7 @@ if(MSVC) SOURCES ${VGM_SOURCE_DIR}/ext_includes/g719.h) endif() - if(USE_FFMPEG) + if(USE_FFMPEG AND NOT FFMPEG_LIBRARIES) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/avcodec.lib ${CMAKE_CURRENT_BINARY_DIR}/avcodec.exp COMMAND lib ARGS /def:${CMAKE_CURRENT_SOURCE_DIR}/avcodec-vgmstream-58.def /machine:x86 /out:${CMAKE_CURRENT_BINARY_DIR}/avcodec.lib @@ -144,7 +144,7 @@ elseif(MINGW) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libg719_decode.lib) endif() - if(USE_FFMPEG) + if(USE_FFMPEG AND NOT FFMPEG_LIBRARIES) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/avcodec.lib COMMAND ${DLLTOOL} ARGS -d ${CMAKE_CURRENT_SOURCE_DIR}/avcodec-vgmstream-58.def -l ${CMAKE_CURRENT_BINARY_DIR}/avcodec.lib -D avcodec-vgmstream-58.dll