cmake: more proper sdl2-config.cmake work (thanks, Alexander!) Fixes Bugzilla #4970.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
diff --git a/Makefile.in b/Makefile.in
index 6b4eecf..65b0fd9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -46,7 +46,7 @@ WAYLAND_SCANNER = @WAYLAND_SCANNER@
INSTALL_SDL2_CONFIG = @INSTALL_SDL2_CONFIG@
-SRC_DIST = *.txt acinclude Android.mk autogen.sh android-project build-scripts cmake cmake_uninstall.cmake.in configure configure.ac debian docs include Makefile.* sdl2-config.cmake.in sdl2-config.in sdl2.m4 sdl2.pc.in SDL2.spec.in SDL2Config.cmake src test VisualC.html VisualC VisualC-WinRT Xcode Xcode-iOS wayland-protocols
+SRC_DIST = *.txt acinclude Android.mk autogen.sh android-project build-scripts cmake cmake_uninstall.cmake.in configure configure.ac debian docs include Makefile.* sdl2-config.cmake.in sdl2-config-version.cmake.in sdl2-config.in sdl2.m4 sdl2.pc.in SDL2.spec.in SDL2Config.cmake src test VisualC.html VisualC VisualC-WinRT Xcode Xcode-iOS wayland-protocols
GEN_DIST = SDL2.spec
ifneq ($V,1)
@@ -188,6 +188,7 @@ install-data:
ifeq ($(INSTALL_SDL2_CONFIG),TRUE)
$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)/cmake/SDL2
$(INSTALL) -m 644 sdl2-config.cmake $(DESTDIR)$(libdir)/cmake/SDL2
+ $(INSTALL) -m 644 sdl2-config-version.cmake $(DESTDIR)$(libdir)/cmake/SDL2
endif
uninstall: uninstall-bin uninstall-hdrs uninstall-lib uninstall-data
@@ -208,6 +209,7 @@ uninstall-data:
rm -f $(DESTDIR)$(datadir)/aclocal/sdl2.m4
rm -f $(DESTDIR)$(libdir)/pkgconfig/sdl2.pc
rm -f $(DESTDIR)$(libdir)/cmake/SDL2/sdl2-config.cmake
+ rm -f $(DESTDIR)$(libdir)/cmake/SDL2/sdl2-config-version.cmake
clean:
rm -rf $(objects)
diff --git a/configure b/configure
index d8da74a..744a916 100755
--- a/configure
+++ b/configure
@@ -25627,7 +25627,7 @@ $SDLTEST_DEPENDS
$WAYLAND_PROTOCOLS_DEPENDS
__EOF__
-ac_config_files="$ac_config_files Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake SDL2.spec sdl2.pc"
+ac_config_files="$ac_config_files Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake sdl2-config-version.cmake SDL2.spec sdl2.pc"
ac_config_commands="$ac_config_commands sdl2_config"
@@ -26779,6 +26779,7 @@ do
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile:Makefile.in:Makefile.rules" ;;
"sdl2-config") CONFIG_FILES="$CONFIG_FILES sdl2-config" ;;
"sdl2-config.cmake") CONFIG_FILES="$CONFIG_FILES sdl2-config.cmake" ;;
+ "sdl2-config-version.cmake") CONFIG_FILES="$CONFIG_FILES sdl2-config-version.cmake" ;;
"SDL2.spec") CONFIG_FILES="$CONFIG_FILES SDL2.spec" ;;
"sdl2.pc") CONFIG_FILES="$CONFIG_FILES sdl2.pc" ;;
"sdl2_config") CONFIG_COMMANDS="$CONFIG_COMMANDS sdl2_config" ;;
diff --git a/configure.ac b/configure.ac
index aa751d1..e16c02e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4293,7 +4293,7 @@ $WAYLAND_PROTOCOLS_DEPENDS
__EOF__
AC_CONFIG_FILES([
- Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake SDL2.spec sdl2.pc
+ Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake sdl2-config-version.cmake SDL2.spec sdl2.pc
])
AC_CONFIG_COMMANDS([sdl2_config],[chmod a+x sdl2-config])
diff --git a/debian/libsdl2-dev.install b/debian/libsdl2-dev.install
index a1f02d8..40a9754 100644
--- a/debian/libsdl2-dev.install
+++ b/debian/libsdl2-dev.install
@@ -5,4 +5,5 @@ usr/lib/*/*.la
usr/lib/*/*.so
usr/lib/*/pkgconfig/sdl2.pc
usr/lib/*/cmake/SDL2/sdl2-config.cmake
+usr/lib/*/cmake/SDL2/sdl2-config-version.cmake
usr/share/aclocal/sdl2.m4
diff --git a/sdl2-config.cmake.in b/sdl2-config.cmake.in
index 03efbe1..110c605 100644
--- a/sdl2-config.cmake.in
+++ b/sdl2-config.cmake.in
@@ -9,3 +9,31 @@ set(SDL2_LIBDIR "@libdir@")
set(SDL2_INCLUDE_DIRS "@includedir@/SDL2")
set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} @SDL_RLD_FLAGS@ @SDL_LIBS@")
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
+
+if(NOT TARGET SDL2::SDL2)
+ # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
+ # This may require "libdir" beeing set (from above)
+ string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "@SDL_RLD_FLAGS@ @SDL_LIBS@ ")
+ string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
+ string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@ ")
+ string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
+
+ add_library(SDL2::SDL2 SHARED IMPORTED)
+ set_target_properties(SDL2::SDL2 PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "@libdir@/libSDL2.so"
+ INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
+
+ add_library(SDL2::SDL2-static STATIC IMPORTED)
+ set_target_properties(SDL2::SDL2-static PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "@libdir@/libSDL2.a"
+ INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")
+
+ add_library(SDL2::SDL2main STATIC IMPORTED)
+ set_target_properties(SDL2::SDL2main PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "@libdir@/libSDL2main.a")
+endif()