Commit fff421f4b8a75fdaae0b6ef01af9265c80b7ead9

Ryan C. Gordon 2021-08-23T23:59:54

cmake: fix a bunch of things to properly link without LOADSO enabled. The wrong logic, copy/pasted to a bunch of places, would correctly disable the dynamic loading but fail to specify the libraries that SDL would now need to explicitly link against.

diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index ba549c3..36e8b38 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -101,14 +101,13 @@ macro(CheckALSA)
       file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
       set(SDL_AUDIO_DRIVER_ALSA 1)
-      if(ALSA_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
-        else()
-          FindLibraryAndSONAME("asound")
-          set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
-          set(HAVE_ALSA_SHARED TRUE)
-        endif()
+      if(ALSA_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
+      endif()
+      if(ALSA_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("asound")
+        set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
+        set(HAVE_ALSA_SHARED TRUE)
       else()
         list(APPEND EXTRA_LIBS asound)
       endif()
@@ -131,14 +130,13 @@ macro(CheckPipewire)
             set(SOURCE_FILES ${SOURCE_FILES} ${PIPEWIRE_SOURCES})
             set(SDL_AUDIO_DRIVER_PIPEWIRE 1)
             list(APPEND EXTRA_CFLAGS ${PKG_PIPEWIRE_CFLAGS})
-            if(PIPEWIRE_SHARED)
-                if(NOT HAVE_SDL_LOADSO)
-                    message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
-                else()
-                    FindLibraryAndSONAME("pipewire-0.3")
-                    set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
-                    set(HAVE_PIPEWIRE_SHARED TRUE)
-                endif()
+            if(PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO)
+                message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
+            endif()
+            if(PIPEWIRE_SHARED AND HAVE_SDL_LOADSO)
+                FindLibraryAndSONAME("pipewire-0.3")
+                set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
+                set(HAVE_PIPEWIRE_SHARED TRUE)
             else()
                 list(APPEND EXTRA_LDFLAGS ${PKG_PIPEWIRE_LDFLAGS})
             endif()
@@ -162,14 +160,13 @@ macro(CheckPulseAudio)
       set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
       set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
       list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
-      if(PULSEAUDIO_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
-        else()
-          FindLibraryAndSONAME("pulse-simple")
-          set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
-          set(HAVE_PULSEAUDIO_SHARED TRUE)
-        endif()
+      if(PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
+      endif()
+      if(PULSEAUDIO_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("pulse-simple")
+        set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
+        set(HAVE_PULSEAUDIO_SHARED TRUE)
       else()
         list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
       endif()
@@ -192,14 +189,13 @@ macro(CheckJACK)
       set(SOURCE_FILES ${SOURCE_FILES} ${JACK_SOURCES})
       set(SDL_AUDIO_DRIVER_JACK 1)
       list(APPEND EXTRA_CFLAGS ${PKG_JACK_CFLAGS})
-      if(JACK_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
-        else()
-          FindLibraryAndSONAME("jack")
-          set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
-          set(HAVE_JACK_SHARED TRUE)
-        endif()
+      if(JACK_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
+      endif()
+      if(JACK_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("jack")
+        set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
+        set(HAVE_JACK_SHARED TRUE)
       else()
         list(APPEND EXTRA_LDFLAGS ${PKG_JACK_LDFLAGS})
       endif()
@@ -222,16 +218,15 @@ macro(CheckESD)
       set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
       set(SDL_AUDIO_DRIVER_ESD 1)
       list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
-      if(ESD_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
+      if(ESD_SHARED AND NOT HAVE_SDL_LOADSO)
           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
-        else()
+      endif()
+      if(ESD_SHARED AND HAVE_SDL_LOADSO)
           FindLibraryAndSONAME(esd)
           set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
           set(HAVE_ESD_SHARED TRUE)
-        endif()
       else()
-        list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
+          list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
       endif()
       set(HAVE_SDL_AUDIO TRUE)
     endif()
@@ -256,15 +251,14 @@ macro(CheckARTS)
       set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
       set(SDL_AUDIO_DRIVER_ARTS 1)
       set(HAVE_ARTS TRUE)
-      if(ARTS_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
-        else()
-          # TODO
-          FindLibraryAndSONAME(artsc)
-          set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
-          set(HAVE_ARTS_SHARED TRUE)
-        endif()
+      if(ARTS_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
+      endif()
+      if(ARTS_SHARED AND HAVE_SDL_LOADSO)
+        # TODO
+        FindLibraryAndSONAME(artsc)
+        set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
+        set(HAVE_ARTS_SHARED TRUE)
       else()
         list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
       endif()
@@ -288,14 +282,13 @@ macro(CheckNAS)
       file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
       set(SDL_AUDIO_DRIVER_NAS 1)
-      if(NAS_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
-        else()
-          FindLibraryAndSONAME("audio")
-          set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
-          set(HAVE_NAS_SHARED TRUE)
-        endif()
+      if(NAS_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
+      endif()
+      if(NAS_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("audio")
+        set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
+        set(HAVE_NAS_SHARED TRUE)
       else()
         list(APPEND EXTRA_LIBS ${D_NAS_LIB})
       endif()
@@ -319,14 +312,13 @@ macro(CheckSNDIO)
       file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
       set(SDL_AUDIO_DRIVER_SNDIO 1)
-      if(SNDIO_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
-        else()
-          FindLibraryAndSONAME("sndio")
-          set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
-          set(HAVE_SNDIO_SHARED TRUE)
-        endif()
+      if(SNDIO_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
+      endif()
+      if(SNDIO_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("sndio")
+        set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
+        set(HAVE_SNDIO_SHARED TRUE)
       else()
         list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
       endif()
@@ -349,14 +341,13 @@ macro(CheckFusionSound)
       set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
       set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
       list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
-      if(FUSIONSOUND_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
-        else()
-          FindLibraryAndSONAME("fusionsound")
-          set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
-          set(HAVE_FUSIONSOUND_SHARED TRUE)
-        endif()
+      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")
+        set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
+        set(HAVE_FUSIONSOUND_SHARED TRUE)
       else()
         list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
       endif()
@@ -375,14 +366,13 @@ macro(CheckLibSampleRate)
     check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
     if(HAVE_LIBSAMPLERATE_H)
       set(HAVE_LIBSAMPLERATE TRUE)
-      if(LIBSAMPLERATE_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
-        else()
-          FindLibraryAndSONAME("samplerate")
-          set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
-          set(HAVE_LIBSAMPLERATE_SHARED TRUE)
-        endif()
+      if(LIBSAMPLERATE_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
+      endif()
+      if(LIBSAMPLERATE_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("samplerate")
+        set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
+        set(HAVE_LIBSAMPLERATE_SHARED TRUE)
       else()
         list(APPEND EXTRA_LDFLAGS -lsamplerate)
       endif()
@@ -668,20 +658,19 @@ macro(CheckWayland)
           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
       endif()
 
-      if(WAYLAND_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
-        else()
-          FindLibraryAndSONAME(wayland-client)
-          FindLibraryAndSONAME(wayland-egl)
-          FindLibraryAndSONAME(wayland-cursor)
-          FindLibraryAndSONAME(xkbcommon)
-          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}\"")
-          set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
-          set(HAVE_WAYLAND_SHARED TRUE)
-        endif()
+      if(WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
+      endif()
+      if(WAYLAND_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME(wayland-client)
+        FindLibraryAndSONAME(wayland-egl)
+        FindLibraryAndSONAME(wayland-cursor)
+        FindLibraryAndSONAME(xkbcommon)
+        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}\"")
+        set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
+        set(HAVE_WAYLAND_SHARED TRUE)
       else()
         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
       endif()
@@ -693,14 +682,13 @@ macro(CheckWayland)
             set(HAVE_LIBDECOR_H 1)
             link_directories(${LIBDECOR_LIBRARY_DIRS})
             include_directories(${LIBDECOR_INCLUDE_DIRS})
-            if(LIBDECOR_SHARED)
-              if(NOT HAVE_SDL_LOADSO)
+            if(LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO)
                 message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
-              else()
+            endif()
+            if(LIBDECOR_SHARED AND HAVE_SDL_LOADSO)
                 set(HAVE_LIBDECOR_SHARED TRUE)
                 FindLibraryAndSONAME(decor-0)
                 set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
-              endif()
             else()
               set(EXTRA_LIBS ${LIBDECOR_LIBRARIES} ${EXTRA_LIBS})
             endif()
@@ -745,14 +733,13 @@ macro(CheckDirectFB)
       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
       set(SDL_VIDEO_RENDER_DIRECTFB 1)
       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
-      if(DIRECTFB_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
-        else()
-          FindLibraryAndSONAME("directfb")
-          set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
-          set(HAVE_DIRECTFB_SHARED TRUE)
-        endif()
+      if(DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
+      endif()
+      if(DIRECTFB_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME("directfb")
+        set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
+        set(HAVE_DIRECTFB_SHARED TRUE)
       else()
         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
       endif()
@@ -1242,16 +1229,15 @@ macro(CheckKMSDRM)
 
       set(SDL_VIDEO_DRIVER_KMSDRM 1)
 
-      if(KMSDRM_SHARED)
-        if(NOT HAVE_SDL_LOADSO)
-          message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
-        else()
-          FindLibraryAndSONAME(drm)
-          FindLibraryAndSONAME(gbm)
-          set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
-          set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
-          set(HAVE_KMSDRM_SHARED TRUE)
-        endif()
+      if(KMSDRM_SHARED AND NOT HAVE_SDL_LOADSO)
+        message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
+      endif()
+      if(KMSDRM_SHARED AND HAVE_SDL_LOADSO)
+        FindLibraryAndSONAME(drm)
+        FindLibraryAndSONAME(gbm)
+        set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
+        set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
+        set(HAVE_KMSDRM_SHARED TRUE)
       else()
         set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
       endif()