Cmake: Build celt for Linux target

This commit is contained in:
KatieFrogs 2021-10-22 07:51:04 +03:00
parent a35e405cc9
commit 009bddf976
3 changed files with 120 additions and 8 deletions

View File

@ -51,10 +51,7 @@ 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)
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)
endif()
option(USE_CELT "Use libcelt for support of FSB CELT versions 0.6.1 and 0.11.0" ON)
option(USE_SPEEX "Use libspeex for support of SPEEX" ON)
if(NOT WIN32)
option(USE_JANSSON "Use jansson for JSON dumping" ON)
@ -69,6 +66,8 @@ if(NOT WIN32)
set(G719_PATH CACHE PATH "Path to G.719 decoder")
set(ATRAC9_PATH CACHE PATH "Path to LibAtrac9")
set(SPEEX_PATH CACHE PATH "Path to SPEEX")
set(CELT0061_PATH CACHE PATH "Path to CELT version 0.6.1")
set(CELT0110_PATH CACHE PATH "Path to CELT version 0.11.0")
set(LIBAO_PATH CACHE PATH "Path to libao")
endif()
@ -101,6 +100,7 @@ endif()
if(EMSCRIPTEN)
set(USE_MPEG OFF)
set(USE_CELT OFF)
set(USE_JANSSON OFF)
set(BUILD_V123 OFF)
set(BUILD_AUDACIOUS OFF)
@ -149,6 +149,7 @@ include(dependencies/libao)
include(dependencies/maitrac3plus)
include(dependencies/g719)
include(dependencies/atrac9)
include(dependencies/celt)
include(dependencies/speex)
include(dependencies/jansson)
include(dependencies/audacious)
@ -262,9 +263,7 @@ message(STATUS " MAIATRAC3+: ${USE_MAIATRAC3PLUS} ${MAIATRAC3PLUS_SOURCE}")
message(STATUS " G.722.1: ${USE_G7221} ${G7221_SOURCE}")
message(STATUS " G.719: ${USE_G719} ${G719_SOURCE}")
message(STATUS " ATRAC9: ${USE_ATRAC9} ${ATRAC9_SOURCE}")
if(WIN32)
message(STATUS " FSB CELT: ${USE_CELT}")
endif()
message(STATUS " FSB CELT: ${USE_CELT} ${CELT_SOURCE}")
message(STATUS " SPEEX: ${USE_SPEEX} ${SPEEX_SOURCE}")
if(NOT WIN32)
message(STATUS " LIBAO: ${BUILD_V123} ${LIBAO_SOURCE}")

View File

@ -0,0 +1,110 @@
if(NOT WIN32 AND USE_CELT)
FetchDependency(CELT_0061
DIR celt-0061
GIT_REPOSITORY https://gitlab.xiph.org/xiph/celt
GIT_TAG 8ccf148573277b983692e15d5f0753081f806bea
)
FetchDependency(CELT_0110
DIR celt-0110
GIT_REPOSITORY https://gitlab.xiph.org/xiph/celt
GIT_TAG 0b405d1170122c859faab435405666506d52fa2e
)
if(CELT_0061_PATH AND CELT_0110_PATH)
set(CELT_0061_LINK_PATH ${CELT_0061_BIN}/libcelt/.libs/libcelt.a)
set(CELT_0110_LINK_PATH ${CELT_0110_BIN}/libcelt/.libs/libcelt0.a)
set(CELT_CONF
alg_quant
alg_unquant
celt_decode
celt_decoder_create
celt_decoder_create_custom
celt_decoder_destroy
celt_mode_create
celt_mode_destroy
celt_mode_info
celt_encoder_destroy
celt_encoder_create
celt_encode
celt_encode_float
celt_encoder_ctl
celt_decode_float
celt_decoder_ctl
compute_allocation
compute_band_energies
denormalise_bands
ec_dec_init
ec_decode
ec_decode_bin
ec_dec_update
ec_dec_uint
ec_dec_bits
ec_enc_init
ec_encode
ec_encode_bin
ec_enc_uint
ec_enc_bits
ec_enc_done
normalise_bands
renormalise_vector
quant_coarse_energy
quant_fine_energy
quant_energy_finalise
unquant_coarse_energy
unquant_energy_finalise
unquant_fine_energy
)
foreach(ver 0061 0110)
foreach(source ${CELT_CONF})
string(REGEX REPLACE "^([^_]+)" "\\1_${ver}" target ${source})
list(APPEND CELT_${ver}_CONF "-D${source}=${target}")
endforeach()
if(ver STREQUAL "0110")
list(APPEND CELT_${ver}_CONF "-DCUSTOM_MODES=1")
endif()
list(APPEND CELT_${ver}_CONF "-fPIC")
if(NOT EXISTS ${CELT_${ver}_PATH}/configure)
add_custom_target(CELT_${ver}_AUTOGEN
COMMAND ./autogen.sh
BYPRODUCTS ${CELT_${ver}_PATH}/configure
WORKING_DIRECTORY ${CELT_${ver}_PATH}
)
endif()
file(MAKE_DIRECTORY ${CELT_${ver}_BIN})
add_custom_target(CELT_${ver}_CONFIGURE
COMMAND "${CELT_${ver}_PATH}/configure" --enable-static --disable-shared CC="${CMAKE_C_COMPILER}" AR="${CMAKE_AR}" CFLAGS="${CELT_${ver}_CONF}"
DEPENDS ${CELT_${ver}_PATH}/configure
BYPRODUCTS ${CELT_${ver}_BIN}/Makefile
WORKING_DIRECTORY ${CELT_${ver}_BIN}
)
add_custom_target(CELT_${ver}_MAKE
COMMAND make
DEPENDS ${CELT_${ver}_BIN}/Makefile
BYPRODUCTS ${CELT_${ver}_LINK_PATH} ${CELT_${ver}_BIN}
WORKING_DIRECTORY ${CELT_${ver}_BIN}
)
add_library(celt${ver} STATIC IMPORTED)
if(NOT EXISTS ${CELT_${ver}_LINK_PATH})
add_dependencies(celt${ver} CELT_${ver}_MAKE)
endif()
set_target_properties(celt${ver} PROPERTIES
IMPORTED_LOCATION ${CELT_${ver}_LINK_PATH}
)
endforeach()
else()
set(USE_CELT OFF)
endif()
endif()
if(USE_CELT)
if(CELT_0061_SOURCE STREQUAL "${CELT_0110_SOURCE}")
set(CELT_SOURCE ${CELT_0061_SOURCE})
else()
set(CELT_SOURCE "v0.6.1: ${CELT_0061_SOURCE}, v0.11.0: ${CELT_0110_SOURCE}")
endif()
else()
unset(CELT_SOURCE)
endif()

View File

@ -121,12 +121,15 @@ macro(setup_target TARGET)
if(USE_CELT)
target_compile_definitions(${TARGET} PRIVATE VGM_USE_CELT)
if(LINK)
if(WIN32 AND LINK)
add_dependencies(${TARGET} libcelt)
target_link_libraries(${TARGET}
${VGM_BINARY_DIR}/ext_libs/libcelt-0061.lib
${VGM_BINARY_DIR}/ext_libs/libcelt-0110.lib)
endif()
if(NOT WIN32 AND LINK)
target_link_libraries(${TARGET} celt0061 celt0110 m)
endif()
endif()
if(USE_SPEEX)