SDL_image: Fix SDL2IMAGE_TIF_SHARED option when using CMake >= 3.28

From 2bca7c31b303d471500ed915d02406e691ac4e76 Mon Sep 17 00:00:00 2001
From: Silvio Traversaro <[EMAIL REDACTED]>
Date: Mon, 25 Mar 2024 15:13:50 +0100
Subject: [PATCH] Fix SDL2IMAGE_TIF_SHARED option when using CMake >= 3.28

---
 CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4ebbddaa..9700b983 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -767,12 +767,19 @@ if(SDL2IMAGE_TIF)
     if(SDL2IMAGE_TIF_ENABLED)
         target_compile_definitions(SDL2_image PRIVATE LOAD_TIF)
         if(SDL2IMAGE_TIF_SHARED)
+            # If TIFF::tiff exists, use that one, otherwise
+            # fallback to TIFF:TIFF
+            if(TARGET TIFF::tiff)
+                set(SDL2IMAGE_TIF_IMPORTED_TARGET "TIFF::tiff")
+            else()
+                set(SDL2IMAGE_TIF_IMPORTED_TARGET "TIFF::TIFF")
+            endif()
             target_include_directories(SDL2_image PRIVATE
-                $<TARGET_PROPERTY:TIFF::TIFF,INCLUDE_DIRECTORIES>
-                $<TARGET_PROPERTY:TIFF::TIFF,INTERFACE_INCLUDE_DIRECTORIES>
-                $<TARGET_PROPERTY:TIFF::TIFF,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
+                $<TARGET_PROPERTY:${SDL2IMAGE_TIF_IMPORTED_TARGET},INCLUDE_DIRECTORIES>
+                $<TARGET_PROPERTY:${SDL2IMAGE_TIF_IMPORTED_TARGET},INTERFACE_INCLUDE_DIRECTORIES>
+                $<TARGET_PROPERTY:${SDL2IMAGE_TIF_IMPORTED_TARGET},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
             )
-            target_get_dynamic_library(dynamic_tif TIFF::TIFF)
+            target_get_dynamic_library(dynamic_tif ${SDL2IMAGE_TIF_IMPORTED_TARGET})
             message(STATUS "Dynamic libtiff: ${dynamic_tif}")
             target_compile_definitions(SDL2_image PRIVATE "LOAD_TIF_DYNAMIC=\"${dynamic_tif}\"")
             if(SDL2IMAGE_TIF_VENDORED)