SDL_rtf: cmake: fix CMake configuration files

From 53d2a995cafc835184e422ba3c0a7c6766a9bf8f Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 15 Jan 2024 12:13:58 +0100
Subject: [PATCH] cmake: fix CMake configuration files

---
 CMakeLists.txt                |  2 +-
 cmake/SDL3_rtfConfig.cmake.in | 33 ++++++++++++++++++++++++++-------
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5f5b497..efb6efa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,7 +101,7 @@ if(NOT TARGET SDL3_rtf::SDL3_rtf)
 endif()
 target_include_directories(${sdl3_rtf_target_name} PUBLIC
     "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
-    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
 )
 target_compile_definitions(${sdl3_rtf_target_name} PRIVATE
     BUILD_SDL
diff --git a/cmake/SDL3_rtfConfig.cmake.in b/cmake/SDL3_rtfConfig.cmake.in
index 22675d7..b0989c8 100644
--- a/cmake/SDL3_rtfConfig.cmake.in
+++ b/cmake/SDL3_rtfConfig.cmake.in
@@ -1,17 +1,36 @@
-# sdl2_rtf cmake project-config input for CMakeLists.txt script
+# sdl3_rtf cmake project-config input for CMakeLists.txt script
 
 include(FeatureSummary)
-set_package_properties(SDL2_rtf PROPERTIES
+set_package_properties(SDL3_rtf PROPERTIES
     URL "https://www.libsdl.org/projects/SDL_rtf/"
     DESCRIPTION "Support for Rich Text Format (.rtf) files with Simple Directmedia Layer"
 )
 
-set(SDL2_rtf_FOUND ON)
+set(SDL3_rtf_FOUND ON)
 
-if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-shared-targets.cmake")
-    include("${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-shared-targets.cmake")
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_rtf-shared-targets.cmake")
+    include("${CMAKE_CURRENT_LIST_DIR}/SDL3_rtf-shared-targets.cmake")
 endif()
 
-if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-static-targets.cmake")
-    include("${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-static-targets.cmake")
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_rtf-static-targets.cmake")
+    include("${CMAKE_CURRENT_LIST_DIR}/SDL3_rtf-static-targets.cmake")
+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_rtf::SDL3_rtf always exists
+if(NOT TARGET SDL3_rtf::SDL3_rtf)
+    if(TARGET SDL3_rtf::SDL3_rtf-shared)
+        _sdl_create_target_alias_compat(SDL3_rtf::SDL3_rtf SDL3_rtf::SDL3_rtf-shared)
+    else()
+        _sdl_create_target_alias_compat(SDL3_rtf::SDL3_rtf SDL3_rtf::SDL3_rtf-static)
+    endif()
 endif()