From f1202fccdc2c8a011f21556d0066b445c9a9a1f6 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Mon, 20 Feb 2023 00:43:53 +0100 Subject: [PATCH] cmake: create SDL3::SDL3-shared for VC and Xcode devel package --- VisualC/pkg-support/cmake/sdl3-config.cmake | 37 ++++++++++++++++--- .../resources/CMake/sdl3-config.cmake | 35 ++++++++++++++++-- cmake/SDL3Config.cmake.in | 2 +- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/VisualC/pkg-support/cmake/sdl3-config.cmake b/VisualC/pkg-support/cmake/sdl3-config.cmake index a00e7888d..4aeace21d 100644 --- a/VisualC/pkg-support/cmake/sdl3-config.cmake +++ b/VisualC/pkg-support/cmake/sdl3-config.cmake @@ -63,9 +63,9 @@ unset(_sdl3_include_dirs) set(_sdl3_library "${SDL3_LIBDIR}/SDL3.lib") set(_sdl3_dll_library "${SDL3_BINDIR}/SDL3.dll") if(EXISTS "${_sdl3_library}" AND EXISTS "${_sdl3_dll_library}") - if(NOT TARGET SDL3::SDL3) - add_library(SDL3::SDL3 SHARED IMPORTED) - set_target_properties(SDL3::SDL3 + if(NOT TARGET SDL3::SDL3-shared) + add_library(SDL3::SDL3-shared SHARED IMPORTED) + set_target_properties(SDL3::SDL3-shared PROPERTIES INTERFACE_LINK_LIBRARIES "SDL3::Headers" IMPORTED_IMPLIB "${_sdl3_library}" @@ -74,13 +74,15 @@ if(EXISTS "${_sdl3_library}" AND EXISTS "${_sdl3_dll_library}") INTERFACE_SDL3_SHARED "ON" ) endif() - set(SDL3_SDL3_FOUND TRUE) + set(SDL3_SDL3-shared_FOUND TRUE) else() - set(SDL3_SDL3_FOUND FALSE) + set(SDL3_SDL3-shared_FOUND FALSE) endif() unset(_sdl3_library) unset(_sdl3_dll_library) +set(SDL3_SDL3-static_FOUND FALSE) + set(_sdl3test_library "${SDL3_LIBDIR}/SDL3_test.lib") if(EXISTS "${_sdl3test_library}") if(NOT TARGET SDL3::SDL3_test) @@ -93,8 +95,31 @@ if(EXISTS "${_sdl3test_library}") endif() set(SDL3_SDL3_test_FOUND TRUE) else() - set(SDL3_SDL3_FOUND FALSE) + set(SDL3_SDL3_test_FOUND FALSE) endif() unset(_sdl3test_library) +if(SDL3_SDL3-shared_FOUND OR SDL3_SDL3-static_FOUND) + set(SDL3_SDL3_FOUND TRUE) +endif() + +function(_sdl_create_target_alias_compat NEW_TARGET TARGET) + if(CMAKE_VERSION VERSION_LESS "3.18") + # Aliasing local targets is not supported on CMake < 3.18, so make it global. + add_library(${NEW_TARGET} INTERFACE IMPORTED) + set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}") + else() + 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() + check_required_components(SDL3) diff --git a/Xcode/SDL/pkg-support/resources/CMake/sdl3-config.cmake b/Xcode/SDL/pkg-support/resources/CMake/sdl3-config.cmake index fd09ec046..34c2e1009 100644 --- a/Xcode/SDL/pkg-support/resources/CMake/sdl3-config.cmake +++ b/Xcode/SDL/pkg-support/resources/CMake/sdl3-config.cmake @@ -55,9 +55,9 @@ endif() set(SDL3_Headers_FOUND TRUE) unset(_sdl3_include_dirs) -if(NOT TARGET SDL3::SDL3) - add_library(SDL3::SDL3 SHARED IMPORTED) - set_target_properties(SDL3::SDL3 +if(NOT TARGET SDL3::SDL3-shared) + add_library(SDL3::SDL3-shared SHARED IMPORTED) + set_target_properties(SDL3::SDL3-shared PROPERTIES FRAMEWORK "TRUE" INTERFACE_LINK_LIBRARIES "SDL3::Headers" @@ -67,9 +67,36 @@ if(NOT TARGET SDL3::SDL3) INTERFACE_SDL3_SHARED "ON" ) endif() -set(SDL3_SDL3_FOUND TRUE) +set(SDL3_SDL3-shared_FOUND TRUE) + +set(SDL3_SDL3-static FALSE) + +set(SDL3_SDL3_test FALSE) unset(_sdl3_framework_parent_path) unset(_sdl3_framework_path) +if(SDL3_SDL3-shared_FOUND OR SDL3_SDL3-static_FOUND) + set(SDL3_SDL3_FOUND TRUE) +endif() + +function(_sdl_create_target_alias_compat NEW_TARGET TARGET) + if(CMAKE_VERSION VERSION_LESS "3.18") + # Aliasing local targets is not supported on CMake < 3.18, so make it global. + add_library(${NEW_TARGET} INTERFACE IMPORTED) + set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}") + else() + 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() + check_required_components(SDL3) diff --git a/cmake/SDL3Config.cmake.in b/cmake/SDL3Config.cmake.in index b1dbdadc9..18bce2706 100644 --- a/cmake/SDL3Config.cmake.in +++ b/cmake/SDL3Config.cmake.in @@ -71,7 +71,7 @@ check_required_components(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. + # Aliasing local targets is not supported on CMake < 3.18, so make it global. add_library(${NEW_TARGET} INTERFACE IMPORTED) set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}") else()