sdl2-config.cmake.in
author David Ludwig <dludwig@pobox.com>
Tue, 17 Mar 2020 17:34:24 -0400
changeset 13646 784ce9766fb9
parent 13543 ef2d5382a887
child 13683 60f1e9fb5957
permissions -rw-r--r--
Fix for Bug 5034 - Replugging in a controller crashes on macOS in SDL 2.0.12

This is a multi-part fix, and is the 2nd attempt at a fix for Bug 5034. Here
are the problems being addressed:

1. On macOS 10.14.x and earlier, trying to call IOHIDDeviceUnscheduleFromRunLoop
without a prior, paired call to IOHIDDeviceScheduleWithRunLoop, appears to
lead to a crash. A per-device flag has been added to make sure that these
calls are paired.
2. DARWIN_JoystickDetect was free'ing its SDL_joystick's hwdata field
(via FreeDevice) without setting it to NULL, and DARWIN_JoystickRumble wasn't
checking for a NULL hwdata. FreeDevice will now set hwdata to NULL and
DARWIN_JoystickRumble will check for a NULL hwdata.
     1 # sdl2 cmake project-config input for ./configure scripts
     2 
     3 set(prefix "@prefix@") 
     4 set(exec_prefix "@exec_prefix@")
     5 set(libdir "@libdir@")
     6 set(SDL2_PREFIX "@prefix@")
     7 set(SDL2_EXEC_PREFIX "@prefix@")
     8 set(SDL2_LIBDIR "@libdir@")
     9 set(SDL2_INCLUDE_DIRS "@includedir@/SDL2")
    10 set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} @SDL_RLD_FLAGS@ @SDL_LIBS@")
    11 string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
    12 
    13 if(NOT TARGET SDL2::SDL2)
    14   # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
    15   # This may require "libdir" beeing set (from above)
    16   string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "@SDL_RLD_FLAGS@ @SDL_LIBS@ ")
    17   string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
    18   string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@ ")
    19   string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
    20 
    21   add_library(SDL2::SDL2 SHARED IMPORTED)
    22   set_target_properties(SDL2::SDL2 PROPERTIES
    23     INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
    24     IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    25     IMPORTED_LOCATION "@libdir@/libSDL2.so"
    26     INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
    27 
    28   add_library(SDL2::SDL2-static STATIC IMPORTED)
    29   set_target_properties(SDL2::SDL2-static PROPERTIES
    30     INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
    31     IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    32     IMPORTED_LOCATION "@libdir@/libSDL2.a"
    33     INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")
    34 
    35   add_library(SDL2::SDL2main STATIC IMPORTED)
    36   set_target_properties(SDL2::SDL2main PROPERTIES
    37     IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    38     IMPORTED_LOCATION "@libdir@/libSDL2main.a")
    39 endif()