SDL_image: cmake: don't build zlib examples + create ZLIB::ZLIB target

From 72581a39da348b2bb6bb12041fbebc2d4d696b7f Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 29 Jan 2024 20:53:53 +0100
Subject: [PATCH] cmake: don't build zlib examples + create ZLIB::ZLIB target

---
 CMakeLists.txt | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5d7fa8c5..a6c3388c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -344,10 +344,10 @@ endif()
 if(SDL2IMAGE_ZLIB)
     if(SDL2IMAGE_ZLIB_VENDORED)
         message(STATUS "${PROJECT_NAME}: Using vendored zlib")
-        sdl_check_project_in_subfolder(external/zlib zlib SDL2IMAGE_VENDORED)
-        add_subdirectory(external/zlib EXCLUDE_FROM_ALL)
         # disable build of zlib example programs:
         set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "zlib examples" FORCE)
+        sdl_check_project_in_subfolder(external/zlib zlib SDL2IMAGE_VENDORED)
+        add_subdirectory(external/zlib EXCLUDE_FROM_ALL)
         # PNG_BUILD_ZLIB variable is used by vendored libpng
         set(PNG_BUILD_ZLIB ON CACHE BOOL "libpng option to tell it should use 'our' vendored ZLIB library" FORCE)
         # ZLIB_INCLUDE_DIR variable is used by vendored libpng
@@ -358,6 +358,9 @@ if(SDL2IMAGE_ZLIB)
         else()
             set(ZLIB_LIBRARY zlibstatic)
         endif()
+        if(NOT TARGET ZLIB::ZLIB)
+            add_library(ZLIB::ZLIB ALIAS ${ZLIB_LIBRARY})
+        endif()
         # ZLIB_INCLUDE_DIRS variable is used by vendored libpng
         set(ZLIB_INCLUDE_DIRS "${ZLIB_INCLUDE_DIR}")
         # ZLIB_LIBRARIES variable is used by vendored libpng