cmake: make sure SDL2::SDL2 is always available
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 80bba4e..ddbc7e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3194,3 +3194,8 @@ endif()
##### Fix Objective C builds #####
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} ${CMAKE_C_FLAGS}")
+
+# Make sure SDL2::SDL2 always exists
+if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
+ add_library(SDL2::SDL2 ALIAS SDL2-static)
+endif()
diff --git a/SDL2Config.cmake.in b/SDL2Config.cmake.in
index 99344b2..ba35770 100644
--- a/SDL2Config.cmake.in
+++ b/SDL2Config.cmake.in
@@ -30,12 +30,14 @@ endif()
check_required_components(SDL2)
# Create SDL2::SDL2 alias for static-only builds
-if(NOT TARGET SDL2::SDL2 AND TARGET SDL2::SDL2-static)
+if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
if(CMAKE_VERSION VERSION_LESS "3.18")
- # Aliasing local targets is not supported on CMake < 3.18, so make it global.
- set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE)
+ # FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
+ add_library(SDL2::SDL2 INTERFACE IMPORTED)
+ set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES "SDL2::SDL2-static")
+ else()
+ add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
endif()
- add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
endif()
# For compatibility with autotools sdl2-config.cmake, provide SDL2_* variables.
@@ -57,4 +59,4 @@ if(TARGET SDL2::SDL2main)
list(INSERT SDL2_STATIC_LIBRARIES 0 SDL2::SDL2main)
endif()
-set(SDL2TEST_LIBRARY SDL2::SDL2test)
+set(SDL2TEST_LIBRARY SDL2::SDL2test)
\ No newline at end of file
diff --git a/sdl2-config.cmake.in b/sdl2-config.cmake.in
index 2ac3fbe..37610ba 100644
--- a/sdl2-config.cmake.in
+++ b/sdl2-config.cmake.in
@@ -192,3 +192,14 @@ macro(check_required_components _NAME)
endmacro()
check_required_components(SDL2)
+
+# Create SDL2::SDL2 alias for static-only builds
+if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
+ if(CMAKE_VERSION VERSION_LESS "3.18")
+ # FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
+ add_library(SDL2::SDL2 INTERFACE IMPORTED)
+ set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES "SDL2::SDL2-static")
+ else()
+ add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
+ endif()
+endif()