Skip to content
Permalink
Browse files

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.
  • Loading branch information
chewi committed Apr 11, 2020
1 parent bd7b4f3 commit 99f87a71583bb86329c7fac393819e62772efd4f
Showing with 18 additions and 8 deletions.
  1. +5 −2 CMakeLists.txt
  2. +5 −1 configure
  3. +5 −1 configure.ac
  4. +1 −1 sdl2-config.cmake.in
  5. +1 −1 sdl2-config.in
  6. +1 −2 sdl2.pc.in
@@ -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()
@@ -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

# 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}"



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

0 comments on commit 99f87a7

Please sign in to comment.