SDL_image: cmake: fix SDL2IMAGE_TIF_SHARED option when using CMake >= 3.28

From 15f9976c4094253b91b29a412c2c68bba7b608dc Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 26 Mar 2024 02:08:54 +0100
Subject: [PATCH] cmake: fix SDL2IMAGE_TIF_SHARED option when using CMake >=
 3.28

Forward port of 2bca7c31b303d471500ed915d02406e691ac4e76
---
 CMakeLists.txt | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 46f925fc..14e703ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -842,6 +842,7 @@ if(SDL3IMAGE_TIF)
         set(BUILD_SHARED_LIBS ${SDL3IMAGE_TIF_SHARED})
         add_subdirectory(external/libtiff EXCLUDE_FROM_ALL)
         add_library(TIFF::TIFF ALIAS tiff)
+        set(SDL2IMAGE_TIF_TARGET "TIFF::tiff")
         if(SDL3IMAGE_TIF_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS)
           list(APPEND INSTALL_EXTRA_TARGETS tiff)
         endif()
@@ -858,6 +859,13 @@ if(SDL3IMAGE_TIF)
             if(NOT SDL3IMAGE_TIF_SHARED)
                 list(APPEND PC_REQUIRES libtiff-4)
             endif()
+            if(TARGET TIFF::tiff)
+                # introduced in CMake 3.28
+                # TIFF::TIFF still exists, but it is an INTERFACE library linking to TIFF::tiff (no ALIAS library)
+                set(SDL2IMAGE_TIF_TARGET "TIFF::tiff")
+            else()
+                set(SDL2IMAGE_TIF_TARGET "TIFF::TIFF")
+            endif()
         else()
             message(${fatal_error} "libtiff NOT found")
         endif()
@@ -866,18 +874,18 @@ if(SDL3IMAGE_TIF)
         target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_TIF)
         if(SDL3IMAGE_TIF_SHARED)
             target_include_directories(${sdl3_image_target_name} 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_TARGET},INCLUDE_DIRECTORIES>
+                $<TARGET_PROPERTY:${SDL2IMAGE_TIF_TARGET},INTERFACE_INCLUDE_DIRECTORIES>
+                $<TARGET_PROPERTY:${SDL2IMAGE_TIF_TARGET},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
             )
-            target_get_dynamic_library(dynamic_tif TIFF::TIFF)
+            target_get_dynamic_library(dynamic_tif ${SDL2IMAGE_TIF_TARGET})
             message(STATUS "Dynamic libtiff: ${dynamic_tif}")
             target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_TIF_DYNAMIC=\"${dynamic_tif}\"")
             if(SDL3IMAGE_TIF_VENDORED)
-                add_dependencies(${sdl3_image_target_name} TIFF::TIFF)
+                add_dependencies(${sdl3_image_target_name} ${SDL2IMAGE_TIF_TARGET})
             endif()
         else()
-            target_link_libraries(${sdl3_image_target_name} PRIVATE TIFF::TIFF)
+            target_link_libraries(${sdl3_image_target_name} PRIVATE ${SDL2IMAGE_TIF_TARGET})
         endif()
     endif()
 endif()