SDL: Alias SDL2::SDL2 to SDL2::SDL2-static on static-only builds

From 407867cf7262a45952d095b9a22af14b22878df9 Mon Sep 17 00:00:00 2001
From: Ivan Epifanov <[EMAIL REDACTED]>
Date: Tue, 13 Jul 2021 13:47:08 +0300
Subject: [PATCH] Alias SDL2::SDL2 to SDL2::SDL2-static on static-only builds

---
 SDL2Config.cmake | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/SDL2Config.cmake b/SDL2Config.cmake
index 4c9dbab413..e24fa7975a 100644
--- a/SDL2Config.cmake
+++ b/SDL2Config.cmake
@@ -1,5 +1,14 @@
 include("${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")
 
+# on static-only builds create an alias
+if(NOT TARGET SDL2::SDL2 AND TARGET SDL2::SDL2-static)
+  if(CMAKE_VERSION VERSION_LESS "3.18")
+      # Aliasing local targets is not supported on CMake < 3.18, so make it global.
+      set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE)
+  endif()
+  add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
+endif()
+
 # provide ${SDL2_LIBRARIES}, ${SDL2_INCLUDE_DIRS} etc, like sdl2-config.cmake does,
 # for compatibility between SDL2 built with autotools and SDL2 built with CMake