cmake: SDL3-shared target will always be a shared target

This commit is contained in:
Anonymous Maarten
2023-02-16 23:30:20 +01:00
committed by Anonymous Maarten
parent 6ae1578691
commit dc138ee3d4
6 changed files with 83 additions and 70 deletions

View File

@@ -17,10 +17,10 @@ if(NOT TARGET SDL3::Headers)
endif()
set(SDL3_Headers_FOUND TRUE)
# Find SDL3::SDL3
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SDL3Targets.cmake")
set(SDL3_SDL3_FOUND TRUE)
# Find SDL3::SDL3-shared
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3sharedTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SDL3sharedTargets.cmake")
set(SDL3_SDL3-shared_FOUND TRUE)
endif()
# Find SDL3::SDL3-static
@@ -39,6 +39,10 @@ else()
endif()
endif()
if(SDL3_SDL3-shared_FOUND OR SDL3_SDL3-static_FOUND)
set(SDL3_SDL3_FOUND TRUE)
endif()
# Find SDL3::SDL3_test
if(_sdl3_framework)
find_package(SDL3_test CONFIG)
@@ -65,14 +69,22 @@ unset(SDL_ALSA_SHARED)
check_required_components(SDL3)
# Create SDL3::SDL3 alias for static-only builds
if(TARGET SDL3::SDL3-static AND NOT TARGET SDL3::SDL3)
function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
if(CMAKE_VERSION VERSION_LESS "3.18")
# FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
add_library(SDL3::SDL3 INTERFACE IMPORTED)
set_target_properties(SDL3::SDL3 PROPERTIES INTERFACE_LINK_LIBRARIES "SDL3::SDL3-static")
add_library(${NEW_TARGET} INTERFACE IMPORTED)
set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
else()
add_library(SDL3::SDL3 ALIAS SDL3::SDL3-static)
add_library(${NEW_TARGET} ALIAS ${TARGET})
endif()
endfunction()
# Make sure SDL3::SDL3 always exists
if(NOT TARGET SDL3::SDL3)
if(TARGET SDL3::SDL3-shared)
_sdl_create_target_alias_compat(SDL3::SDL3 SDL3::SDL3-shared)
else()
_sdl_create_target_alias_compat(SDL3::SDL3 SDL3::SDL3-static)
endif()
endif()