mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-14 10:37:38 +01:00
Merge pull request #953 from LoveEevee/wasm-ffmpeg
Cmake: Build FFmpeg for wasm target
This commit is contained in:
commit
2cddb50da9
@ -47,6 +47,7 @@ set_mpeg(ON FALSE)
|
||||
set_vorbis(ON FALSE)
|
||||
set_ffmpeg(ON FALSE)
|
||||
|
||||
option(USE_MAIATRAC3PLUS "Use MAIATRAC3+ for support of ATRAC3+" OFF)
|
||||
option(USE_G7221 "Use G7221 for support of ITU-T G.722.1 annex C" ON)
|
||||
option(USE_G719 "Use libg719_decode for support ITU-T G.719" ON)
|
||||
option(USE_ATRAC9 "Use LibAtrac9 for support of ATRAC9" ON)
|
||||
@ -100,7 +101,6 @@ endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set(USE_MPEG OFF)
|
||||
set(USE_FFMPEG OFF)
|
||||
set(USE_JANSSON OFF)
|
||||
set(BUILD_V123 OFF)
|
||||
set(BUILD_AUDACIOUS OFF)
|
||||
@ -141,13 +141,6 @@ add_custom_target(version_h ALL DEPENDS ${VGM_SOURCE_DIR}/version_auto.h)
|
||||
include(FetchDependency)
|
||||
|
||||
include(dependencies/ffmpeg)
|
||||
|
||||
if(USE_FFMPEG)
|
||||
option(USE_MAIATRAC3PLUS "Use MAIATRAC3+ for support of ATRAC3+" OFF)
|
||||
else()
|
||||
option(USE_MAIATRAC3PLUS "Use MAIATRAC3+ for support of ATRAC3+" ON)
|
||||
endif()
|
||||
|
||||
include(dependencies/mpg123)
|
||||
include(dependencies/vorbis)
|
||||
include(dependencies/libao)
|
||||
|
@ -6,7 +6,7 @@ if(NOT WIN32)
|
||||
endif()
|
||||
|
||||
function(FetchDependency name)
|
||||
set(value_args DIR GIT_REPOSITORY GIT_TAG)
|
||||
set(value_args DIR GIT_REPOSITORY GIT_TAG DOWNLOAD SUBDIR)
|
||||
cmake_parse_arguments(ARGS "" "${value_args}" "" ${ARGN})
|
||||
|
||||
if(NOT ARGS_DIR)
|
||||
@ -18,23 +18,41 @@ function(FetchDependency name)
|
||||
|
||||
if(${name}_PATH AND IS_DIRECTORY "${${name}_PATH}")
|
||||
set(${name}_SOURCE "(local path)" PARENT_SCOPE)
|
||||
elseif(Git_FOUND AND ARGS_GIT_REPOSITORY)
|
||||
elseif(Git_FOUND AND ARGS_GIT_REPOSITORY OR ARGS_DOWNLOAD)
|
||||
set(${name}_PATH ${VGM_SOURCE_DIR}/dependencies/${ARGS_DIR})
|
||||
set(${name}_PATH ${${name}_PATH} PARENT_SCOPE)
|
||||
set(${name}_SOURCE "(download)" PARENT_SCOPE)
|
||||
|
||||
FetchContent_Declare(${name}_FETCH
|
||||
GIT_REPOSITORY ${ARGS_GIT_REPOSITORY}
|
||||
SOURCE_DIR ${${name}_PATH}
|
||||
BINARY_DIR ${${name}_BIN}
|
||||
SUBBUILD_DIR ${${name}_BIN}-sub
|
||||
GIT_TAG ${ARGS_GIT_TAG}
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
FetchContent_GetProperties(${name}_FETCH)
|
||||
if(NOT ${name}_FETCH_POPULATED)
|
||||
message("Downloading ${ARGS_DIR}...")
|
||||
FetchContent_Populate(${name}_FETCH)
|
||||
if(Git_FOUND AND ARGS_GIT_REPOSITORY)
|
||||
FetchContent_Declare(${name}_FETCH
|
||||
GIT_REPOSITORY ${ARGS_GIT_REPOSITORY}
|
||||
SOURCE_DIR ${${name}_PATH}
|
||||
BINARY_DIR ${${name}_BIN}
|
||||
SUBBUILD_DIR ${${name}_BIN}-sub
|
||||
GIT_TAG ${ARGS_GIT_TAG}
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
FetchContent_GetProperties(${name}_FETCH)
|
||||
if(NOT ${name}_FETCH_POPULATED)
|
||||
message("Downloading ${ARGS_DIR}...")
|
||||
FetchContent_Populate(${name}_FETCH)
|
||||
endif()
|
||||
else()
|
||||
string(REGEX REPLACE ".*/" "" FILE ${ARGS_DOWNLOAD})
|
||||
if(NOT EXISTS ${${name}_PATH}/${FILE})
|
||||
message("Downloading ${ARGS_DIR}...")
|
||||
file(DOWNLOAD
|
||||
${ARGS_DOWNLOAD}
|
||||
${${name}_PATH}/${FILE}
|
||||
)
|
||||
file(ARCHIVE_EXTRACT
|
||||
INPUT ${${name}_PATH}/${FILE}
|
||||
DESTINATION ${${name}_PATH}
|
||||
)
|
||||
endif()
|
||||
if(ARGS_SUBDIR)
|
||||
set(${name}_PATH ${${name}_PATH}/${ARGS_SUBDIR} PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(${name}_PATH "" PARENT_SCOPE)
|
||||
|
@ -43,8 +43,14 @@ if(USE_FFMPEG)
|
||||
endif()
|
||||
endif()
|
||||
if(USE_FFMPEG AND NOT WIN32 AND (NOT FFmpeg_FOUND OR FFMPEG_PATH OR BUILD_STATIC))
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(PC_OPUS REQUIRED opus>=1.1)
|
||||
set(USE_FFMPEG_LIBOPUS OFF)
|
||||
if(NOT EMSCRIPTEN)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(PC_OPUS QUIET opus>=1.1)
|
||||
if(PC_OPUS_FOUND)
|
||||
set(USE_FFMPEG_LIBOPUS ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
FetchDependency(FFMPEG
|
||||
DIR ffmpeg
|
||||
@ -60,8 +66,13 @@ if(USE_FFMPEG)
|
||||
ac3 asf xwma mov oma ogg tak dsf wav aac dts dtshd mp3 bink flac msf xmv caf ape smacker pcm_s8 spdif mpc mpc8
|
||||
)
|
||||
set(FFMPEG_CONF_DECODER
|
||||
ac3 wmapro wmav1 wmav2 wmavoice wmalossless xma1 xma2 dca tak dsd_lsbf dsd_lsbf_planar dsd_mbf dsd_msbf_planar aac atrac3 atrac3p mp1float mp2float mp3float binkaudio_dct binkaudio_rdft flac pcm_s16be pcm_s16be_planar pcm_s16le pcm_s16le_planar vorbis ape adpcm_ima_qt smackaud libopus pcm_s8 pcm_s8_planar mpc7 mpc8 alac adpcm_ima_dk3 adpcm_ima_dk4
|
||||
ac3 wmapro wmav1 wmav2 wmavoice wmalossless xma1 xma2 dca tak dsd_lsbf dsd_lsbf_planar dsd_mbf dsd_msbf_planar aac atrac3 atrac3p mp1float mp2float mp3float binkaudio_dct binkaudio_rdft flac pcm_s16be pcm_s16be_planar pcm_s16le pcm_s16le_planar vorbis ape adpcm_ima_qt smackaud pcm_s8 pcm_s8_planar mpc7 mpc8 alac adpcm_ima_dk3 adpcm_ima_dk4
|
||||
)
|
||||
if(USE_FFMPEG_LIBOPUS)
|
||||
list(APPEND FFMPEG_CONF_DECODER libopus)
|
||||
else()
|
||||
list(APPEND FFMPEG_CONF_DECODER opus)
|
||||
endif()
|
||||
set(FFMPEG_CONF_DISABLE_PARSER
|
||||
mpeg4video h263
|
||||
)
|
||||
@ -101,7 +112,6 @@ if(USE_FFMPEG)
|
||||
--disable-everything
|
||||
--enable-hwaccels
|
||||
--enable-swresample
|
||||
--enable-libopus
|
||||
--enable-parser=${FFMPEG_CONF_PARSER}
|
||||
--enable-demuxer=${FFMPEG_CONF_DEMUXER}
|
||||
--enable-decoder=${FFMPEG_CONF_DECODER}
|
||||
@ -113,14 +123,45 @@ if(USE_FFMPEG)
|
||||
--extra-cflags=--static
|
||||
--pkg-config-flags=--static
|
||||
)
|
||||
if(USE_FFMPEG_LIBOPUS)
|
||||
list(APPEND FFMPEG_CONF_ARGS
|
||||
--enable-libopus
|
||||
)
|
||||
endif()
|
||||
if(EMSCRIPTEN)
|
||||
list(APPEND FFMPEG_CONF_ARGS
|
||||
--cc=emcc
|
||||
--ranlib=emranlib
|
||||
--enable-cross-compile
|
||||
--target-os=none
|
||||
--arch=x86
|
||||
--disable-runtime-cpudetect
|
||||
--disable-asm
|
||||
--disable-fast-unaligned
|
||||
--disable-pthreads
|
||||
--disable-w32threads
|
||||
--disable-os2threads
|
||||
--disable-debug
|
||||
--disable-stripping
|
||||
--disable-safe-bitstream-reader
|
||||
)
|
||||
endif()
|
||||
|
||||
set(FFMPEG_LINK_PATH ${FFMPEG_BIN}/bin/usr/local/lib)
|
||||
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_BIN}/bin/usr/local/include)
|
||||
|
||||
if(NOT EXISTS ${FFMPEG_LINK_PATH}/libavutil.a)
|
||||
add_custom_target(FFMPEG_MAKE ALL
|
||||
COMMAND ./configure ${FFMPEG_CONF_ARGS} && make && make install DESTDIR="${FFMPEG_BIN}/bin" && make clean
|
||||
WORKING_DIRECTORY ${FFMPEG_PATH}
|
||||
)
|
||||
if(EMSCRIPTEN)
|
||||
add_custom_target(FFMPEG_MAKE ALL
|
||||
COMMAND emconfigure ./configure ${FFMPEG_CONF_ARGS} && emmake make && make install DESTDIR="${FFMPEG_BIN}/bin" && make clean
|
||||
WORKING_DIRECTORY ${FFMPEG_PATH}
|
||||
)
|
||||
else()
|
||||
add_custom_target(FFMPEG_MAKE ALL
|
||||
COMMAND ./configure ${FFMPEG_CONF_ARGS} && make && make install DESTDIR="${FFMPEG_BIN}/bin" && make clean
|
||||
WORKING_DIRECTORY ${FFMPEG_PATH}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
foreach(LIB avutil avformat swresample avcodec)
|
||||
@ -129,6 +170,25 @@ if(USE_FFMPEG)
|
||||
IMPORTED_LOCATION ${FFMPEG_LINK_PATH}/lib${LIB}.a
|
||||
)
|
||||
endforeach()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
FetchDependency(ZLIB
|
||||
DIR zlib
|
||||
DOWNLOAD https://zlib.net/zlib-1.2.11.tar.xz
|
||||
SUBDIR zlib-1.2.11
|
||||
)
|
||||
|
||||
add_subdirectory(${ZLIB_PATH} ${ZLIB_BIN})
|
||||
target_include_directories(example PRIVATE ${ZLIB_PATH})
|
||||
target_include_directories(minigzip PRIVATE ${ZLIB_PATH})
|
||||
target_include_directories(example64 PRIVATE ${ZLIB_PATH})
|
||||
target_include_directories(minigzip64 PRIVATE ${ZLIB_PATH})
|
||||
|
||||
add_library(z STATIC IMPORTED)
|
||||
set_target_properties(z PROPERTIES
|
||||
IMPORTED_LOCATION ${ZLIB_BIN}/libz.a
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
@ -1,8 +1,6 @@
|
||||
if(USE_MAIATRAC3PLUS)
|
||||
FetchDependency(MAIATRAC3PLUS
|
||||
DIR maiatrac3plus
|
||||
GIT_REPOSITORY https://github.com/emulibraries/maiatrac3plus
|
||||
GIT_TAG 95c34f2651b0988a8ed762692925eb22700e9b42
|
||||
)
|
||||
|
||||
if(MAIATRAC3PLUS_PATH)
|
||||
@ -19,6 +17,8 @@ if(USE_MAIATRAC3PLUS)
|
||||
${MAIATRAC3PLUS_PATH}/MaiAT3PlusDecoder/src/base/Mai_Mem.cc
|
||||
COPYONLY)
|
||||
add_subdirectory(${MAIATRAC3PLUS_PATH}/MaiAT3PlusDecoder ${MAIATRAC3PLUS_BIN})
|
||||
else()
|
||||
message(FATAL_ERROR "Path to MAIATRAC3+ must be set. (Use MAIATRAC3PLUS_PATH)")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT USE_MAIATRAC3PLUS)
|
||||
|
@ -7,29 +7,11 @@ if(NOT WIN32 AND USE_MPEG)
|
||||
endif()
|
||||
endif()
|
||||
if(MPEG_PATH OR BUILD_STATIC OR NOT MPG123_FOUND)
|
||||
set(MPEG_BIN ${VGM_BINARY_DIR}/dependencies/mpg123)
|
||||
|
||||
if(MPEG_PATH)
|
||||
set(MPEG_SOURCE "(local path)")
|
||||
else()
|
||||
set(MPEG_PATH ${VGM_SOURCE_DIR}/dependencies/mgp123)
|
||||
set(MPEG_FILE ${MPEG_PATH}/mpg123-1.28.2.tar.bz2)
|
||||
set(MPEG_SOURCE "(download)")
|
||||
|
||||
if(NOT EXISTS ${MPEG_FILE})
|
||||
|
||||
file(DOWNLOAD
|
||||
https://downloads.sourceforge.net/mpg123/mpg123-1.28.2.tar.bz2
|
||||
${MPEG_FILE}
|
||||
)
|
||||
file(ARCHIVE_EXTRACT
|
||||
INPUT ${MPEG_FILE}
|
||||
DESTINATION ${MPEG_PATH}
|
||||
)
|
||||
endif()
|
||||
|
||||
set(MPEG_PATH ${MPEG_PATH}/mpg123-1.28.2)
|
||||
endif()
|
||||
FetchDependency(MPEG
|
||||
DIR mpg123
|
||||
DOWNLOAD https://downloads.sourceforge.net/mpg123/mpg123-1.28.2.tar.bz2
|
||||
SUBDIR mpg123-1.28.2
|
||||
)
|
||||
|
||||
set(MPEG_LINK_PATH ${MPEG_BIN}/bin/usr/local/lib/libmpg123.a)
|
||||
|
||||
|
@ -73,7 +73,11 @@ macro(setup_target TARGET)
|
||||
target_include_directories(${TARGET} PRIVATE ${FFMPEG_INCLUDE_DIRS})
|
||||
if(LINK)
|
||||
if(BUILD_STATIC)
|
||||
target_link_libraries(${TARGET} avformat avcodec avutil swresample opus pthread m z)
|
||||
if(USE_FFMPEG_LIBOPUS)
|
||||
target_link_libraries(${TARGET} avformat avcodec avutil swresample opus pthread m z)
|
||||
else()
|
||||
target_link_libraries(${TARGET} avformat avcodec avutil swresample pthread m z)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(${TARGET} ${FFMPEG_LIBRARIES})
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user