mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
CMake: Clean up the handling of libopus and libvorbis.
This commit is contained in:
+22
-48
@@ -470,24 +470,18 @@ if(NOT MINIAUDIO_NO_LIBVORBIS)
|
||||
# Try pkg-config first
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(PC_VORBISFILE vorbisfile)
|
||||
pkg_check_modules(vorbisfile IMPORTED_TARGET vorbisfile)
|
||||
endif()
|
||||
|
||||
if(PC_VORBISFILE_FOUND)
|
||||
message(STATUS "Found vorbisfile via pkg-config: ${PC_VORBISFILE_LIBRARIES}")
|
||||
set(HAS_LIBVORBIS TRUE)
|
||||
if(TARGET PkgConfig::vorbisfile)
|
||||
add_library(vorbisfile ALIAS PkgConfig::vorbisfile)
|
||||
else()
|
||||
# Fallback to building from source.
|
||||
add_libvorbis_subdirectory()
|
||||
if(NOT TARGET vorbisfile)
|
||||
message(STATUS "libvorbisfile not found. miniaudio_libvorbis will be excluded.")
|
||||
else()
|
||||
set(HAS_LIBVORBIS TRUE)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "libvorbisfile already found.")
|
||||
set(HAS_LIBVORBIS TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -499,24 +493,18 @@ if(NOT MINIAUDIO_NO_LIBOPUS)
|
||||
# Try pkg-config first
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(PC_OPUSFILE opusfile)
|
||||
pkg_check_modules(opusfile IMPORTED_TARGET opusfile)
|
||||
endif()
|
||||
|
||||
if(PC_OPUSFILE_FOUND)
|
||||
message(STATUS "Found opusfile via pkg-config: ${PC_OPUSFILE_LIBRARIES}")
|
||||
set(HAS_LIBOPUS TRUE)
|
||||
if(TARGET PkgConfig::opusfile)
|
||||
add_library(opusfile ALIAS PkgConfig::opusfile)
|
||||
else()
|
||||
# Fallback to building from source.
|
||||
add_libopusfile_subdirectory()
|
||||
if(NOT TARGET opusfile)
|
||||
message(STATUS "libopusfile not found. miniaudio_libopus will be excluded.")
|
||||
else()
|
||||
set(HAS_LIBOPUS TRUE)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "libopusfile already found.")
|
||||
set(HAS_LIBOPUS TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -667,19 +655,12 @@ endif()
|
||||
|
||||
|
||||
# Extra Decoders
|
||||
add_library(libvorbis_interface INTERFACE)
|
||||
if(HAS_LIBVORBIS)
|
||||
if(TARGET vorbisfile)
|
||||
target_link_libraries(libvorbis_interface INTERFACE vorbisfile)
|
||||
elseif(PC_VORBISFILE_FOUND)
|
||||
target_link_libraries (libvorbis_interface INTERFACE ${PC_VORBISFILE_LIBRARIES})
|
||||
target_include_directories(libvorbis_interface INTERFACE ${PC_VORBISFILE_INCLUDE_DIRS})
|
||||
target_link_directories (libvorbis_interface INTERFACE ${PC_VORBISFILE_LIBRARY_DIRS})
|
||||
target_compile_options (libvorbis_interface INTERFACE ${PC_VORBISFILE_CFLAGS_OTHER})
|
||||
endif()
|
||||
if(TARGET vorbisfile)
|
||||
add_library (libvorbis_interface INTERFACE)
|
||||
target_link_libraries(libvorbis_interface INTERFACE vorbisfile)
|
||||
endif()
|
||||
|
||||
if(HAS_LIBVORBIS)
|
||||
if(TARGET libopus_interface)
|
||||
add_library(miniaudio_libvorbis
|
||||
extras/decoders/libvorbis/miniaudio_libvorbis.c
|
||||
extras/decoders/libvorbis/miniaudio_libvorbis.h
|
||||
@@ -696,25 +677,18 @@ if(HAS_LIBVORBIS)
|
||||
target_include_directories(miniaudio_libvorbis PUBLIC extras/decoders/libvorbis/)
|
||||
endif()
|
||||
|
||||
add_library(libopus_interface INTERFACE)
|
||||
if(HAS_LIBOPUS)
|
||||
if(TARGET opusfile)
|
||||
target_link_libraries (libopus_interface INTERFACE opusfile)
|
||||
elseif(PC_OPUSFILE_FOUND)
|
||||
target_link_libraries (libopus_interface INTERFACE ${PC_OPUSFILE_LIBRARIES})
|
||||
target_include_directories(libopus_interface INTERFACE ${PC_OPUSFILE_INCLUDE_DIRS})
|
||||
target_link_directories (libopus_interface INTERFACE ${PC_OPUSFILE_LIBRARY_DIRS})
|
||||
target_compile_options (libopus_interface INTERFACE ${PC_OPUSFILE_CFLAGS_OTHER})
|
||||
endif()
|
||||
|
||||
if(TARGET opusfile)
|
||||
add_library (libopus_interface INTERFACE)
|
||||
target_link_libraries(libopus_interface INTERFACE opusfile)
|
||||
endif()
|
||||
|
||||
if(HAS_LIBOPUS)
|
||||
if(TARGET libopus_interface)
|
||||
add_library(miniaudio_libopus
|
||||
extras/decoders/libopus/miniaudio_libopus.c
|
||||
extras/decoders/libopus/miniaudio_libopus.h
|
||||
)
|
||||
|
||||
|
||||
list(APPEND LIBS_TO_INSTALL miniaudio_libopus)
|
||||
if(MINIAUDIO_INSTALL)
|
||||
install(FILES extras/decoders/libopus/miniaudio_libopus.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/miniaudio/extras/decoders/libopus)
|
||||
@@ -893,27 +867,27 @@ if (MINIAUDIO_BUILD_EXAMPLES)
|
||||
add_miniaudio_example(miniaudio_custom_backend custom_backend.c)
|
||||
|
||||
add_miniaudio_example(miniaudio_custom_decoder_engine custom_decoder_engine.c)
|
||||
if(HAS_LIBVORBIS)
|
||||
if(TARGET libvorbis_interface)
|
||||
target_link_libraries(miniaudio_custom_decoder_engine PRIVATE libvorbis_interface)
|
||||
else()
|
||||
target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBVORBIS)
|
||||
message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder_engine.")
|
||||
endif()
|
||||
if(HAS_LIBOPUS)
|
||||
target_link_libraries(miniaudio_custom_decoder_engine PRIVATE libopus_interface)
|
||||
if(TARGET libopus_interface)
|
||||
target_link_libraries(miniaudio_custom_decoder_engine PRIVATE libopus_interface)
|
||||
else()
|
||||
target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBOPUS)
|
||||
message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder_engine.")
|
||||
endif()
|
||||
|
||||
add_miniaudio_example(miniaudio_custom_decoder custom_decoder.c)
|
||||
if(HAS_LIBVORBIS)
|
||||
if(TARGET libvorbis_interface)
|
||||
target_link_libraries(miniaudio_custom_decoder PRIVATE libvorbis_interface)
|
||||
else()
|
||||
target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBVORBIS)
|
||||
message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder.")
|
||||
endif()
|
||||
if(HAS_LIBOPUS)
|
||||
if(TARGET libopus_interface)
|
||||
target_link_libraries(miniaudio_custom_decoder PRIVATE libopus_interface)
|
||||
else()
|
||||
target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBOPUS)
|
||||
@@ -981,10 +955,10 @@ string(JOIN ", " MINIAUDIO_PC_REQUIRES_PRIVATE ${LINKED_LIBS})
|
||||
|
||||
# Add vorbisfile and opusfile to pkg-config dependencies if found via pkg-config
|
||||
set(PC_REQUIRES_PRIVATE_LIST)
|
||||
if(PC_VORBISFILE_FOUND AND HAS_LIBVORBIS)
|
||||
if(TARGET vorbisfile)
|
||||
list(APPEND PC_REQUIRES_PRIVATE_LIST "vorbisfile")
|
||||
endif()
|
||||
if(PC_OPUSFILE_FOUND AND HAS_LIBOPUS)
|
||||
if(TARGET opusfile)
|
||||
list(APPEND PC_REQUIRES_PRIVATE_LIST "opusfile")
|
||||
endif()
|
||||
if(PC_REQUIRES_PRIVATE_LIST)
|
||||
|
||||
Reference in New Issue
Block a user