switch-sdl2: Fix importing SDL2 on platforms that only support static libs

This commit is contained in:
Vicki Pfau 2020-07-23 19:17:08 +01:00 committed by Dave Murphy
parent 995ae3fbef
commit cd14a6c0b6
1 changed files with 15 additions and 6 deletions

View File

@ -18,12 +18,21 @@ if(NOT TARGET SDL2::SDL2)
string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_STATIC_LIBS@ ") string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_STATIC_LIBS@ ")
string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC) string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
add_library(SDL2::SDL2 SHARED IMPORTED) if(TARGET_SUPPORTS_SHARED_LIBS)
set_target_properties(SDL2::SDL2 PROPERTIES add_library(SDL2::SDL2 SHARED IMPORTED)
INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2" set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C" INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
IMPORTED_LOCATION "@libdir@/${CMAKE_SHARED_LIBRARY_PREFIX}SDL2${CMAKE_SHARED_LIBRARY_SUFFIX}" IMPORTED_LINK_INTERFACE_LANGUAGES "C"
INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}") IMPORTED_LOCATION "@libdir@/${CMAKE_SHARED_LIBRARY_PREFIX}SDL2${CMAKE_SHARED_LIBRARY_SUFFIX}"
INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
else()
add_library(SDL2::SDL2 STATIC IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "@libdir@/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2${CMAKE_STATIC_LIBRARY_SUFFIX}"
INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")
endif()
add_library(SDL2::SDL2-static STATIC IMPORTED) add_library(SDL2::SDL2-static STATIC IMPORTED)
set_target_properties(SDL2::SDL2-static PROPERTIES set_target_properties(SDL2::SDL2-static PROPERTIES