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.
This commit is contained in:
James Le Cuirot 2020-04-11 23:38:34 +01:00
parent bd7b4f39ed
commit 99f87a7158
6 changed files with 18 additions and 8 deletions

View File

@ -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 "")
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()

6
configure vendored
View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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@