cmake: more proper sdl2-config.cmake work (thanks, Alexander!)
authorRyan C. Gordon <icculus@icculus.org>
Fri, 21 Feb 2020 15:52:35 -0500
changeset 13543ef2d5382a887
parent 13542 27cf93d543ca
child 13544 c66d1c7700bd
cmake: more proper sdl2-config.cmake work (thanks, Alexander!)

Fixes Bugzilla #4970.
Makefile.in
configure
configure.ac
debian/libsdl2-dev.install
sdl2-config.cmake.in
     1.1 --- a/Makefile.in	Fri Feb 21 15:51:04 2020 -0500
     1.2 +++ b/Makefile.in	Fri Feb 21 15:52:35 2020 -0500
     1.3 @@ -46,7 +46,7 @@
     1.4  
     1.5  INSTALL_SDL2_CONFIG = @INSTALL_SDL2_CONFIG@
     1.6  
     1.7 -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
     1.8 +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
     1.9  GEN_DIST = SDL2.spec
    1.10  
    1.11  ifneq ($V,1)
    1.12 @@ -188,6 +188,7 @@
    1.13  ifeq ($(INSTALL_SDL2_CONFIG),TRUE)
    1.14  	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)/cmake/SDL2
    1.15  	$(INSTALL) -m 644 sdl2-config.cmake $(DESTDIR)$(libdir)/cmake/SDL2
    1.16 +	$(INSTALL) -m 644 sdl2-config-version.cmake $(DESTDIR)$(libdir)/cmake/SDL2
    1.17  endif
    1.18  
    1.19  uninstall: uninstall-bin uninstall-hdrs uninstall-lib uninstall-data
    1.20 @@ -208,6 +209,7 @@
    1.21  	rm -f $(DESTDIR)$(datadir)/aclocal/sdl2.m4
    1.22  	rm -f $(DESTDIR)$(libdir)/pkgconfig/sdl2.pc
    1.23  	rm -f $(DESTDIR)$(libdir)/cmake/SDL2/sdl2-config.cmake
    1.24 +	rm -f $(DESTDIR)$(libdir)/cmake/SDL2/sdl2-config-version.cmake
    1.25  
    1.26  clean:
    1.27  	rm -rf $(objects)
     2.1 --- a/configure	Fri Feb 21 15:51:04 2020 -0500
     2.2 +++ b/configure	Fri Feb 21 15:52:35 2020 -0500
     2.3 @@ -25627,7 +25627,7 @@
     2.4  $WAYLAND_PROTOCOLS_DEPENDS
     2.5  __EOF__
     2.6  
     2.7 -ac_config_files="$ac_config_files Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake SDL2.spec sdl2.pc"
     2.8 +ac_config_files="$ac_config_files Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake sdl2-config-version.cmake SDL2.spec sdl2.pc"
     2.9  
    2.10  ac_config_commands="$ac_config_commands sdl2_config"
    2.11  
    2.12 @@ -26779,6 +26779,7 @@
    2.13      "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile:Makefile.in:Makefile.rules" ;;
    2.14      "sdl2-config") CONFIG_FILES="$CONFIG_FILES sdl2-config" ;;
    2.15      "sdl2-config.cmake") CONFIG_FILES="$CONFIG_FILES sdl2-config.cmake" ;;
    2.16 +    "sdl2-config-version.cmake") CONFIG_FILES="$CONFIG_FILES sdl2-config-version.cmake" ;;
    2.17      "SDL2.spec") CONFIG_FILES="$CONFIG_FILES SDL2.spec" ;;
    2.18      "sdl2.pc") CONFIG_FILES="$CONFIG_FILES sdl2.pc" ;;
    2.19      "sdl2_config") CONFIG_COMMANDS="$CONFIG_COMMANDS sdl2_config" ;;
     3.1 --- a/configure.ac	Fri Feb 21 15:51:04 2020 -0500
     3.2 +++ b/configure.ac	Fri Feb 21 15:52:35 2020 -0500
     3.3 @@ -4293,7 +4293,7 @@
     3.4  __EOF__
     3.5  
     3.6  AC_CONFIG_FILES([
     3.7 -    Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake SDL2.spec sdl2.pc
     3.8 +    Makefile:Makefile.in:Makefile.rules sdl2-config sdl2-config.cmake sdl2-config-version.cmake SDL2.spec sdl2.pc
     3.9  ])
    3.10  AC_CONFIG_COMMANDS([sdl2_config],[chmod a+x sdl2-config])
    3.11  
     4.1 --- a/debian/libsdl2-dev.install	Fri Feb 21 15:51:04 2020 -0500
     4.2 +++ b/debian/libsdl2-dev.install	Fri Feb 21 15:52:35 2020 -0500
     4.3 @@ -5,4 +5,5 @@
     4.4  usr/lib/*/*.so
     4.5  usr/lib/*/pkgconfig/sdl2.pc
     4.6  usr/lib/*/cmake/SDL2/sdl2-config.cmake
     4.7 +usr/lib/*/cmake/SDL2/sdl2-config-version.cmake
     4.8  usr/share/aclocal/sdl2.m4
     5.1 --- a/sdl2-config.cmake.in	Fri Feb 21 15:51:04 2020 -0500
     5.2 +++ b/sdl2-config.cmake.in	Fri Feb 21 15:52:35 2020 -0500
     5.3 @@ -9,3 +9,31 @@
     5.4  set(SDL2_INCLUDE_DIRS "@includedir@/SDL2")
     5.5  set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} @SDL_RLD_FLAGS@ @SDL_LIBS@")
     5.6  string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
     5.7 +
     5.8 +if(NOT TARGET SDL2::SDL2)
     5.9 +  # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
    5.10 +  # This may require "libdir" beeing set (from above)
    5.11 +  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "@SDL_RLD_FLAGS@ @SDL_LIBS@ ")
    5.12 +  string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
    5.13 +  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@ ")
    5.14 +  string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
    5.15 +
    5.16 +  add_library(SDL2::SDL2 SHARED IMPORTED)
    5.17 +  set_target_properties(SDL2::SDL2 PROPERTIES
    5.18 +    INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
    5.19 +    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    5.20 +    IMPORTED_LOCATION "@libdir@/libSDL2.so"
    5.21 +    INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
    5.22 +
    5.23 +  add_library(SDL2::SDL2-static STATIC IMPORTED)
    5.24 +  set_target_properties(SDL2::SDL2-static PROPERTIES
    5.25 +    INTERFACE_INCLUDE_DIRECTORIES "@includedir@/SDL2"
    5.26 +    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    5.27 +    IMPORTED_LOCATION "@libdir@/libSDL2.a"
    5.28 +    INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")
    5.29 +
    5.30 +  add_library(SDL2::SDL2main STATIC IMPORTED)
    5.31 +  set_target_properties(SDL2::SDL2main PROPERTIES
    5.32 +    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    5.33 +    IMPORTED_LOCATION "@libdir@/libSDL2main.a")
    5.34 +endif()