Skip to content

Commit

Permalink
build: Merge pkg-config Libs.private into Libs for static-only builds
Browse files Browse the repository at this point in the history
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 99f87a7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion configure
Expand Up @@ -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
Expand Down Expand Up @@ -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}"

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion configure.ac
Expand Up @@ -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}"

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdl2-config.cmake.in
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdl2-config.in
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions sdl2.pc.in
Expand Up @@ -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.