cmake: use pkg-config's library dirs as hint for finding a shared library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index c1100fd..090852d 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -1,8 +1,11 @@
+include(CMakeParseArguments)
macro(FindLibraryAndSONAME _LIB)
+ cmake_parse_arguments(FLAS "" "" "LIBDIRS" ${ARGN})
+
string(TOUPPER ${_LIB} _UPPERLNAME)
string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}")
- find_library(${_LNAME}_LIB ${_LIB})
+ find_library(${_LNAME}_LIB ${_LIB} PATHS ${FLAS_LIBDIRS})
if(${_LNAME}_LIB)
# reduce the library name for shared linking
@@ -121,7 +124,7 @@ macro(CheckPipewire)
if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
endif()
- FindLibraryAndSONAME("pipewire-0.3")
+ FindLibraryAndSONAME("pipewire-0.3" LIBDIRS ${PKG_PIPEWIRE_LIBRARY_DIRS})
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)
@@ -150,7 +153,7 @@ macro(CheckPulseAudio)
if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
endif()
- FindLibraryAndSONAME("pulse-simple")
+ FindLibraryAndSONAME("pulse-simple" LIBDIRS ${PKG_PULSEAUDIO_LIBRARY_DIRS})
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)
@@ -179,7 +182,7 @@ 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()
- FindLibraryAndSONAME("jack")
+ FindLibraryAndSONAME("jack" LIBDIRS ${PKG_JACK_LIBRARY_DIRS})
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)
@@ -208,7 +211,7 @@ macro(CheckESD)
if(SDL_ESD_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
endif()
- FindLibraryAndSONAME(esd)
+ FindLibraryAndSONAME(esd LIBDIRS ${PKG_ESD_LIBRARY_DIRS})
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)
@@ -301,7 +304,7 @@ macro(CheckSNDIO)
if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
endif()
- FindLibraryAndSONAME("sndio")
+ FindLibraryAndSONAME("sndio" LIBDIRS ${PKG_SNDIO_LIBRARY_DIRS})
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)
@@ -330,7 +333,7 @@ macro(CheckFusionSound)
if(FUSIONSOUND_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
endif()
- FindLibraryAndSONAME("fusionsound")
+ FindLibraryAndSONAME("fusionsound" LIBDIRS ${PKG_FUSIONSOUND_LIBRARY_DIRS})
if(FUSIONSOUND_SHARED AND FUSIONSOUND_LIB AND HAVE_SDL_LOADSO)
set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
set(HAVE_FUSIONSOUND_SHARED TRUE)
@@ -626,9 +629,11 @@ endmacro()
# - HAVE_SDL_LOADSO opt
macro(CheckWayland)
if(SDL_WAYLAND)
- pkg_check_modules(WAYLAND "wayland-client>=1.18" wayland-egl wayland-cursor egl "xkbcommon>=0.5.0")
+ set(WAYLAND_FOUND FALSE)
+ pkg_check_modules(PKG_WAYLAND "wayland-client>=1.18" wayland-egl wayland-cursor egl "xkbcommon>=0.5.0")
- if(WAYLAND_FOUND)
+ if(PKG_WAYLAND_FOUND)
+ set(WAYLAND_FOUND TRUE)
find_program(WAYLAND_SCANNER NAMES wayland-scanner REQUIRED)
execute_process(
COMMAND ${WAYLAND_SCANNER} --version
@@ -651,8 +656,8 @@ macro(CheckWayland)
endif()
if(WAYLAND_FOUND)
- target_link_directories(sdl-build-options INTERFACE "${WAYLAND_LIBRARY_DIRS}")
- target_include_directories(sdl-build-options INTERFACE "${WAYLAND_INCLUDE_DIRS}")
+ target_link_directories(sdl-build-options INTERFACE "${PKG_WAYLAND_LIBRARY_DIRS}")
+ target_include_directories(sdl-build-options INTERFACE "${PKG_WAYLAND_INCLUDE_DIRS}")
set(HAVE_WAYLAND TRUE)
set(HAVE_SDL_VIDEO TRUE)
@@ -678,10 +683,10 @@ macro(CheckWayland)
if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
endif()
- FindLibraryAndSONAME(wayland-client)
- FindLibraryAndSONAME(wayland-egl)
- FindLibraryAndSONAME(wayland-cursor)
- FindLibraryAndSONAME(xkbcommon)
+ FindLibraryAndSONAME(wayland-client LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
+ FindLibraryAndSONAME(wayland-egl LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
+ FindLibraryAndSONAME(wayland-cursor LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
+ FindLibraryAndSONAME(xkbcommon LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
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}\"")
@@ -689,25 +694,25 @@ macro(CheckWayland)
set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
set(HAVE_WAYLAND_SHARED TRUE)
else()
- list(APPEND EXTRA_LIBS ${WAYLAND_LIBRARIES})
+ list(APPEND EXTRA_LIBS ${PKG_WAYLAND_LIBRARIES})
endif()
if(SDL_WAYLAND_LIBDECOR)
- pkg_check_modules(LIBDECOR libdecor-0)
- if(LIBDECOR_FOUND)
+ pkg_check_modules(PKG_LIBDECOR libdecor-0)
+ if(PKG_LIBDECOR)
set(HAVE_WAYLAND_LIBDECOR TRUE)
set(HAVE_LIBDECOR_H 1)
- target_link_directories(sdl-build-options INTERFACE "${LIBDECOR_LIBRARY_DIRS}")
- target_include_directories(sdl-build-options INTERFACE "${LIBDECOR_INCLUDE_DIRS}")
+ target_link_directories(sdl-build-options INTERFACE "${PKG_LIBDECOR_LIBRARY_DIRS}")
+ target_include_directories(sdl-build-options INTERFACE "${PKG_LIBDECOR_INCLUDE_DIRS}")
if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
endif()
- FindLibraryAndSONAME(decor-0)
+ FindLibraryAndSONAME(decor-0 LIBDIRS ${PKG_LIBDECOR_LIBRARY_DIRS})
if(SDL_WAYLAND_LIBDECOR_SHARED AND DECOR_0_LIB AND HAVE_SDL_LOADSO)
set(HAVE_LIBDECOR_SHARED TRUE)
set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
else()
- list(APPEND EXTRA_LIBS ${LIBDECOR_LIBRARIES})
+ list(APPEND EXTRA_LIBS ${PKG_LIBDECOR_LIBRARIES})
endif()
endif()
endif()
@@ -753,7 +758,7 @@ macro(CheckDirectFB)
if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
endif()
- FindLibraryAndSONAME("directfb")
+ FindLibraryAndSONAME("directfb" LIBDIRS ${PKG_DIRECTFB_LIBRARY_DIRS})
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)
@@ -1159,19 +1164,19 @@ macro(CheckHIDAPI)
if(SDL_HIDAPI)
if(SDL_HIDAPI_LIBUSB)
set(HAVE_LIBUSB FALSE)
- pkg_check_modules(LIBUSB libusb-1.0)
- if(LIBUSB_FOUND)
- check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
+ pkg_check_modules(PKG_LIBUSB libusb-1.0)
+ if(PKG_LIBUSB_FOUND)
+ check_include_file(libusb.h HAVE_LIBUSB_H ${PKG_LIBUSB_CFLAGS})
if(HAVE_LIBUSB_H)
set(HAVE_LIBUSB TRUE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PKG_LIBUSB_CFLAGS}")
if(HIDAPI_ONLY_LIBUSB)
- list(APPEND EXTRA_LIBS ${LIBUSB_LIBRARIES})
+ list(APPEND EXTRA_LIBS ${PKG_LIBUSB_LIBRARIES})
elseif(OS2)
set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
else()
# libusb is loaded dynamically, so don't add it to EXTRA_LIBS
- FindLibraryAndSONAME("usb-1.0")
+ FindLibraryAndSONAME("usb-1.0" LIBDIRS ${PKG_LIBUSB_LIBRARY_DIRS})
if(USB_1.0_LIB)
set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
endif()
@@ -1257,19 +1262,17 @@ endmacro()
# - HAVE_SDL_LOADSO opt
macro(CheckKMSDRM)
if(SDL_KMSDRM)
- pkg_check_modules(KMSDRM libdrm gbm egl)
- if(KMSDRM_FOUND AND HAVE_OPENGL_EGL)
- link_directories(
- ${KMSDRM_LIBRARY_DIRS}
- )
- target_include_directories(sdl-build-options INTERFACE "${KMSDRM_INCLUDE_DIRS}")
+ pkg_check_modules(PKG_KMSDRM libdrm gbm egl)
+ if(PKG_KMSDRM_FOUND AND HAVE_OPENGL_EGL)
+ target_link_directories(sdl-build-options INTERFACE ${PKG_KMSDRM_LIBRARY_DIRS})
+ target_include_directories(sdl-build-options INTERFACE "${PKG_KMSDRM_INCLUDE_DIRS}")
set(HAVE_KMSDRM TRUE)
set(HAVE_SDL_VIDEO TRUE)
file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
list(APPEND SOURCE_FILES ${KMSDRM_SOURCES})
- list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
+ list(APPEND EXTRA_CFLAGS ${PKG_KMSDRM_CFLAGS})
set(SDL_VIDEO_DRIVER_KMSDRM 1)
@@ -1277,13 +1280,13 @@ macro(CheckKMSDRM)
message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
endif()
if(SDL_KMSDRM_SHARED AND HAVE_SDL_LOADSO)
- FindLibraryAndSONAME(drm)
- FindLibraryAndSONAME(gbm)
+ FindLibraryAndSONAME(drm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS})
+ FindLibraryAndSONAME(gbm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS})
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()
- list(APPEND EXTRA_LIBS ${KMSDRM_LIBRARIES})
+ list(APPEND EXTRA_LIBS ${PKG_KMSDRM_LIBRARIES})
endif()
endif()
endif()