From 773aad14f841578cbf055221fd78fd5e3fcaf60f Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 19 Mar 2023 21:24:51 +0100
Subject: [PATCH] cmake: Fix building without libsamplerate library
On Fedora, the headers for 32-bit and 64-bit are shared.
When building a 32-bit library, CMake found the header (that was installed
for the 64-bit libsamplerate development package). Because no 32-bit libsamplerate
library was installed, linking failed. (SDL_LIBSAMPLERATE_DYNAMIC was set to FALSE
because CMake could not find a library)
---
cmake/sdlchecks.cmake | 1 -
include/build_config/SDL_build_config.h.cmake | 2 +-
src/audio/SDL_audio.c | 6 +++---
src/audio/SDL_audio_c.h | 2 +-
src/audio/SDL_audiocvt.c | 18 +++++++++---------
5 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index a43fec49a318..b7061ec23897 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -250,7 +250,6 @@ macro(CheckLibSampleRate)
find_package(SampleRate QUIET)
if(SampleRate_FOUND AND TARGET SampleRate::samplerate)
set(HAVE_LIBSAMPLERATE TRUE)
- set(HAVE_LIBSAMPLERATE_H TRUE)
if(SDL_LIBSAMPLERATE_SHARED)
target_include_directories(sdl-build-options INTERFACE $<TARGET_PROPERTY:SampleRate::samplerate,INTERFACE_INCLUDE_DIRECTORIES>)
if(NOT HAVE_SDL_LOADSO)
diff --git a/include/build_config/SDL_build_config.h.cmake b/include/build_config/SDL_build_config.h.cmake
index 5d8d2dbc59b3..742172c24b09 100644
--- a/include/build_config/SDL_build_config.h.cmake
+++ b/include/build_config/SDL_build_config.h.cmake
@@ -226,7 +226,7 @@
#cmakedefine HAVE_O_CLOEXEC 1
#cmakedefine HAVE_LIBUDEV_H 1
-#cmakedefine HAVE_LIBSAMPLERATE_H 1
+#cmakedefine HAVE_LIBSAMPLERATE 1
#cmakedefine HAVE_LIBDECOR_H 1
#cmakedefine HAVE_D3D_H @HAVE_D3D_H@
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 56dc2e89641c..e8dd7f5c75fd 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -100,7 +100,7 @@ static const AudioBootStrap *const bootstrap[] = {
NULL
};
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
#ifdef SDL_LIBSAMPLERATE_DYNAMIC
static void *SRC_lib = NULL;
#endif
@@ -965,7 +965,7 @@ int SDL_InitAudio(const char *driver_name)
/* Make sure we have a list of devices available at startup. */
current_audio.impl.DetectDevices();
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
LoadLibSampleRate();
#endif
@@ -1590,7 +1590,7 @@ void SDL_QuitAudio(void)
SDL_zero(current_audio);
SDL_zeroa(open_devices);
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
UnloadLibSampleRate();
#endif
}
diff --git a/src/audio/SDL_audio_c.h b/src/audio/SDL_audio_c.h
index 97bef2adea63..d1c35b872ff7 100644
--- a/src/audio/SDL_audio_c.h
+++ b/src/audio/SDL_audio_c.h
@@ -36,7 +36,7 @@
/* Functions and variables exported from SDL_audio.c for SDL_sysaudio.c */
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
#include "samplerate.h"
extern SDL_bool SRC_available;
extern int SRC_converter;
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index b8b74159cb06..c29c80358077 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/src/audio/SDL_audiocvt.c
@@ -494,7 +494,7 @@ static int SDL_BuildAudioTypeCVTFromFloat(SDL_AudioCVT *cvt, const SDL_AudioForm
return retval;
}
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
static void SDL_ResampleCVT_SRC(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format)
{
@@ -533,7 +533,7 @@ static void SDL_ResampleCVT_SRC(SDL_AudioCVT *cvt, const int chans, const SDL_Au
}
}
-#endif /* HAVE_LIBSAMPLERATE_H */
+#endif /* HAVE_LIBSAMPLERATE */
static int SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format)
{
@@ -595,7 +595,7 @@ RESAMPLER_FUNCS(6)
RESAMPLER_FUNCS(8)
#undef RESAMPLER_FUNCS
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
#define RESAMPLER_FUNCS(chans) \
static void SDLCALL \
SDL_ResampleCVT_SRC_c##chans(SDL_AudioCVT *cvt, SDL_AudioFormat format) \
@@ -608,11 +608,11 @@ RESAMPLER_FUNCS(4)
RESAMPLER_FUNCS(6)
RESAMPLER_FUNCS(8)
#undef RESAMPLER_FUNCS
-#endif /* HAVE_LIBSAMPLERATE_H */
+#endif /* HAVE_LIBSAMPLERATE */
static SDL_AudioFilter ChooseCVTResampler(const int dst_channels)
{
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
if (SRC_available) {
switch (dst_channels) {
case 1:
@@ -629,7 +629,7 @@ static SDL_AudioFilter ChooseCVTResampler(const int dst_channels)
break;
}
}
-#endif /* HAVE_LIBSAMPLERATE_H */
+#endif /* HAVE_LIBSAMPLERATE */
switch (dst_channels) {
case 1:
@@ -934,7 +934,7 @@ static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, int newlen)
return offset ? ptr + (16 - offset) : ptr;
}
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
static int SDL_ResampleAudioStream_SRC(SDL_AudioStream *stream, const void *_inbuf, const int inbuflen, void *_outbuf, const int outbuflen)
{
const float *inbuf = (const float *)_inbuf;
@@ -1010,7 +1010,7 @@ static SDL_bool SetupLibSampleRateResampling(SDL_AudioStream *stream)
return SDL_TRUE;
}
-#endif /* HAVE_LIBSAMPLERATE_H */
+#endif /* HAVE_LIBSAMPLERATE */
static int SDL_ResampleAudioStream(SDL_AudioStream *stream, const void *_inbuf, const int inbuflen, void *_outbuf, const int outbuflen)
{
@@ -1141,7 +1141,7 @@ SDL_CreateAudioStream(SDL_AudioFormat src_format,
return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
}
-#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef HAVE_LIBSAMPLERATE
SetupLibSampleRateResampling(retval);
#endif