SDL_image: cmake: Be compatible with older versions of SDL built with Autotools

From 315d57a2ea89648d28313f273adf62ddc34d7047 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Thu, 5 May 2022 14:38:20 +0100
Subject: [PATCH] cmake: Be compatible with older versions of SDL built with
 Autotools

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 CMakeLists.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b70d39a..5829b4f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,20 @@ if (NOT ANDROID AND NOT (TARGET SDL2 OR TARGET SDL2-static))
 	find_package(SDL2 REQUIRED)
 endif()
 
+# Workaround for Ubuntu 20.04's SDL being older than
+# https://github.com/libsdl-org/SDL/issues/3531
+if (NOT TARGET SDL2::SDL2)
+	add_library(SDL2::SDL2 SHARED IMPORTED)
+	find_library(SDL2_LIBRARY
+		NAMES SDL2
+		HINTS "${SDL2_EXEC_PREFIX}"
+		REQUIRED)
+	set_target_properties(SDL2::SDL2 PROPERTIES
+		INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
+		IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+		IMPORTED_LOCATION "${SDL2_LIBRARY}")
+endif()
+
 option(SUPPORT_JPG "Support loading JPEG images" ON)
 option(SUPPORT_PNG "Support loading PNG images" ON)
 option(SUPPORT_WEBP "Support loading WEBP images" OFF)