Commit 32df5aeb3d0dca1a28533d413bdd54ea072fe0d3

Anonymous Maarten 2022-06-15T03:16:28

Check result of FindLibraryAndSONAME before use

diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index fd98ffb..b812f6a 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -111,8 +111,8 @@ macro(CheckALSA)
       if(SDL_ALSA_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
       endif()
-      if(SDL_ALSA_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("asound")
+      FindLibraryAndSONAME("asound")
+      if(SDL_ALSA_SHARED AND ASOUND_LIB AND HAVE_SDL_LOADSO)
         set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
         set(HAVE_ALSA_SHARED TRUE)
       else()
@@ -140,8 +140,8 @@ macro(CheckPipewire)
             if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO)
                 message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
             endif()
-            if(SDL_PIPEWIRE_SHARED AND HAVE_SDL_LOADSO)
-                FindLibraryAndSONAME("pipewire-0.3")
+            FindLibraryAndSONAME("pipewire-0.3")
+            if(SDL_PIPEWIRE_SHARED AND PIPEWIRE_0.3_LIB AND HAVE_SDL_LOADSO)
                 set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
                 set(HAVE_PIPEWIRE_SHARED TRUE)
             else()
@@ -169,8 +169,8 @@ macro(CheckPulseAudio)
       if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
       endif()
-      if(SDL_PULSEAUDIO_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("pulse-simple")
+      FindLibraryAndSONAME("pulse-simple")
+      if(SDL_PULSEAUDIO_SHARED AND PULSE_SIMPLE_LIB AND HAVE_SDL_LOADSO)
         set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
         set(HAVE_PULSEAUDIO_SHARED TRUE)
       else()
@@ -198,8 +198,8 @@ macro(CheckJACK)
       if(SDL_JACK_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
       endif()
-      if(SDL_JACK_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("jack")
+      FindLibraryAndSONAME("jack")
+      if(SDL_JACK_SHARED AND JACK_LIB AND HAVE_SDL_LOADSO)
         set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
         set(HAVE_JACK_SHARED TRUE)
       else()
@@ -227,8 +227,8 @@ macro(CheckESD)
       if(SDL_ESD_SHARED AND NOT HAVE_SDL_LOADSO)
           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
       endif()
-      if(SDL_ESD_SHARED AND HAVE_SDL_LOADSO)
-          FindLibraryAndSONAME(esd)
+      FindLibraryAndSONAME(esd)
+      if(SDL_ESD_SHARED AND ESD_LIB AND HAVE_SDL_LOADSO)
           set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
           set(HAVE_ESD_SHARED TRUE)
       else()
@@ -260,9 +260,9 @@ macro(CheckARTS)
       if(SDL_ARTS_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
       endif()
-      if(SDL_ARTS_SHARED AND HAVE_SDL_LOADSO)
+      FindLibraryAndSONAME(artsc)
+      if(SDL_ARTS_SHARED AND ARTSC_LIB AND HAVE_SDL_LOADSO)
         # TODO
-        FindLibraryAndSONAME(artsc)
         set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
         set(HAVE_ARTS_SHARED TRUE)
       else()
@@ -291,8 +291,8 @@ macro(CheckNAS)
       if(SDL_NAS_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
       endif()
-      if(SDL_NAS_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("audio")
+      FindLibraryAndSONAME("audio")
+      if(SDL_NAS_SHARED AND AUDIO_LIB AND HAVE_SDL_LOADSO)
         set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
         set(HAVE_NAS_SHARED TRUE)
       else()
@@ -321,8 +321,8 @@ macro(CheckSNDIO)
       if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
       endif()
-      if(SDL_SNDIO_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("sndio")
+      FindLibraryAndSONAME("sndio")
+      if(SDL_SNDIO_SHARED AND SNDIO_LIB AND HAVE_SDL_LOADSO)
         set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
         set(HAVE_SNDIO_SHARED TRUE)
       else()
@@ -350,8 +350,8 @@ macro(CheckFusionSound)
       if(FUSIONSOUND_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
       endif()
-      if(FUSIONSOUND_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("fusionsound")
+      FindLibraryAndSONAME("fusionsound")
+      if(FUSIONSOUND_SHARED AND FUSIONSOUND_LIB AND HAVE_SDL_LOADSO)
         set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
         set(HAVE_FUSIONSOUND_SHARED TRUE)
       else()
@@ -375,8 +375,8 @@ macro(CheckLibSampleRate)
       if(SDL_LIBSAMPLERATE_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
       endif()
-      if(SDL_LIBSAMPLERATE_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("samplerate")
+      FindLibraryAndSONAME("samplerate")
+      if(SDL_LIBSAMPLERATE_SHARED AND SAMPLERATE_LIB AND HAVE_SDL_LOADSO)
         set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
         set(HAVE_LIBSAMPLERATE_SHARED TRUE)
       else()
@@ -459,7 +459,7 @@ macro(CheckX11)
         else()
           set(HAVE_X11_SHARED TRUE)
         endif()
-        if(HAVE_X11_SHARED)
+        if(HAVE_X11_SHARED AND X11_LIB AND XEXT_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
         else()
@@ -662,11 +662,11 @@ macro(CheckWayland)
       if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
       endif()
-      if(SDL_WAYLAND_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME(wayland-client)
-        FindLibraryAndSONAME(wayland-egl)
-        FindLibraryAndSONAME(wayland-cursor)
-        FindLibraryAndSONAME(xkbcommon)
+      FindLibraryAndSONAME(wayland-client)
+      FindLibraryAndSONAME(wayland-egl)
+      FindLibraryAndSONAME(wayland-cursor)
+      FindLibraryAndSONAME(xkbcommon)
+      if(SDL_WAYLAND_SHARED AND WAYLAND_CLIENT_LIB AND WAYLAND_EGL_LIB AND WAYLAND_CURSOR_LIB AND XKBCOMMON_LIB AND HAVE_SDL_LOADSO)
         set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
         set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
         set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
@@ -686,9 +686,9 @@ macro(CheckWayland)
             if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO)
                 message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
             endif()
-            if(SDL_WAYLAND_LIBDECOR_SHARED AND HAVE_SDL_LOADSO)
+            FindLibraryAndSONAME(decor-0)
+            if(SDL_WAYLAND_LIBDECOR_SHARED AND DECOR_0_LIB AND HAVE_SDL_LOADSO)
                 set(HAVE_LIBDECOR_SHARED TRUE)
-                FindLibraryAndSONAME(decor-0)
                 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
             else()
               list(APPEND EXTRA_LIBS ${LIBDECOR_LIBRARIES})
@@ -736,8 +736,8 @@ macro(CheckDirectFB)
       if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
         message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
       endif()
-      if(SDL_DIRECTFB_SHARED AND HAVE_SDL_LOADSO)
-        FindLibraryAndSONAME("directfb")
+      FindLibraryAndSONAME("directfb")
+      if(SDL_DIRECTFB_SHARED AND DIRECTFB_LIB AND HAVE_SDL_LOADSO)
         set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
         set(HAVE_DIRECTFB_SHARED TRUE)
       else()
@@ -1155,7 +1155,9 @@ macro(CheckHIDAPI)
         else()
           # libusb is loaded dynamically, so don't add it to EXTRA_LIBS
           FindLibraryAndSONAME("usb-1.0")
-          set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
+          if(USB_1.0_LIB)
+            set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
+          endif()
         endif()
       endif()
     endif()