From f604acf5bb348734d114ba3b54e3385ba1a508d3 Mon Sep 17 00:00:00 2001 From: "Tom M." Date: Fri, 27 Dec 2024 11:30:13 +0100 Subject: [PATCH] Restore discovery of libsndfile on Ubuntu (#1454) --- CMakeLists.txt | 7 +- FluidSynthConfig.cmake.in | 5 +- cmake_admin/FindFLAC.cmake | 106 ++++++++++++++++ cmake_admin/FindOgg.cmake | 84 +++++++++++++ cmake_admin/FindSndFileLegacy.cmake | 182 ++++++++++++++++++++++++++++ cmake_admin/FindVorbis.cmake | 127 +++++++++++++++++++ cmake_admin/Findmp3lame.cmake | 63 ++++++++++ cmake_admin/Findmpg123.cmake | 108 +++++++++++++++++ 8 files changed, 680 insertions(+), 2 deletions(-) create mode 100644 cmake_admin/FindFLAC.cmake create mode 100644 cmake_admin/FindOgg.cmake create mode 100644 cmake_admin/FindSndFileLegacy.cmake create mode 100644 cmake_admin/FindVorbis.cmake create mode 100644 cmake_admin/Findmp3lame.cmake create mode 100644 cmake_admin/Findmpg123.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f1104992a..8b01a1af5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -520,7 +520,7 @@ set ( ALSA_MINIMUM_VERSION 0.9.1 ) set ( DBUS_MINIMUM_VERSION 1.11.12 ) set ( GLIB2_MINUMUM_VERSION 2.6.5 ) set ( LIBINSTPATCH_MINIMUM_VERSION 1.1.0 ) -set ( LIBSNDFILE_MINIMUM_VERSION 1.2.1 ) +set ( LIBSNDFILE_MINIMUM_VERSION 1.0.0 ) set ( PIPEWIRE_MINIMUM_VERSION 0.3 ) set ( PORTAUDIO_MINIMUM_VERSION 2.19 ) set ( PULSEAUDIO_MINIMUM_VERSION 2.0 ) @@ -546,6 +546,11 @@ unset ( LIBSNDFILE_HASVORBIS CACHE ) if ( enable-libsndfile ) #set(CMAKE_FIND_DEBUG_MODE ON) find_package ( SndFile ${LIBSNDFILE_MINIMUM_VERSION} QUIET ) + if ( NOT SndFile_FOUND ) + # Not all distros have switched to libsndfile's cmake based build system, see #1445. + # Therefore, discover sndfile via the legacy pkg-config magic. + find_package ( SndFileLegacy ) + endif () set ( LIBSNDFILE_SUPPORT ${SndFile_FOUND} ) if ( LIBSNDFILE_SUPPORT ) message ( STATUS "Found libSndFile: ${SndFile_VERSION}" ) diff --git a/FluidSynthConfig.cmake.in b/FluidSynthConfig.cmake.in index 83b1ae2ee..d2e0c5e9d 100644 --- a/FluidSynthConfig.cmake.in +++ b/FluidSynthConfig.cmake.in @@ -22,6 +22,7 @@ set(FLUIDSYNTH_SUPPORT_WINMIDI @WINMIDI_SUPPORT@) set(FLUIDSYNTH_SUPPORT_DLS @LIBINSTPATCH_SUPPORT@) set(FLUIDSYNTH_SUPPORT_LIBINSTPATCH @LIBINSTPATCH_SUPPORT@) set(FLUIDSYNTH_SUPPORT_LIBSNDFILE @LIBSNDFILE_SUPPORT@) +set(FLUIDSYNTH_SUPPORT_LIBSNDFILE_LEGACY @SndFileLegacy_FOUND@) set(FLUIDSYNTH_SUPPORT_SF3 @LIBSNDFILE_HASVORBIS@) # Miscrellaneous support @@ -96,7 +97,9 @@ if(NOT FLUIDSYNTH_IS_SHARED) find_dependency(InstPatch @LIBINSTPATCH_MINIMUM_VERSION@) endif() - if(FLUIDSYNTH_SUPPORT_LIBSNDFILE AND NOT TARGET SndFile::sndfile) + if(FLUIDSYNTH_SUPPORT_LIBSNDFILE_LEGACY AND NOT TARGET SndFile::sndfile) + find_dependency(SndFileLegacy @LIBSNDFILE_MINIMUM_VERSION@) + elseif(FLUIDSYNTH_SUPPORT_LIBSNDFILE AND NOT TARGET SndFile::sndfile) find_dependency(SndFile @LIBSNDFILE_MINIMUM_VERSION@) endif() diff --git a/cmake_admin/FindFLAC.cmake b/cmake_admin/FindFLAC.cmake new file mode 100644 index 000000000..2de2f41a8 --- /dev/null +++ b/cmake_admin/FindFLAC.cmake @@ -0,0 +1,106 @@ +#[=======================================================================[.rst: +FindFLAC +------- + +Finds the FLAC library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``FLAC::FLAC`` + The FLAC C library. +``FLAC::FLAC++`` + The FLAC C++ library. + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``FLAC_FOUND`` + True if both libraries were found. +``FLAC_FLAC_FOUND`` + True if the C library was found. +``FLAC_FLAC++_FOUND`` + True if the C++ library was found.. + +#]=======================================================================] + +# Use pkg-config if available +find_package(PkgConfig QUIET) +pkg_check_modules(PC_FLAC QUIET flac) +pkg_check_modules(PC_FLAC++ QUIET flac++) + +# Find the headers and libraries +find_path( + FLAC_INCLUDE_DIR + NAMES "FLAC/all.h" + HINTS "PC_FLAC_INCLUDEDIR") + +find_path( + FLAC++_INCLUDE_DIR + NAMES "FLAC++/all.h" + HINTS "PC_FLAC++_INCLUDEDIR") + +find_library( + FLAC_LIBRARY + NAMES "FLAC" + HINTS "${PC_FLAC_LIBDIR}") + +find_library( + FLAC++_LIBRARY + NAMES "FLAC++" + HINTS "${PC_FLAC++_LIBDIR}") + +# Handle transitive dependencies +if(PC_FLAC_FOUND) + get_target_properties_from_pkg_config("${FLAC_LIBRARY}" "PC_FLAC" "_flac") +else() + if(NOT TARGET "Ogg::ogg") + find_package(Ogg QUIET) + endif() + set(_flac_link_libraries "Ogg::ogg" ${MATH_LIBRARY}) +endif() + +if(PC_FLAC++_FOUND) + get_target_properties_from_pkg_config("${FLAC++_LIBRARY}" "PC_FLAC++" + "_flac++") +else() + set(_flac++_link_libraries "FLAC::FLAC") +endif() + +# Forward the result to CMake +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + FLAC REQUIRED_VARS "FLAC_LIBRARY" "FLAC_INCLUDE_DIR" "FLAC++_LIBRARY" + "FLAC++_INCLUDE_DIR") + +# Create the target +if(FLAC_FOUND AND NOT TARGET FLAC::FLAC) + add_library(FLAC::FLAC UNKNOWN IMPORTED) + set_target_properties( + FLAC::FLAC + PROPERTIES IMPORTED_LOCATION "${FLAC_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${_flac_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${FLAC_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${_flac_link_libraries}" + INTERFACE_LINK_DIRECTORIES "${_flac_link_directories}") + set(FLAC_FLAC_FOUND TRUE) +endif() + +if(FLAC_FOUND AND NOT TARGET FLAC::FLAC++) + add_library(FLAC::FLAC++ UNKNOWN IMPORTED) + set_target_properties( + FLAC::FLAC++ + PROPERTIES IMPORTED_LOCATION "${FLAC++_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${_flac++_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${FLAC++_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${_flac++_link_libraries}" + INTERFACE_LINK_DIRECTORIES "${_flac++_link_directories}") + set(FLAC_FLAC++_FOUND TRUE) +endif() + +mark_as_advanced(FLAC_LIBRARY FLAC_INCLUDE_DIR FLAC++_LIBRARY + FLAC++_INCLUDE_DIR) diff --git a/cmake_admin/FindOgg.cmake b/cmake_admin/FindOgg.cmake new file mode 100644 index 000000000..8044c9414 --- /dev/null +++ b/cmake_admin/FindOgg.cmake @@ -0,0 +1,84 @@ +#[=======================================================================[.rst: +FindOgg +------- + +Finds the Ogg library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``Ogg::ogg`` + The Ogg library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``Ogg_FOUND`` + True if the system has the Ogg library. + +For compatibility with upstream, the following variables are also set: + +``Ogg_INCLUDE_DIR`` +``Ogg_INCLUDE_DIRS`` +``Ogg_LIBRARY`` +``Ogg_LIBRARIES`` +``OGG_INCLUDE_DIR`` +``OGG_INCLUDE_DIRS`` +``OGG_LIBRARY`` +``OGG_LIBRARIES`` +``OGG_FOUND`` + +#]=======================================================================] + +# Use pkg-config if available +find_package(PkgConfig QUIET) +pkg_check_modules(PC_OGG QUIET ogg) + +# Find the headers and library +find_path( + Ogg_INCLUDE_DIR + NAMES "ogg/ogg.h" + HINTS "${PC_OGG_INCLUDEDIR}") + +find_library( + _ogg_library + NAMES "ogg" + HINTS "${PC_OGG_LIBDIR}") + +# Extract additional flags if pkg-config is available +if(PC_OGG_FOUND) + get_target_properties_from_pkg_config("${_ogg_library}" "PC_OGG" "_ogg") +endif() + +# Forward the result to CMake +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Ogg REQUIRED_VARS "_ogg_library" + "Ogg_INCLUDE_DIR") + +# Create the target +if(Ogg_FOUND AND NOT TARGET Ogg::ogg) + add_library(Ogg::ogg UNKNOWN IMPORTED) + set_target_properties( + Ogg::ogg + PROPERTIES IMPORTED_LOCATION "${_ogg_library}" + INTERFACE_COMPILE_OPTIONS "${_ogg_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${Ogg_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${_ogg_link_libraries}" + INTERFACE_LINK_DIRECTORIES "${_ogg_link_directories}") + + # Set additional variables for compatibility with upstream config + set(Ogg_INCLUDE_DIRS "${Ogg_INCLUDE_DIR}") + set(Ogg_LIBRARY Ogg::ogg) + set(Ogg_LIBRARIES Ogg::ogg) + set(OGG_INCLUDE_DIR "${${Ogg_INCLUDE_DIR}}") + set(OGG_INCLUDE_DIRS "${${Ogg_INCLUDE_DIR}}") + set(OGG_LIBRARY Ogg::ogg) + set(OGG_LIBRARIES Ogg::ogg) + set(OGG_FOUND TRUE) +endif() + +mark_as_advanced(_ogg_library) diff --git a/cmake_admin/FindSndFileLegacy.cmake b/cmake_admin/FindSndFileLegacy.cmake new file mode 100644 index 000000000..4565110b0 --- /dev/null +++ b/cmake_admin/FindSndFileLegacy.cmake @@ -0,0 +1,182 @@ +#[=======================================================================[.rst: +FindSndFile +------- + +Finds the SndFile library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``SndFile::sndfile`` + The SndFile library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``SndFile_FOUND`` + True if the system has the SndFile library. +``SndFile_VERSION`` + The version of the SndFile library which was found. +``SndFile_WITH_EXTERNAL_LIBS`` + True if the library was built with Xiph codecs. + +For compatibility with upstream, the following variables are also set: + +``SndFile_WITH_MPEG`` +``SndFile_VERSION_MAJOR`` +``SndFile_VERSION_MINOR`` +``SndFile_VERSION_PATCH`` +``SndFile_LIBRARY`` +``SndFile_LIBRARIES`` +``SNDFILE_LIBRARY`` +``SNDFILE_LIBRARIES`` +``SNDFILE_INCLUDE_DIR`` + +#]=======================================================================] + +# Use pkg-config if available +find_package(PkgConfig QUIET) +pkg_check_modules(PC_SNDFILE QUIET sndfile) + +# Find the headers and libraries +find_path( + SndFile_INCLUDE_DIR + NAMES "sndfile.h" + HINTS "${PC_SNDFILE_INCLUDEDIR}") + +find_library( + _sndfile_library + NAMES "sndfile" "sndfile-1" + HINTS "${PC_SNDFILE_LIBDIR}") + +# Get version from pkg-config or read the config header +if(PC_SNDFILE_VERSION) + set(SndFile_VERSION "${PC_SNDFILE_VERSION}") + string(REPLACE "." ";" _sndfile_version_list "${SndFile_VERSION}") + list(GET _sndfile_version_list 0 SndFile_VERSION_MAJOR) + list(GET _sndfile_version_list 1 SndFile_VERSION_MINOR) + list(GET _sndfile_version_list 2 SndFile_VERSION_PATCH) +elseif(SndFile_INCLUDE_DIR) + file(READ "${SndFile_INCLUDE_DIR}/sndfile.h" _sndfile_h) + if("#define SNDFILE_1" MATCHES _snfile_h) + set(SndFile_VERSION "1") + set(SndFile_VERSION_MAJOR "1") + endif() +endif() + +# Check the features SndFile was built with +# 2024-01-02: Recent versions of libsndfile don't seem to provide a pkgconfig file and older version who did are lacking private libraries like OGG. +if(FALSE) #PC_SNDFILE_FOUND + if("vorbis" IN_LIST PC_SNDFILE_STATIC_LIBRARIES) + set(SndFile_WITH_EXTERNAL_LIBS TRUE) + endif() + if("mpg123" IN_LIST PC_SNDFILE_STATIC_LIBRARIES) + set(SndFile_WITH_MPEG TRUE) + endif() +elseif(_sndfile_library) + # sndfile may need any of these libraries + find_package(Ogg 1.3 QUIET) + find_package(Vorbis QUIET) + find_package(FLAC QUIET) + find_package(Opus QUIET) + find_package(mp3lame QUIET) + find_package(mpg123 QUIET) + + if(NOT CMAKE_CROSSCOMPILING) + include(CheckSourceRuns) + set(_backup_includes ${CMAKE_REQUIRED_INCLUDES}) + set(_backup_libraries ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_INCLUDES "${SndFile_INCLUDE_DIR}") + set(CMAKE_REQUIRED_LIBRARIES "${_sndfile_library}") + + set(_optional_libs "MPG123::libmpg123" "mp3lame::mp3lame" "FLAC::FLAC" + "Opus::opus" "Vorbis::vorbisenc" "Ogg::ogg") + foreach(_target ${_optional_libs}) + if(TARGET "${_target}") + list(APPEND CMAKE_REQUIRED_LIBRARIES "${_target}") + endif() + endforeach() + + check_source_runs( + C + "#include +#include +int main() { + SF_FORMAT_INFO info = {SF_FORMAT_VORBIS}; + sf_command(NULL, SFC_GET_FORMAT_INFO, &info, sizeof info); + return info.name != NULL ? EXIT_SUCCESS : EXIT_FAILURE; +}" + SNDFILE_SUPPORTS_VORBIS) + + check_source_runs( + C + "#include +#include +int main() { + SF_FORMAT_INFO info = {SF_FORMAT_MPEG_LAYER_III}; + sf_command(NULL, SFC_GET_FORMAT_INFO, &info, sizeof info); + return info.name != NULL ? EXIT_SUCCESS : EXIT_FAILURE; +}" + SNDFILE_SUPPORTS_MPEG) + + set(SndFile_WITH_EXTERNAL_LIBS ${SNDFILE_SUPPORTS_VORBIS}) + set(SndFile_WITH_MPEG ${SNDFILE_SUPPORTS_MPEG}) + set(CMAKE_REQUIRED_INCLUDES ${_backup_includes}) + set(CMAKE_REQUIRED_LIBRARIES ${_backup_libraries}) + else() + message( + STATUS + "Cross-compiling without pkg-config - cannot check for external libraries." + "If you have the upstream CMake config set CMAKE_FIND_PACKAGE_PREFER_CONFIG to true for accurate results." + ) + set(SndFile_WITH_EXTERNAL_LIBS FALSE) + set(SndFile_WITH_MPEG FALSE) + endif() +endif() + +# Handle transitive dependencies +if(PC_SNDFILE_FOUND) + get_target_properties_from_pkg_config("${_sndfile_library}" "PC_SNDFILE" + "_sndfile") +else() + if(SndFile_WITH_EXTERNAL_LIBS) + list(APPEND _sndfile_link_libraries "FLAC::FLAC" "Opus::opus" + "Vorbis::vorbisenc" "Ogg::ogg") + endif() + if(SndFile_WITH_MPEG) + list(APPEND _sndfile_link_libraries "MPG123::libmpg123" "mp3lame::mp3lame") + endif() +endif() + +# Forward the result to CMake +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + SndFileLegacy + REQUIRED_VARS "_sndfile_library" "SndFile_INCLUDE_DIR" + VERSION_VAR "SndFile_VERSION") + +if(SndFileLegacy_FOUND AND NOT TARGET SndFile::sndfile) + add_library(SndFile::sndfile UNKNOWN IMPORTED) + set_target_properties( + SndFile::sndfile + PROPERTIES IMPORTED_LOCATION "${_sndfile_library}" + INTERFACE_COMPILE_OPTIONS "${_sndfile_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${SndFile_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${_sndfile_link_libraries}" + INTERFACE_LINK_DIRECTORIES "${_sndfile_link_directories}") + + # Set additional variables for compatibility with upstream config + set(SNDFILE_FOUND TRUE) + set(SndFile_FOUND TRUE) + set(SndFile_LIBRARY SndFile::sndfile) + set(SndFile_LIBRARIES SndFile::sndfile) + set(SNDFILE_LIBRARY SndFile::sndfile) + set(SNDFILE_LIBRARIES SndFile::sndfile) + set(SNDFILE_INCLUDE_DIR "${SndFile_INCLUDE_DIR}") +endif() + +mark_as_advanced(_sndfile_library) diff --git a/cmake_admin/FindVorbis.cmake b/cmake_admin/FindVorbis.cmake new file mode 100644 index 000000000..0865c3ea2 --- /dev/null +++ b/cmake_admin/FindVorbis.cmake @@ -0,0 +1,127 @@ +#[=======================================================================[.rst: +FindVorbis +------- + +Finds the Vorbis library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``Vorbis::vorbisc`` + The Vorbis core library +``Vorbis::vorbisenc`` + The Vorbis encoder library +``Vorbis::vorbisfile`` + The Vorbis file library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``Vorbis_FOUND`` + True if all vorbis libraries were found. +``Vorbis_Vorbis_FOUND`` + True if the base vorbis library was found. +``Vorbis_Enc_FOUND`` + True if the encoder library was found. +``Vorbis_File_FOUND`` + True if the file library was found. + +#]=======================================================================] + +# Use pkg-config if available +find_package(PkgConfig QUIET) +pkg_check_modules(PC_VORBIS QUIET vorbis) +pkg_check_modules(PC_VORBISENC QUIET vorbisenc) +pkg_check_modules(PC_VORBISFILE QUIET vorbisfile) + +# Find the headers and libraries +find_path( + Vorbis_INCLUDE_DIR + NAMES "vorbis/codec.h" + HINTS "${PC_VORBIS_INCLUDEDIR}") + +find_library( + Vorbis_LIBRARY + NAMES "vorbis" + HINTS "${PC_VORBIS_LIBDIR}") + +find_library( + Vorbis_Enc_LIBRARY + NAMES "vorbisenc" + HINTS "${PC_VORBISENC_LIBDIR}") + +find_library( + Vorbis_File_LIBRARY + NAMES "vorbisfile" + HINTS "${PC_VORBISFILE_LIBDIR}") + +# Handle transitive dependencies +if(PC_VORBIS_FOUND) + get_target_properties_from_pkg_config("${Vorbis_LIBRARY}" "PC_VORBIS" + "_vorbis") +else() + if(NOT TARGET Ogg::ogg) + find_package(Ogg QUIET) + endif() + set(_vorbis_link_libraries "Ogg::ogg" ${MATH_LIBRARY}) +endif() + +# Extract additional flags if pkg-config is available +if(PC_VORBISENC_FOUND) + get_target_properties_from_pkg_config("${Vorbis_Enc_LIBRARY}" "PC_VORBISENC" + "_vorbis_enc") +endif() + +if(PC_VORBISFILE_FOUND) + get_target_properties_from_pkg_config("${Vorbis_File_LIBRARY}" + "PC_VORBISFILE" "_vorbis_file") +endif() + +# Forward the result to CMake +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + Vorbis REQUIRED_VARS "Vorbis_LIBRARY" "Vorbis_Enc_LIBRARY" + "Vorbis_File_LIBRARY" "Vorbis_INCLUDE_DIR") + +# Create the targets +if(Vorbis_FOUND AND NOT TARGET Vorbis::vorbis) + add_library(Vorbis::vorbis UNKNOWN IMPORTED) + set_target_properties( + Vorbis::vorbis + PROPERTIES IMPORTED_LOCATION "${Vorbis_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${_vorbis_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${Vorbis_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${_vorbis_link_libraries}" + INTERFACE_LINK_DIRECTORIES "${_vorbis_link_directories}") + set(Vorbis_Vorbis_FOUND TRUE) +endif() + +if(Vorbis_FOUND AND NOT TARGET Vorbis::vorbisenc) + add_library(Vorbis::vorbisenc UNKNOWN IMPORTED) + set_target_properties( + Vorbis::vorbisenc + PROPERTIES IMPORTED_LOCATION "${Vorbis_Enc_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${_vorbis_enc_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${Vorbis_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "Vorbis::vorbis" + INTERFACE_LINK_DIRECTORIES "${_vorbis_enc_link_directories}") + set(Vorbis_Enc_FOUND TRUE) +endif() + +if(Vorbis_FOUND AND NOT TARGET Vorbis::vorbisfile) + add_library(Vorbis::vorbisfile UNKNOWN IMPORTED) + set_target_properties( + Vorbis::vorbisfile + PROPERTIES IMPORTED_LOCATION "${Vorbis_File_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${_vorbis_file_compile_options}" + INTERFACE_INCLUDE_DIRECTORIES "${Vorbis_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "Vorbis::vorbis" + INTERFACE_LINK_DIRECTORIES "${_vorbis_file_link_directories}") + set(Vorbis_File_FOUND TRUE) +endif() + +mark_as_advanced(Vorbis_LIBRARY Vorbis_Enc_LIBRARY Vorbis_File_LIBRARY) diff --git a/cmake_admin/Findmp3lame.cmake b/cmake_admin/Findmp3lame.cmake new file mode 100644 index 000000000..cd8b4c8a1 --- /dev/null +++ b/cmake_admin/Findmp3lame.cmake @@ -0,0 +1,63 @@ +#[=======================================================================[.rst: +Findmp3lame +------- + +Finds the mp3lame library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``mp3lame::mp3lame`` + The mp3lame library. +``mp3lame::mpghip`` + The mpghip library. + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``mp3lame_FOUND`` + True if the mp3lame library was found. +``mp3lame_mpghip_FOUND`` + True if the mpghip library was found. + +#]=======================================================================] + +# Find the headers and libraries +find_path(mp3lame_INCLUDE_DIR NAMES "lame/lame.h") + +find_library(mp3lame_mp3lame_LIBRARY NAMES "mp3lame" "libmp3lame" + "libmp3lame-static") +find_library(mp3lame_mpghip_LIBRARY NAMES "mpghip" "libmpghip" + "libmpghip-static") + +# Forward the result to CMake +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + mp3lame REQUIRED_VARS "mp3lame_mp3lame_LIBRARY" + "mp3lame_INCLUDE_DIR") + +# Create the targets +if(mp3lame_FOUND AND NOT TARGET mp3lame::mp3lame) + add_library(mp3lame::mp3lame UNKNOWN IMPORTED) + set_target_properties( + mp3lame::mp3lame + PROPERTIES IMPORTED_LOCATION "${mp3lame_mp3lame_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${mp3lame_INCLUDE_DIR}") + set(mp3lame_mp3lame_FOUND TRUE) +endif() + +if(mp3lame_mpghip_LIBRARY AND NOT TARGET mp3lame::mpghip) + add_library(mp3lame::mpghip UNKNOWN IMPORTED) + set_target_properties( + mp3lame::mpghip + PROPERTIES IMPORTED_LOCATION "${mp3lame_mpghip_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${mp3lame_INCLUDE_DIR}") + set(mp3lame_mpghip_FOUND) +endif() + +mark_as_advanced(mp3lame_INCLUDE_DIR mp3lame_mp3lame_LIBRARY + mp3lame_mpghip_LIBRARY) diff --git a/cmake_admin/Findmpg123.cmake b/cmake_admin/Findmpg123.cmake new file mode 100644 index 000000000..3cb351679 --- /dev/null +++ b/cmake_admin/Findmpg123.cmake @@ -0,0 +1,108 @@ +#[=======================================================================[.rst: +Findmpg123 +------- + +Finds the mpg123 library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``MPG123::libmpg123`` + The mpg123 decoder library +``MPG123::libout123`` + The mpg123 output library +``MPG123::libsyn123`` + The mpg123 signal synthesis library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``mpg123_FOUND`` + True if the package was found. +``mpg123_libmpg123_FOUND`` + True if the decoder library was found. +``mpg123_libout123_FOUND`` + True if the output library was found. +``mpg123_libsyn123_FOUND`` + True if the signal synthesis library was found. + +#]=======================================================================] + +# Use pkg-config if available +find_package(PkgConfig QUIET) +pkg_check_modules(PC_MPG123 QUIET libmpg123) +pkg_check_modules(PC_OUT123 QUIET libout123) +pkg_check_modules(PC_SYN123 QUIET libsyn123) + +# Find the headers and libraries +find_path( + mpg123_INCLUDE_DIR + NAMES "mpg123.h" + HINTS "${PC_MPG123_INCLUDEDIR}") + +find_library( + mpg123_libmpg123_LIBRARY + NAMES "mpg123" + HINTS "${PC_MPG123_LIBDIR}") + +find_library( + mpg123_libout123_LIBRARY + NAMES "out123" + HINTS "${PC_OUT123_LIBDIR}") + +find_library( + mpg123_libsyn123_LIBRARY + NAMES "syn123" + HINTS "${PC_SYN123_LIBDIR}") + +# Extract additional flags if pkg-config is available +if(PC_MPG123_FOUND) + get_target_properties_from_pkg_config("${mpg123_libmpg123_LIBRARY}" + "PC_MPG123" "_libmpg123") +endif() +if(PC_OUT123_FOUND) + get_target_properties_from_pkg_config("${mpg123_libout123_LIBRARY}" + "PC_OUT123" "_libout123") +endif() +if(PC_SYN123_FOUND) + get_target_properties_from_pkg_config("${mpg123_libsyn123_LIBRARY}" + "PC_SYN123" "_libsyn123") +endif() + +# Mark which component were found +foreach(_component libmpg123 libout123 libsyn123) + if(mpg123_${_component}_LIBRARY) + set(mpg123_${_component}_FOUND TRUE) + else() + set(mpg123_${_component}_FOUND FALSE) + endif() +endforeach() + +# Forward the result to CMake +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + mpg123 + REQUIRED_VARS "mpg123_libmpg123_LIBRARY" "mpg123_INCLUDE_DIR" + HANDLE_COMPONENTS) + +# Create the targets +foreach(_component libmpg123 libout123 libsyn123) + if(mpg123_${_component}_FOUND AND NOT TARGET MPG123::${_component}) + add_library(MPG123::${_component} UNKNOWN IMPORTED) + set_target_properties( + MPG123::${_component} + PROPERTIES IMPORTED_LOCATION "${mpg123_${_component}_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${mpg123_INCLUDE_DIR}" + INTERFACE_COMPILE_OPTIONS "${_${_component}_compile_options}" + INTERFACE_LINK_LIBRARIES "${_${_component}_link_libraries}" + INTERFACE_LINK_DIRECTORIES + "${_${_component}_link_directories}") + endif() +endforeach() + +mark_as_advanced(mpg123_libmpg123_LIBRARY mpg123_libout123_LIBRARY + mpg123_libsyn123_LIBRARY mpg123_INCLUDE_DIR)