From 99f87a71583bb86329c7fac393819e62772efd4f Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Sat, 11 Apr 2020 23:38:34 +0100 Subject: [PATCH] build: Merge pkg-config Libs.private into Libs for static-only builds A project being built entirely statically will call pkg-config with --static, which utilises the Libs.private field. Conversely it will not use --static when not being built entirely statically, even if there is only a static build of SDL available. This will most likely cause the build to fail due to underlinking unless we merge the Libs fields. This is what the Meson build system does when it generates pkg-config files. This also also follows the behaviour of sdl2-config. At the same time, the runtime linker flags are not applicable to static-only builds so only add them for shared builds. --- CMakeLists.txt | 7 +++++-- configure | 6 +++++- configure.ac | 6 +++++- sdl2-config.cmake.in | 2 +- sdl2-config.in | 2 +- sdl2.pc.in | 3 +-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c783d2ca9..2c9cea107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1279,8 +1279,8 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS) set(HAVE_SDL_TIMERS TRUE) endif() - if(RPATH) - set(SDL_RLD_FLAGS "") + set(SDL_RLD_FLAGS "") + if(RPATH AND SDL_SHARED) if(BSDI OR FREEBSD OR LINUX OR NETBSD) set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags") check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS) @@ -1950,9 +1950,12 @@ if(NOT WINDOWS OR CYGWIN) set(ENABLE_STATIC_FALSE "") endif() if(SDL_SHARED) + set(PKG_CONFIG_LIBS_PRIV " +Libs.private:") set(ENABLE_SHARED_TRUE "") set(ENABLE_SHARED_FALSE "#") else() + set(PKG_CONFIG_LIBS_PRIV "") set(ENABLE_SHARED_TRUE "#") set(ENABLE_SHARED_FALSE "") endif() diff --git a/configure b/configure index a08ec422c..5103b8429 100755 --- a/configure +++ b/configure @@ -647,6 +647,7 @@ ENABLE_STATIC_FALSE ENABLE_STATIC_TRUE ENABLE_SHARED_FALSE ENABLE_SHARED_TRUE +PKG_CONFIG_LIBS_PRIV SDL_RLD_FLAGS SDL_STATIC_LIBS SDL_LIBS @@ -25675,7 +25676,7 @@ SDLTEST_DEPENDS=`echo "$SDLTEST_DEPENDS" | sed "s,\\([^ ]*\\)/\\([^ ]*\\)\\.c,\\ # Set runtime shared library paths as needed -if test "x$enable_rpath" = "xyes"; then +if test "x$enable_rpath" = "xyes" -a "x$enable_shared" = "xyes"; then if test $ARCH = bsdi -o $ARCH = freebsd -o $ARCH = linux -o $ARCH = netbsd; then SDL_RLD_FLAGS="-Wl,-rpath,\${libdir}" @@ -25723,9 +25724,12 @@ SDL_STATIC_LIBS="$SDL_LIBS $EXTRA_LDFLAGS" if test x$enable_shared = xyes; then + PKG_CONFIG_LIBS_PRIV=" +Libs.private:" ENABLE_SHARED_TRUE= ENABLE_SHARED_FALSE="#" else + PKG_CONFIG_LIBS_PRIV= ENABLE_SHARED_TRUE="#" ENABLE_SHARED_FALSE= fi diff --git a/configure.ac b/configure.ac index e2c9ef1f8..a8985c72b 100644 --- a/configure.ac +++ b/configure.ac @@ -4247,7 +4247,7 @@ SDLTEST_DEPENDS=`echo "$SDLTEST_DEPENDS" | sed "s,\\([[^ ]]*\\)/\\([[^ ]]*\\)\\. # Set runtime shared library paths as needed -if test "x$enable_rpath" = "xyes"; then +if test "x$enable_rpath" = "xyes" -a "x$enable_shared" = "xyes"; then if test $ARCH = bsdi -o $ARCH = freebsd -o $ARCH = linux -o $ARCH = netbsd; then SDL_RLD_FLAGS="-Wl,-rpath,\${libdir}" @@ -4279,9 +4279,12 @@ AC_SUBST(SDL_LIBS) AC_SUBST(SDL_STATIC_LIBS) AC_SUBST(SDL_RLD_FLAGS) if test x$enable_shared = xyes; then + PKG_CONFIG_LIBS_PRIV=" +Libs.private:" ENABLE_SHARED_TRUE= ENABLE_SHARED_FALSE="#" else + PKG_CONFIG_LIBS_PRIV= ENABLE_SHARED_TRUE="#" ENABLE_SHARED_FALSE= fi @@ -4292,6 +4295,7 @@ else ENABLE_STATIC_TRUE="#" ENABLE_STATIC_FALSE= fi +AC_SUBST(PKG_CONFIG_LIBS_PRIV) AC_SUBST(ENABLE_SHARED_TRUE) AC_SUBST(ENABLE_SHARED_FALSE) AC_SUBST(ENABLE_STATIC_TRUE) diff --git a/sdl2-config.cmake.in b/sdl2-config.cmake.in index de54e9aad..e528a8844 100644 --- a/sdl2-config.cmake.in +++ b/sdl2-config.cmake.in @@ -15,7 +15,7 @@ if(NOT TARGET SDL2::SDL2) # 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(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_STATIC_LIBS@ ") string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC) add_library(SDL2::SDL2 SHARED IMPORTED) diff --git a/sdl2-config.in b/sdl2-config.in index 254a345e6..98d6e0653 100644 --- a/sdl2-config.in +++ b/sdl2-config.in @@ -49,7 +49,7 @@ while test $# -gt 0; do @ENABLE_SHARED_TRUE@ ;; @ENABLE_STATIC_TRUE@@ENABLE_SHARED_TRUE@ --static-libs) @ENABLE_STATIC_TRUE@@ENABLE_SHARED_FALSE@ --libs|--static-libs) -@ENABLE_STATIC_TRUE@ echo -L@libdir@ @SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@ +@ENABLE_STATIC_TRUE@ echo -L@libdir@ @SDL_STATIC_LIBS@ @ENABLE_STATIC_TRUE@ ;; *) echo "${usage}" 1>&2 diff --git a/sdl2.pc.in b/sdl2.pc.in index b11667dc6..9d76d4797 100644 --- a/sdl2.pc.in +++ b/sdl2.pc.in @@ -10,6 +10,5 @@ Description: Simple DirectMedia Layer is a cross-platform multimedia library des Version: @SDL_VERSION@ Requires: Conflicts: -Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@ -Libs.private: @SDL_STATIC_LIBS@ +Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@ @PKG_CONFIG_LIBS_PRIV@ @SDL_STATIC_LIBS@ Cflags: -I${includedir}/SDL2 @SDL_CFLAGS@