SDL_image: cmake: use SDL2IMAGE_TIF_TARGET consistently

From b9694685952ac6cc287c9e30c03305860496baf6 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 26 Mar 2024 02:24:18 +0100
Subject: [PATCH] cmake: use SDL2IMAGE_TIF_TARGET consistently

---
 CMakeLists.txt | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9700b983..e3cb0c07 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -746,6 +746,7 @@ if(SDL2IMAGE_TIF)
         set(BUILD_SHARED_LIBS ${SDL2IMAGE_TIF_SHARED})
         add_subdirectory(external/libtiff EXCLUDE_FROM_ALL)
         add_library(TIFF::TIFF ALIAS tiff)
+        set(SDL2IMAGE_TIF_TARGET "TIFF::tiff")
         list(APPEND INSTALL_EXTRA_TARGETS tiff)
         set_target_properties(tiff PROPERTIES EXPORT_NAME external_libtiff)
         add_library(SDL2_image::external_libtiff ALIAS tiff)
@@ -760,6 +761,13 @@ if(SDL2IMAGE_TIF)
             if(NOT SDL2IMAGE_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()
@@ -767,26 +775,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:${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_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 ${SDL2IMAGE_TIF_IMPORTED_TARGET})
+            target_get_dynamic_library(dynamic_tif ${SDL2IMAGE_TIF_TARGET})
             message(STATUS "Dynamic libtiff: ${dynamic_tif}")
             target_compile_definitions(SDL2_image PRIVATE "LOAD_TIF_DYNAMIC=\"${dynamic_tif}\"")
             if(SDL2IMAGE_TIF_VENDORED)
-                add_dependencies(SDL2_image TIFF::TIFF)
+                add_dependencies(SDL2_image ${SDL2IMAGE_TIF_TARGET})
             endif()
         else()
-            target_link_libraries(SDL2_image PRIVATE TIFF::TIFF)
+            target_link_libraries(SDL2_image PRIVATE ${SDL2IMAGE_TIF_TARGET})
         endif()
     endif()
 endif()