cmake: use pkg-config's library dirs as hint for finding a shared library

This commit is contained in:
Anonymous Maarten 2022-10-20 01:11:39 +02:00 committed by Anonymous Maarten
parent 94ac8ae08b
commit 11d53c84a7

View File

@ -1,8 +1,11 @@
include(CMakeParseArguments)
macro(FindLibraryAndSONAME _LIB) macro(FindLibraryAndSONAME _LIB)
cmake_parse_arguments(FLAS "" "" "LIBDIRS" ${ARGN})
string(TOUPPER ${_LIB} _UPPERLNAME) string(TOUPPER ${_LIB} _UPPERLNAME)
string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}") string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}")
find_library(${_LNAME}_LIB ${_LIB}) find_library(${_LNAME}_LIB ${_LIB} PATHS ${FLAS_LIBDIRS})
if(${_LNAME}_LIB) if(${_LNAME}_LIB)
# reduce the library name for shared linking # reduce the library name for shared linking
@ -121,7 +124,7 @@ macro(CheckPipewire)
if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading") message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading")
endif() 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) 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(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"")
set(HAVE_PIPEWIRE_SHARED TRUE) set(HAVE_PIPEWIRE_SHARED TRUE)
@ -150,7 +153,7 @@ macro(CheckPulseAudio)
if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading") message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
endif() endif()
FindLibraryAndSONAME("pulse-simple") FindLibraryAndSONAME("pulse-simple" LIBDIRS ${PKG_PULSEAUDIO_LIBRARY_DIRS})
if(SDL_PULSEAUDIO_SHARED AND PULSE_SIMPLE_LIB AND HAVE_SDL_LOADSO) if(SDL_PULSEAUDIO_SHARED AND PULSE_SIMPLE_LIB AND HAVE_SDL_LOADSO)
set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"") set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
set(HAVE_PULSEAUDIO_SHARED TRUE) set(HAVE_PULSEAUDIO_SHARED TRUE)
@ -179,7 +182,7 @@ macro(CheckJACK)
if(SDL_JACK_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_JACK_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading") message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
endif() endif()
FindLibraryAndSONAME("jack") FindLibraryAndSONAME("jack" LIBDIRS ${PKG_JACK_LIBRARY_DIRS})
if(SDL_JACK_SHARED AND JACK_LIB AND HAVE_SDL_LOADSO) if(SDL_JACK_SHARED AND JACK_LIB AND HAVE_SDL_LOADSO)
set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"") set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
set(HAVE_JACK_SHARED TRUE) set(HAVE_JACK_SHARED TRUE)
@ -208,7 +211,7 @@ macro(CheckESD)
if(SDL_ESD_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_ESD_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic ESD loading") message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
endif() endif()
FindLibraryAndSONAME(esd) FindLibraryAndSONAME(esd LIBDIRS ${PKG_ESD_LIBRARY_DIRS})
if(SDL_ESD_SHARED AND ESD_LIB AND HAVE_SDL_LOADSO) if(SDL_ESD_SHARED AND ESD_LIB AND HAVE_SDL_LOADSO)
set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"") set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
set(HAVE_ESD_SHARED TRUE) set(HAVE_ESD_SHARED TRUE)
@ -301,7 +304,7 @@ macro(CheckSNDIO)
if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic sndio loading") message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
endif() endif()
FindLibraryAndSONAME("sndio") FindLibraryAndSONAME("sndio" LIBDIRS ${PKG_SNDIO_LIBRARY_DIRS})
if(SDL_SNDIO_SHARED AND SNDIO_LIB AND HAVE_SDL_LOADSO) if(SDL_SNDIO_SHARED AND SNDIO_LIB AND HAVE_SDL_LOADSO)
set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"") set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
set(HAVE_SNDIO_SHARED TRUE) set(HAVE_SNDIO_SHARED TRUE)
@ -330,7 +333,7 @@ macro(CheckFusionSound)
if(FUSIONSOUND_SHARED AND NOT HAVE_SDL_LOADSO) if(FUSIONSOUND_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading") message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
endif() endif()
FindLibraryAndSONAME("fusionsound") FindLibraryAndSONAME("fusionsound" LIBDIRS ${PKG_FUSIONSOUND_LIBRARY_DIRS})
if(FUSIONSOUND_SHARED AND FUSIONSOUND_LIB AND HAVE_SDL_LOADSO) if(FUSIONSOUND_SHARED AND FUSIONSOUND_LIB AND HAVE_SDL_LOADSO)
set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"") set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
set(HAVE_FUSIONSOUND_SHARED TRUE) set(HAVE_FUSIONSOUND_SHARED TRUE)
@ -626,9 +629,11 @@ endmacro()
# - HAVE_SDL_LOADSO opt # - HAVE_SDL_LOADSO opt
macro(CheckWayland) macro(CheckWayland)
if(SDL_WAYLAND) 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) find_program(WAYLAND_SCANNER NAMES wayland-scanner REQUIRED)
execute_process( execute_process(
COMMAND ${WAYLAND_SCANNER} --version COMMAND ${WAYLAND_SCANNER} --version
@ -651,8 +656,8 @@ macro(CheckWayland)
endif() endif()
if(WAYLAND_FOUND) if(WAYLAND_FOUND)
target_link_directories(sdl-build-options INTERFACE "${WAYLAND_LIBRARY_DIRS}") target_link_directories(sdl-build-options INTERFACE "${PKG_WAYLAND_LIBRARY_DIRS}")
target_include_directories(sdl-build-options INTERFACE "${WAYLAND_INCLUDE_DIRS}") target_include_directories(sdl-build-options INTERFACE "${PKG_WAYLAND_INCLUDE_DIRS}")
set(HAVE_WAYLAND TRUE) set(HAVE_WAYLAND TRUE)
set(HAVE_SDL_VIDEO TRUE) set(HAVE_SDL_VIDEO TRUE)
@ -678,10 +683,10 @@ macro(CheckWayland)
if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading") message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
endif() endif()
FindLibraryAndSONAME(wayland-client) FindLibraryAndSONAME(wayland-client LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
FindLibraryAndSONAME(wayland-egl) FindLibraryAndSONAME(wayland-egl LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
FindLibraryAndSONAME(wayland-cursor) FindLibraryAndSONAME(wayland-cursor LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS})
FindLibraryAndSONAME(xkbcommon) 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) 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 "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_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(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
set(HAVE_WAYLAND_SHARED TRUE) set(HAVE_WAYLAND_SHARED TRUE)
else() else()
list(APPEND EXTRA_LIBS ${WAYLAND_LIBRARIES}) list(APPEND EXTRA_LIBS ${PKG_WAYLAND_LIBRARIES})
endif() endif()
if(SDL_WAYLAND_LIBDECOR) if(SDL_WAYLAND_LIBDECOR)
pkg_check_modules(LIBDECOR libdecor-0) pkg_check_modules(PKG_LIBDECOR libdecor-0)
if(LIBDECOR_FOUND) if(PKG_LIBDECOR)
set(HAVE_WAYLAND_LIBDECOR TRUE) set(HAVE_WAYLAND_LIBDECOR TRUE)
set(HAVE_LIBDECOR_H 1) set(HAVE_LIBDECOR_H 1)
target_link_directories(sdl-build-options INTERFACE "${LIBDECOR_LIBRARY_DIRS}") target_link_directories(sdl-build-options INTERFACE "${PKG_LIBDECOR_LIBRARY_DIRS}")
target_include_directories(sdl-build-options INTERFACE "${LIBDECOR_INCLUDE_DIRS}") target_include_directories(sdl-build-options INTERFACE "${PKG_LIBDECOR_INCLUDE_DIRS}")
if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading") message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
endif() 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) if(SDL_WAYLAND_LIBDECOR_SHARED AND DECOR_0_LIB AND HAVE_SDL_LOADSO)
set(HAVE_LIBDECOR_SHARED TRUE) set(HAVE_LIBDECOR_SHARED TRUE)
set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
else() else()
list(APPEND EXTRA_LIBS ${LIBDECOR_LIBRARIES}) list(APPEND EXTRA_LIBS ${PKG_LIBDECOR_LIBRARIES})
endif() endif()
endif() endif()
endif() endif()
@ -753,7 +758,7 @@ macro(CheckDirectFB)
if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO) if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading") message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
endif() endif()
FindLibraryAndSONAME("directfb") FindLibraryAndSONAME("directfb" LIBDIRS ${PKG_DIRECTFB_LIBRARY_DIRS})
if(SDL_DIRECTFB_SHARED AND DIRECTFB_LIB AND HAVE_SDL_LOADSO) if(SDL_DIRECTFB_SHARED AND DIRECTFB_LIB AND HAVE_SDL_LOADSO)
set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
set(HAVE_DIRECTFB_SHARED TRUE) set(HAVE_DIRECTFB_SHARED TRUE)
@ -1159,19 +1164,19 @@ macro(CheckHIDAPI)
if(SDL_HIDAPI) if(SDL_HIDAPI)
if(SDL_HIDAPI_LIBUSB) if(SDL_HIDAPI_LIBUSB)
set(HAVE_LIBUSB FALSE) set(HAVE_LIBUSB FALSE)
pkg_check_modules(LIBUSB libusb-1.0) pkg_check_modules(PKG_LIBUSB libusb-1.0)
if(LIBUSB_FOUND) if(PKG_LIBUSB_FOUND)
check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS}) check_include_file(libusb.h HAVE_LIBUSB_H ${PKG_LIBUSB_CFLAGS})
if(HAVE_LIBUSB_H) if(HAVE_LIBUSB_H)
set(HAVE_LIBUSB TRUE) 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) if(HIDAPI_ONLY_LIBUSB)
list(APPEND EXTRA_LIBS ${LIBUSB_LIBRARIES}) list(APPEND EXTRA_LIBS ${PKG_LIBUSB_LIBRARIES})
elseif(OS2) elseif(OS2)
set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"") set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
else() else()
# libusb is loaded dynamically, so don't add it to EXTRA_LIBS # 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) if(USB_1.0_LIB)
set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"") set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
endif() endif()
@ -1257,19 +1262,17 @@ endmacro()
# - HAVE_SDL_LOADSO opt # - HAVE_SDL_LOADSO opt
macro(CheckKMSDRM) macro(CheckKMSDRM)
if(SDL_KMSDRM) if(SDL_KMSDRM)
pkg_check_modules(KMSDRM libdrm gbm egl) pkg_check_modules(PKG_KMSDRM libdrm gbm egl)
if(KMSDRM_FOUND AND HAVE_OPENGL_EGL) if(PKG_KMSDRM_FOUND AND HAVE_OPENGL_EGL)
link_directories( target_link_directories(sdl-build-options INTERFACE ${PKG_KMSDRM_LIBRARY_DIRS})
${KMSDRM_LIBRARY_DIRS} target_include_directories(sdl-build-options INTERFACE "${PKG_KMSDRM_INCLUDE_DIRS}")
)
target_include_directories(sdl-build-options INTERFACE "${KMSDRM_INCLUDE_DIRS}")
set(HAVE_KMSDRM TRUE) set(HAVE_KMSDRM TRUE)
set(HAVE_SDL_VIDEO TRUE) set(HAVE_SDL_VIDEO TRUE)
file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c) file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
list(APPEND SOURCE_FILES ${KMSDRM_SOURCES}) 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) 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") message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
endif() endif()
if(SDL_KMSDRM_SHARED AND HAVE_SDL_LOADSO) if(SDL_KMSDRM_SHARED AND HAVE_SDL_LOADSO)
FindLibraryAndSONAME(drm) FindLibraryAndSONAME(drm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS})
FindLibraryAndSONAME(gbm) FindLibraryAndSONAME(gbm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS})
set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
set(HAVE_KMSDRM_SHARED TRUE) set(HAVE_KMSDRM_SHARED TRUE)
else() else()
list(APPEND EXTRA_LIBS ${KMSDRM_LIBRARIES}) list(APPEND EXTRA_LIBS ${PKG_KMSDRM_LIBRARIES})
endif() endif()
endif() endif()
endif() endif()