From dd1d8ab62c1c7d49d12e7f3f2c79b3528bc52815 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 21 Feb 2020 15:52:35 -0500 Subject: [PATCH] cmake: more proper sdl2-config.cmake work (thanks, Alexander!) Fixes Bugzilla #4970. --- Makefile.in | 4 +++- configure | 3 ++- configure.ac | 2 +- debian/libsdl2-dev.install | 1 + sdl2-config.cmake.in | 28 ++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Makefile.in b/Makefile.in index 6b4eecf73..65b0fd95b 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 d8da74ac0..744a91604 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 aa751d114..e16c02eba 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 a1f02d8cd..40a9754c7 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 03efbe174..110c605d9 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()