cmake: avoid adding full path to SDL_EXTRA_LIBS

This avoids placing e.g. -l/path/to/libX11.so in sdl3.pc when configuring with -DSDL_X11_SHARED=OFF
main
Anonymous Maarten 2023-01-07 20:38:33 +01:00 committed by Anonymous Maarten
parent dfcd8d5835
commit e85e11b211
1 changed files with 20 additions and 11 deletions

View File

@ -27,6 +27,8 @@ macro(FindLibraryAndSONAME _LIB)
string(REGEX REPLACE "(\\.[0-9]*)\\.[0-9\\.]*$" "\\1" _LIB_REGEXD "${_LIB_JUSTNAME}")
endif()
get_filename_component(${_LNAME}_LIBDIR ${${_LNAME}_LIB} DIRECTORY)
SET(_DEBUG_FindSONAME FALSE)
if(_DEBUG_FindSONAME)
message_warn("DYNLIB OUTPUTVAR: ${_LIB} ... ${_LNAME}_LIB")
@ -269,7 +271,6 @@ macro(CheckLibSampleRate)
endif()
else()
target_link_libraries(sdl-build-options INTERFACE SampleRate::samplerate)
list(APPEND SDL_REQUIRES_PRIVATE SampleRate::samplerate)
endif()
else()
check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
@ -283,7 +284,7 @@ macro(CheckLibSampleRate)
set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
set(HAVE_LIBSAMPLERATE_SHARED TRUE)
else()
list(APPEND SDL_EXTRA_LDFLAGS -lsamplerate)
list(APPEND SDL_EXTRA_LIBS samplerate)
endif()
endif()
endif()
@ -371,18 +372,21 @@ macro(CheckX11)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${X11_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${X11_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS X11)
endif()
endif()
if(XEXT_LIB)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${XEXT_LIB_SONAME})
list(APPEND SDL_EXTRA_LDFLAGS "-L${XEXT_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS Xext)
endif()
endif()
else()
list(APPEND SDL_EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${X11_LIBDIR}" "-L${XEXT_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS X11 Xext)
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES ${X11_LIB})
@ -408,7 +412,8 @@ macro(CheckX11)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${XCURSOR_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${XCURSOR_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS Xcursor)
endif()
set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
endif()
@ -423,7 +428,8 @@ macro(CheckX11)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${XI_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${XI_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS Xi)
endif()
set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
@ -457,7 +463,8 @@ macro(CheckX11)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES "\"${XFIXES_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${XFIXES_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${XFIXES_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS Xfixes)
endif()
set(SDL_VIDEO_DRIVER_X11_XFIXES 1)
set(HAVE_X11_XFIXES TRUE)
@ -467,7 +474,8 @@ macro(CheckX11)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${XRANDR_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${XRANDR_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS Xrandr)
endif()
set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
set(HAVE_X11_XRANDR TRUE)
@ -477,7 +485,8 @@ macro(CheckX11)
if(HAVE_X11_SHARED)
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
else()
list(APPEND SDL_EXTRA_LIBS ${XSS_LIB})
list(APPEND SDL_EXTRA_LDFLAGS "-L${XSS_LIBDIR}")
list(APPEND SDL_EXTRA_LIBS Xss)
endif()
set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
set(HAVE_X11_XSCRNSAVER TRUE)
@ -914,7 +923,7 @@ macro(CheckUSBHID)
endif()
check_library_exists(usb hid_init "" LIBUSB)
if(LIBUSB)
set(USB_LIBS ${USB_LIBS} usb)
list(APPEND USB_LIBS usb)
endif()
endif()