SDL_image: Add BUILD_SDL compile definition + override fPIC at start of block

From 9708968d64e8b9aefe3dcd30787d690851df6bae Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 25 May 2022 18:09:04 +0200
Subject: [PATCH] Add BUILD_SDL compile definition + override fPIC at start of
 block

---
 CMakeLists.txt | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6b67c79..8ccdbe3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -203,6 +203,7 @@ target_include_directories(SDL2_image PUBLIC
     "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>"
 )
 target_compile_definitions(SDL2_image PRIVATE
+    BUILD_SDL
     SDL_BUILD_MAJOR_VERSION=${MAJOR_VERSION}
     SDL_BUILD_MINOR_VERSION=${MINOR_VERSION}
     SDL_BUILD_MICRO_VERSION=${MICRO_VERSION}
@@ -211,7 +212,7 @@ target_link_libraries(SDL2_image PRIVATE ${sdl2_target_name})
 if(WIN32 AND SDL2IMAGE_BUILD_SHARED_LIBS)
     target_sources(SDL2_image PRIVATE
         version.rc
-)
+    )
 endif()
 set_target_properties(SDL2_image PROPERTIES
     DEFINE_SYMBOL DLL_EXPORT
@@ -262,10 +263,15 @@ if(SDL2IMAGE_BUILD_SHARED_LIBS)
     endif()
 endif()
 
-# Use `Compatible Interface Properties` to ensure all SDL2 libraries are built with the same "sharedness".
+# Use `Compatible Interface Properties` to ensure all linked SDL2 libraries are built with the same "sharedness".
 set_property(TARGET SDL2_image PROPERTY INTERFACE_SDL2_SHARED ${SDL2IMAGE_BUILD_SHARED_LIBS})
 set_property(TARGET SDL2_image APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
 
+if(SDL2IMAGE_BUILD_SHARED_LIBS)
+    # Make sure static library dependencies are built with -fPIC when building a shared SDL2_image
+    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+endif()
+
 set(INSTALL_EXTRA_TARGETS)
 set(PC_LIBS)
 set(PC_REQUIRES)
@@ -274,11 +280,6 @@ if(SDL2IMAGE_BACKEND_STB)
     target_compile_definitions(SDL2_image PRIVATE USE_STBIMAGE)
 endif()
 
-if(SDL2IMAGE_BUILD_SHARED_LIBS)
-    # Make sure static library dependencies are built with -fPIC when building a shared SDL2_image
-    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
-endif()
-
 if(APPLE)
     if(SDL2IMAGE_BACKEND_IMAGEIO)
         target_link_options(SDL2_image PRIVATE -Wl,-framework,ApplicationServices)