mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-28 00:20:47 +01:00
Static link more libraries
This commit is contained in:
parent
25d6b980dc
commit
a9c398e8c8
213
CMakeLists.txt
213
CMakeLists.txt
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
project(vgmstream C)
|
||||
enable_language(CXX)
|
||||
|
||||
@ -42,6 +42,16 @@ function(set_ffmpeg onoff useForce)
|
||||
set(USE_FFMPEG ${onoff} CACHE BOOL "Use FFmpeg for support of many codecs" ${USE_FORCE_})
|
||||
endfunction()
|
||||
|
||||
function(add_library_path lib_name static lib_path)
|
||||
if(static)
|
||||
add_library(${lib_name} STATIC IMPORTED)
|
||||
set_target_properties(${lib_name} PROPERTIES IMPORTED_LOCATION ${lib_path}.a)
|
||||
else()
|
||||
add_library(${lib_name} SHARED IMPORTED)
|
||||
set_target_properties(${lib_name} PROPERTIES IMPORTED_LOCATION ${lib_path}.so)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Options
|
||||
set_mpeg(ON FALSE)
|
||||
set_vorbis(ON FALSE)
|
||||
@ -50,13 +60,7 @@ option(USE_MAIATRAC3PLUS "Use MAIATRAC3+ for support of ATRAC3+" OFF)
|
||||
set(MAIATRAC3PLUS_PATH CACHE PATH "Path to MAIATRAC3+")
|
||||
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)
|
||||
if(NOT WIN32)
|
||||
set(G719_PATH CACHE PATH "Path to G.719 decoder")
|
||||
endif()
|
||||
option(USE_ATRAC9 "Use LibAtrac9 for support of ATRAC9" ON)
|
||||
if(NOT WIN32)
|
||||
set(ATRAC9_PATH CACHE PATH "Path to LibAtrac9")
|
||||
endif()
|
||||
if(WIN32)
|
||||
# May need to see if it is possible to get these to work on non-Windows systems too
|
||||
option(USE_CELT "Use libcelt for support of FSB CELT versions 0.6.1 and 0.11.0" ON)
|
||||
@ -64,6 +68,12 @@ endif()
|
||||
option(USE_SPEEX "Use libspeex for support of SPEEX" ON)
|
||||
if(NOT WIN32)
|
||||
option(USE_JANSSON "Use jansson for JSON dumping" ON)
|
||||
|
||||
set(MPEG_PATH CACHE PATH "Path to mpg123")
|
||||
set(FFMPEG_PATH CACHE PATH "Path to FFmpeg")
|
||||
set(G719_PATH CACHE PATH "Path to G.719 decoder")
|
||||
set(ATRAC9_PATH CACHE PATH "Path to LibAtrac9")
|
||||
set(LIBAO_PATH CACHE PATH "Path to libao")
|
||||
endif()
|
||||
|
||||
# Build choices
|
||||
@ -80,9 +90,13 @@ if(WIN32)
|
||||
option(BUILD_XMPLAY "Build XMPlay plugin" ON)
|
||||
set(XMPLAY_INSTALL_PREFIX CACHE PATH "Path to XMPlay installation directory")
|
||||
else()
|
||||
option(BUILD_V123 "Build vgmstream123 player" ON)
|
||||
option(BUILD_AUDACIOUS "Build Audacious plugin" ON)
|
||||
option(BUILD_STATIC "Build statically linked binary" OFF)
|
||||
if(BUILD_STATIC)
|
||||
option(BUILD_V123 "Build vgmstream123 player" OFF)
|
||||
else()
|
||||
option(BUILD_V123 "Build vgmstream123 player" ON)
|
||||
endif()
|
||||
option(BUILD_AUDACIOUS "Build Audacious plugin" ON)
|
||||
endif()
|
||||
|
||||
# Static builds will link all libraries statically
|
||||
@ -90,11 +104,7 @@ if(BUILD_STATIC)
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
|
||||
# Libraries that are incompatible with static builds
|
||||
set(USE_MPEG OFF)
|
||||
set(USE_FFMPEG OFF)
|
||||
set(USE_SPEEX OFF)
|
||||
set(BUILD_V123 OFF)
|
||||
# Incompatible with static builds
|
||||
set(BUILD_AUDACIOUS OFF)
|
||||
endif()
|
||||
|
||||
@ -121,23 +131,74 @@ else()
|
||||
endif()
|
||||
add_custom_target(version_h ALL DEPENDS ${VGM_SOURCE_DIR}/version_auto.h)
|
||||
|
||||
if(NOT WIN32)
|
||||
find_package(Git QUIET)
|
||||
if(Git_FOUND)
|
||||
include(FetchContent)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# FFmpeg detection
|
||||
if(USE_FFMPEG)
|
||||
find_package(FFmpeg)
|
||||
if(NOT FFMPEG_LIBRARIES)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
else()
|
||||
if(${AVCODEC_VERSION} VERSION_LESS 57)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
message("libavcodec version mismatch ${AVCODEC_VERSION} expected >=57")
|
||||
elseif(${AVUTIL_VERSION} VERSION_LESS 55)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
message("libavutil version mismatch ${AVUTIL_VERSION} expected >=55")
|
||||
elseif(${SWRESAMPLE_VERSION} VERSION_LESS 2)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
message("libswresample version mismatch ${SWRESAMPLE_VERSION} expected >=2")
|
||||
if(NOT WIN32 AND BUILD_STATIC AND NOT FFMPEG_PATH)
|
||||
if(Git_FOUND)
|
||||
set(FFMPEG_PATH ${VGM_SOURCE_DIR}/dependencies/ffmpeg)
|
||||
FetchContent_Declare(ffmpeg
|
||||
GIT_REPOSITORY https://git.ffmpeg.org/ffmpeg.git
|
||||
SOURCE_DIR ${FFMPEG_PATH}
|
||||
BINARY_DIR ${FFMPEG_PATH}-build
|
||||
SUBBUILD_DIR ${FFMPEG_PATH}-subbuild
|
||||
GIT_TAG n4.4
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
FetchContent_GetProperties(ffmpeg)
|
||||
if(NOT ffmpeg_POPULATED)
|
||||
FetchContent_Populate(ffmpeg)
|
||||
endif()
|
||||
else()
|
||||
set(USE_FFMPEG OFF)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT WIN32 AND FFMPEG_PATH)
|
||||
if(BUILD_STATIC)
|
||||
set(FF_SHARED --enable-static --disable-shared)
|
||||
set(FF_EXTRA --extra-libs=-static --extra-cflags=--static --pkg-config-flags=--static)
|
||||
set(LINK_EXT .a)
|
||||
else()
|
||||
set(FF_SHARED --disable-static --enable-shared)
|
||||
unset(FF_EXTRA)
|
||||
set(LINK_EXT .so)
|
||||
endif()
|
||||
set(FF_CONF_ARGS ${FF_SHARED} --enable-gpl --disable-doc --disable-ffplay --disable-ffprobe --disable-avdevice --disable-ffmpeg --disable-postproc --disable-avfilter --disable-swscale --disable-network --disable-swscale-alpha --disable-vdpau --disable-dxva2 --disable-amf --disable-cuda --disable-d3d11va --disable-ffnvcodec --disable-nvenc --disable-nvdec --disable-hwaccels --disable-sdl2 --disable-iconv --disable-everything --enable-hwaccels --enable-swresample --enable-libopus --enable-parser=ac3,mpegaudio,xma,vorbis,opus --enable-demuxer=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 --enable-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 --disable-parser=mpeg4video,h263 --disable-decoder=mpeg2video,h263,h264,mpeg1video,mpeg2video,mpeg4,hevc,vp9 --disable-cuvid --disable-version3 ${FF_EXTRA})
|
||||
if(NOT EXISTS ${FFMPEG_PATH}/libavutil/libavutil${LINK_EXT})
|
||||
add_custom_target(FF_MAKE ALL
|
||||
COMMAND ./configure ${FF_CONF_ARGS} && make
|
||||
WORKING_DIRECTORY ${FFMPEG_PATH}
|
||||
)
|
||||
endif()
|
||||
add_library_path(avutil ${BUILD_STATIC} ${FFMPEG_PATH}/libavutil/libavutil)
|
||||
add_library_path(avformat ${BUILD_STATIC} ${FFMPEG_PATH}/libavformat/libavformat)
|
||||
add_library_path(swresample ${BUILD_STATIC} ${FFMPEG_PATH}/libswresample/libswresample)
|
||||
add_library_path(avcodec ${BUILD_STATIC} ${FFMPEG_PATH}/libavcodec/libavcodec)
|
||||
elseif(NOT BUILD_STATIC)
|
||||
find_package(FFmpeg)
|
||||
if(NOT FFMPEG_LIBRARIES)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
else()
|
||||
if(${AVCODEC_VERSION} VERSION_LESS 57)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
message("libavcodec version mismatch ${AVCODEC_VERSION} expected >=57")
|
||||
elseif(${AVUTIL_VERSION} VERSION_LESS 55)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
message("libavutil version mismatch ${AVUTIL_VERSION} expected >=55")
|
||||
elseif(${SWRESAMPLE_VERSION} VERSION_LESS 2)
|
||||
set_ffmpeg(OFF TRUE)
|
||||
message("libswresample version mismatch ${SWRESAMPLE_VERSION} expected >=2")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(USE_FFMPEG OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
@ -154,9 +215,43 @@ else()
|
||||
|
||||
# Find the relevant packages
|
||||
if(USE_MPEG)
|
||||
find_package(MPG123)
|
||||
if(NOT MPG123_FOUND)
|
||||
set_mpeg(OFF TRUE)
|
||||
if(NOT WIN32 AND BUILD_STATIC AND NOT MPEG_PATH)
|
||||
set(MPEG_PATH ${VGM_SOURCE_DIR}/dependencies/mgp123)
|
||||
set(MPEG_FILE ${MPEG_PATH}/mpg123-1.28.2.tar.bz2)
|
||||
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()
|
||||
if(NOT WIN32 AND MPEG_PATH)
|
||||
if(BUILD_STATIC)
|
||||
set(MPEG_CONF_ARGS --enable-static=yes --enable-shared=no)
|
||||
set(LINK_EXT .a)
|
||||
else()
|
||||
set(MPEG_CONF_ARGS --enable-static=no --enable-shared=yes)
|
||||
set(LINK_EXT .so)
|
||||
endif()
|
||||
if(NOT EXISTS ${MPEG_PATH}/src/libmpg123/.libs/libmpg123${LINK_EXT})
|
||||
add_custom_target(MPEG_MAKE ALL
|
||||
COMMAND ./configure ${MPEG_CONF_ARGS} && make
|
||||
WORKING_DIRECTORY ${MPEG_PATH}
|
||||
)
|
||||
endif()
|
||||
add_library_path(mpg123 ${BUILD_STATIC} ${MPEG_PATH}/src/libmpg123/.libs/libmpg123)
|
||||
elseif(NOT BUILD_STATIC)
|
||||
find_package(MPG123)
|
||||
if(NOT MPG123_FOUND)
|
||||
set_mpeg(OFF TRUE)
|
||||
endif()
|
||||
else()
|
||||
set(USE_MPEG OFF)
|
||||
endif()
|
||||
endif()
|
||||
if(USE_VORBIS)
|
||||
@ -168,11 +263,33 @@ else()
|
||||
|
||||
# If building the CLI, we need to include AO as well
|
||||
if(BUILD_V123)
|
||||
find_package(AO)
|
||||
if(AO_FOUND)
|
||||
if(LIBAO_PATH)
|
||||
if(BUILD_STATIC)
|
||||
set(LIBAO_CONF_ARGS --enable-static=yes --enable-shared=no)
|
||||
set(LINK_EXT .a)
|
||||
else()
|
||||
set(LIBAO_CONF_ARGS --enable-static=no --enable-shared=yes)
|
||||
set(LINK_EXT .so)
|
||||
endif()
|
||||
if(NOT EXISTS ${LIBAO_PATH}/src/.libs/libao${LINK_EXT})
|
||||
add_custom_target(LIBAO_MAKE ALL
|
||||
COMMAND ./autogen.sh && ./configure ${LIBAO_CONF_ARGS} && make
|
||||
WORKING_DIRECTORY ${LIBAO_PATH}
|
||||
)
|
||||
endif()
|
||||
add_library_path(ao ${BUILD_STATIC} ${LIBAO_PATH}/src/.libs/libao)
|
||||
set(LIBAO_INCLUDE ${LIBAO_PATH}/include/ao)
|
||||
set(USE_V123 ON)
|
||||
else (AO_FOUND)
|
||||
#TODO: add proper separate option
|
||||
elseif(NOT BUILD_STATIC)
|
||||
find_package(AO)
|
||||
if(AO_FOUND)
|
||||
set(LIBAO_INCLUDE ${AO_INCLUDE_DIR})
|
||||
set(USE_V123 ON)
|
||||
else()
|
||||
set(USE_V123 OFF)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Path to libao must be set. (Use LIBAO_PATH)")
|
||||
set(USE_V123 OFF)
|
||||
endif()
|
||||
else()
|
||||
@ -249,20 +366,21 @@ if(USE_MAIATRAC3PLUS)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
find_package(Git QUIET)
|
||||
if(Git_FOUND)
|
||||
include(FetchContent)
|
||||
endif()
|
||||
if(USE_G719)
|
||||
if(NOT G719_PATH)
|
||||
if(Git_FOUND)
|
||||
set(G719_PATH ${VGM_SOURCE_DIR}/dependencies/libg719_decode)
|
||||
FetchContent_Populate(libg719_decode
|
||||
FetchContent_Declare(libg719_decode
|
||||
GIT_REPOSITORY https://github.com/kode54/libg719_decode
|
||||
SOURCE_DIR ${G719_PATH}
|
||||
BINARY_DIR ${G719_PATH}-build
|
||||
SUBBUILD_DIR ${G719_PATH}-subbuild
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
FetchContent_GetProperties(libg719_decode)
|
||||
if(NOT libg719_decode_POPULATED)
|
||||
FetchContent_Populate(libg719_decode)
|
||||
endif()
|
||||
else()
|
||||
set(USE_G719 OFF)
|
||||
endif()
|
||||
@ -279,21 +397,28 @@ if(NOT WIN32)
|
||||
if(NOT ATRAC9_PATH)
|
||||
if(Git_FOUND)
|
||||
set(ATRAC9_PATH ${VGM_SOURCE_DIR}/dependencies/LibAtrac9)
|
||||
FetchContent_Populate(ATRAC9_FETCH
|
||||
FetchContent_Declare(ATRAC9_FETCH
|
||||
GIT_REPOSITORY https://github.com/Thealexbarney/LibAtrac9
|
||||
SOURCE_DIR ${ATRAC9_PATH}
|
||||
BINARY_DIR ${ATRAC9_PATH}-build
|
||||
SUBBUILD_DIR ${ATRAC9_PATH}-subbuild
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
FetchContent_GetProperties(ATRAC9_FETCH)
|
||||
if(NOT ATRAC9_FETCH_POPULATED)
|
||||
FetchContent_Populate(ATRAC9_FETCH)
|
||||
endif()
|
||||
else()
|
||||
set(USE_ATRAC9 OFF)
|
||||
endif()
|
||||
endif()
|
||||
if(ATRAC9_PATH)
|
||||
add_custom_target(ATRAC9_MAKE ALL
|
||||
COMMAND make static CFLAGS="-fPIC"
|
||||
WORKING_DIRECTORY ${ATRAC9_PATH}/C
|
||||
)
|
||||
if(NOT EXISTS ${ATRAC9_PATH}/C/bin/libatrac9.a)
|
||||
add_custom_target(ATRAC9_MAKE ALL
|
||||
COMMAND make static CFLAGS="-fPIC"
|
||||
WORKING_DIRECTORY ${ATRAC9_PATH}/C
|
||||
)
|
||||
endif()
|
||||
add_library(atrac9 STATIC IMPORTED)
|
||||
set_target_properties(atrac9 PROPERTIES
|
||||
IMPORTED_LOCATION ${ATRAC9_PATH}/C/bin/libatrac9.a
|
||||
|
@ -66,7 +66,7 @@ install(TARGETS vgmstream_cli
|
||||
|
||||
# TODO: Make it so vgmstream123 can build with Windows (this probably needs a libao.dll included with vgmstream, though)
|
||||
|
||||
if(NOT WIN32 AND AO_FOUND)
|
||||
if(NOT WIN32 AND USE_V123)
|
||||
# vgmstream123
|
||||
|
||||
add_executable(vgmstream123
|
||||
@ -75,13 +75,13 @@ if(NOT WIN32 AND AO_FOUND)
|
||||
# Link to the vgmstream library as well as libao
|
||||
target_link_libraries(vgmstream123
|
||||
libvgmstream
|
||||
${AO_LIBRARY})
|
||||
ao dl)
|
||||
|
||||
setup_target(vgmstream123 TRUE)
|
||||
|
||||
# Add AO include directory
|
||||
target_include_directories(vgmstream123 PRIVATE
|
||||
${AO_INCLUDE_DIR})
|
||||
${LIBAO_PATH})
|
||||
|
||||
# Include the version string
|
||||
target_compile_definitions(vgmstream123 PRIVATE VGMSTREAM_VERSION="${VGMSTREAM_VERSION}")
|
||||
|
@ -38,7 +38,7 @@ macro(setup_target TARGET)
|
||||
else()
|
||||
target_include_directories(${TARGET} PRIVATE ${MPG123_INCLUDE_DIR})
|
||||
if(LINK)
|
||||
target_link_libraries(${TARGET} ${MPG123_LIBRARIES})
|
||||
target_link_libraries(${TARGET} mpg123)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -72,8 +72,7 @@ macro(setup_target TARGET)
|
||||
else()
|
||||
target_include_directories(${TARGET} PRIVATE ${FFMPEG_INCLUDE_DIRS})
|
||||
if(LINK)
|
||||
target_link_libraries(${TARGET} ${FFMPEG_LIBRARIES})
|
||||
#target_link_libraries(${TARGET} swresample avcodec avformat avutil pthread m soxr)
|
||||
target_link_libraries(${TARGET} avformat avcodec avutil swresample opus pthread m z)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -129,7 +128,7 @@ macro(setup_target TARGET)
|
||||
target_link_libraries(${TARGET} ${VGM_BINARY_DIR}/ext_libs/libspeex/libspeex.lib)
|
||||
endif()
|
||||
if(NOT WIN32 AND LINK)
|
||||
target_link_libraries(${TARGET} speex)
|
||||
target_link_libraries(${TARGET} speex m)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
Loading…
Reference in New Issue
Block a user