sdl2-config.cmake.in
changeset 13543 ef2d5382a887
parent 13542 27cf93d543ca
child 13683 60f1e9fb5957
     1.1 --- a/sdl2-config.cmake.in	Fri Feb 21 15:51:04 2020 -0500
     1.2 +++ b/sdl2-config.cmake.in	Fri Feb 21 15:52:35 2020 -0500
     1.3 @@ -9,3 +9,31 @@
     1.4  set(SDL2_INCLUDE_DIRS "@includedir@/SDL2")
     1.5  set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} @SDL_RLD_FLAGS@ @SDL_LIBS@")
     1.6  string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
     1.7 +
     1.8 +if(NOT TARGET SDL2::SDL2)
     1.9 +  # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
    1.10 +  # This may require "libdir" beeing set (from above)
    1.11 +  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "@SDL_RLD_FLAGS@ @SDL_LIBS@ ")
    1.12 +  string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
    1.13 +  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@ ")
    1.14 +  string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
    1.15 +
    1.16 +  add_library(SDL2::SDL2 SHARED IMPORTED)
    1.17 +  set_target_properties(SDL2::SDL2 PROPERTIES
    1.18 +    INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
    1.19 +    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    1.20 +    IMPORTED_LOCATION "@libdir@/libSDL2.so"
    1.21 +    INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
    1.22 +
    1.23 +  add_library(SDL2::SDL2-static STATIC IMPORTED)
    1.24 +  set_target_properties(SDL2::SDL2-static PROPERTIES
    1.25 +    INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
    1.26 +    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    1.27 +    IMPORTED_LOCATION "@libdir@/libSDL2.a"
    1.28 +    INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")
    1.29 +
    1.30 +  add_library(SDL2::SDL2main STATIC IMPORTED)
    1.31 +  set_target_properties(SDL2::SDL2main PROPERTIES
    1.32 +    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    1.33 +    IMPORTED_LOCATION "@libdir@/libSDL2main.a")
    1.34 +endif()