Commit 8e13cc309ec2147ac31a3d924a7a1ffb5c2edc43

Anonymous Maarten 2022-05-30T00:46:00

cmake: add 'compatible interface properties' to allow enforcing SDL2 sharedness

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cb158c1..a1bb364 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2953,6 +2953,9 @@ if(SDL_SHARED)
   if(NOT ANDROID)
     set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
   endif()
+  # Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
+  set_property(TARGET SDL2 PROPERTY INTERFACE_SDL2_SHARED TRUE)
+  set_property(TARGET SDL2 APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
 endif()
 
 if(SDL_STATIC)
@@ -2984,6 +2987,9 @@ if(SDL_STATIC)
   if(NOT ANDROID)
     set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
   endif()
+  # Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
+  set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL2_SHARED FALSE)
+  set_property(TARGET SDL2-static APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
 endif()
 
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MAJOR_VERSION=${SDL_MAJOR_VERSION}")