Skip to content

Commit

Permalink
Restore discovery of libsndfile on Ubuntu (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst authored Dec 27, 2024
1 parent 0f308a9 commit f604acf
Show file tree
Hide file tree
Showing 8 changed files with 680 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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}" )
Expand Down
5 changes: 4 additions & 1 deletion FluidSynthConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
106 changes: 106 additions & 0 deletions cmake_admin/FindFLAC.cmake
Original file line number Diff line number Diff line change
@@ -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)
84 changes: 84 additions & 0 deletions cmake_admin/FindOgg.cmake
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit f604acf

Please sign in to comment.