SDL_image: CMake improvements: see if SDL2 target is defined; allow to build as a static library

From 91f5c9d9f756dd17c0a5d72988623e5ed7b9f8db Mon Sep 17 00:00:00 2001
From: Elias Daler <[EMAIL REDACTED]>
Date: Sat, 27 Mar 2021 01:40:12 +0300
Subject: [PATCH] CMake improvements: see if SDL2 target is defined; allow to
 build as a static library

---
 CMakeLists.txt | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc74a56..d37a25e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,7 @@
 cmake_minimum_required(VERSION 3.3.2)
 project(SDL_image C)
 
-if (ANDROID)
-
-else()
+if (NOT ANDROID AND NOT TARGET SDL2)
     find_package(SDL2 REQUIRED)
 endif()
 
@@ -13,7 +11,7 @@ option(SUPPORT_WEBP "Support loading WEBP images" OFF)
 option(BUILD_SHOWIMAGE "Build the showimage sample program" OFF)
 option(BUILD_SHARED_LIBS "Build the library as a shared library" ON)
 
-add_library(SDL2_image SHARED)
+add_library(SDL2_image)
 target_sources(SDL2_image PRIVATE IMG.c IMG_png.c IMG_bmp.c IMG_gif.c
 		IMG_jpg.c IMG_lbm.c IMG_pcx.c IMG_pnm.c IMG_svg.c IMG_tga.c
 		IMG_tif.c IMG_webp.c IMG_WIC.c IMG_xcf.c IMG_xpm.c IMG_xv.c IMG_xxx.c)