From 4e90beda31a30ea3a4875988432baf8e4de7bd99 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Fri, 6 May 2022 11:42:57 +0100
Subject: [PATCH] cmake: Allow linking to older SDL2 that was built with
Autotools
Ubuntu 20.04's SDL was built with Autotools and is older than
https://github.com/libsdl-org/SDL/issues/3531, so it doesn't define
the SDL2::SDL2 target.
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
CMakeLists.txt | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 146066a..fae6372 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,6 +70,21 @@ set(SDL_TTF_VERSION "${SDL_TTF_MAJOR_VERSION}.${SDL_TTF_MINOR_VERSION}.${SDL_TTF
##### library generation #####
add_library(SDL2_ttf SDL_ttf.c SDL_ttf.h)
+
+# 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()
+
if (BUILD_SHARED_LIBS)
target_link_libraries(SDL2_ttf SDL2::SDL2)
if (WIN32 OR CYGWIN)