build: Merge pkg-config Libs.private into Libs for static-only builds
authorJames Le Cuirot <chewi@gentoo.org>
Sat, 11 Apr 2020 23:38:34 +0100
changeset 1372989a457159af4
parent 13728 0aea93477d09
child 13730 fc03d19926ed
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
configure
configure.ac
sdl2-config.cmake.in
sdl2-config.in
sdl2.pc.in
     1.1 --- a/CMakeLists.txt	Mon Apr 13 08:05:29 2020 -0700
     1.2 +++ b/CMakeLists.txt	Sat Apr 11 23:38:34 2020 +0100
     1.3 @@ -1279,8 +1279,8 @@
     1.4      set(HAVE_SDL_TIMERS TRUE)
     1.5    endif()
     1.6  
     1.7 -  if(RPATH)
     1.8 -    set(SDL_RLD_FLAGS "")
     1.9 +  set(SDL_RLD_FLAGS "")
    1.10 +  if(RPATH AND SDL_SHARED)
    1.11      if(BSDI OR FREEBSD OR LINUX OR NETBSD)
    1.12        set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags")
    1.13        check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
    1.14 @@ -1950,9 +1950,12 @@
    1.15      set(ENABLE_STATIC_FALSE "")
    1.16    endif()
    1.17    if(SDL_SHARED)
    1.18 +    set(PKG_CONFIG_LIBS_PRIV "
    1.19 +Libs.private:")
    1.20      set(ENABLE_SHARED_TRUE "")
    1.21      set(ENABLE_SHARED_FALSE "#")
    1.22    else()
    1.23 +    set(PKG_CONFIG_LIBS_PRIV "")
    1.24      set(ENABLE_SHARED_TRUE "#")
    1.25      set(ENABLE_SHARED_FALSE "")
    1.26    endif()
     2.1 --- a/configure	Mon Apr 13 08:05:29 2020 -0700
     2.2 +++ b/configure	Sat Apr 11 23:38:34 2020 +0100
     2.3 @@ -647,6 +647,7 @@
     2.4  ENABLE_STATIC_TRUE
     2.5  ENABLE_SHARED_FALSE
     2.6  ENABLE_SHARED_TRUE
     2.7 +PKG_CONFIG_LIBS_PRIV
     2.8  SDL_RLD_FLAGS
     2.9  SDL_STATIC_LIBS
    2.10  SDL_LIBS
    2.11 @@ -25675,7 +25676,7 @@
    2.12  
    2.13  # Set runtime shared library paths as needed
    2.14  
    2.15 -if test "x$enable_rpath" = "xyes"; then
    2.16 +if test "x$enable_rpath" = "xyes" -a "x$enable_shared" = "xyes"; then
    2.17    if test $ARCH = bsdi -o $ARCH = freebsd -o $ARCH = linux -o $ARCH = netbsd; then
    2.18      SDL_RLD_FLAGS="-Wl,-rpath,\${libdir}"
    2.19  
    2.20 @@ -25723,9 +25724,12 @@
    2.21  
    2.22  
    2.23  if test x$enable_shared = xyes; then
    2.24 +    PKG_CONFIG_LIBS_PRIV="
    2.25 +Libs.private:"
    2.26      ENABLE_SHARED_TRUE=
    2.27      ENABLE_SHARED_FALSE="#"
    2.28  else
    2.29 +    PKG_CONFIG_LIBS_PRIV=
    2.30      ENABLE_SHARED_TRUE="#"
    2.31      ENABLE_SHARED_FALSE=
    2.32  fi
     3.1 --- a/configure.ac	Mon Apr 13 08:05:29 2020 -0700
     3.2 +++ b/configure.ac	Sat Apr 11 23:38:34 2020 +0100
     3.3 @@ -4247,7 +4247,7 @@
     3.4  
     3.5  # Set runtime shared library paths as needed
     3.6  
     3.7 -if test "x$enable_rpath" = "xyes"; then
     3.8 +if test "x$enable_rpath" = "xyes" -a "x$enable_shared" = "xyes"; then
     3.9    if test $ARCH = bsdi -o $ARCH = freebsd -o $ARCH = linux -o $ARCH = netbsd; then
    3.10      SDL_RLD_FLAGS="-Wl,-rpath,\${libdir}"
    3.11  
    3.12 @@ -4279,9 +4279,12 @@
    3.13  AC_SUBST(SDL_STATIC_LIBS)
    3.14  AC_SUBST(SDL_RLD_FLAGS)
    3.15  if test x$enable_shared = xyes; then
    3.16 +    PKG_CONFIG_LIBS_PRIV="
    3.17 +Libs.private:"
    3.18      ENABLE_SHARED_TRUE=
    3.19      ENABLE_SHARED_FALSE="#"
    3.20  else
    3.21 +    PKG_CONFIG_LIBS_PRIV=
    3.22      ENABLE_SHARED_TRUE="#"
    3.23      ENABLE_SHARED_FALSE=
    3.24  fi
    3.25 @@ -4292,6 +4295,7 @@
    3.26      ENABLE_STATIC_TRUE="#"
    3.27      ENABLE_STATIC_FALSE=
    3.28  fi
    3.29 +AC_SUBST(PKG_CONFIG_LIBS_PRIV)
    3.30  AC_SUBST(ENABLE_SHARED_TRUE)
    3.31  AC_SUBST(ENABLE_SHARED_FALSE)
    3.32  AC_SUBST(ENABLE_STATIC_TRUE)
     4.1 --- a/sdl2-config.cmake.in	Mon Apr 13 08:05:29 2020 -0700
     4.2 +++ b/sdl2-config.cmake.in	Sat Apr 11 23:38:34 2020 +0100
     4.3 @@ -15,7 +15,7 @@
     4.4    # This may require "libdir" beeing set (from above)
     4.5    string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "@SDL_RLD_FLAGS@ @SDL_LIBS@ ")
     4.6    string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
     4.7 -  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@ ")
     4.8 +  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_STATIC_LIBS@ ")
     4.9    string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
    4.10  
    4.11    add_library(SDL2::SDL2 SHARED IMPORTED)
     5.1 --- a/sdl2-config.in	Mon Apr 13 08:05:29 2020 -0700
     5.2 +++ b/sdl2-config.in	Sat Apr 11 23:38:34 2020 +0100
     5.3 @@ -49,7 +49,7 @@
     5.4  @ENABLE_SHARED_TRUE@      ;;
     5.5  @ENABLE_STATIC_TRUE@@ENABLE_SHARED_TRUE@    --static-libs)
     5.6  @ENABLE_STATIC_TRUE@@ENABLE_SHARED_FALSE@    --libs|--static-libs)
     5.7 -@ENABLE_STATIC_TRUE@      echo -L@libdir@ @SDL_RLD_FLAGS@ @SDL_STATIC_LIBS@
     5.8 +@ENABLE_STATIC_TRUE@      echo -L@libdir@ @SDL_STATIC_LIBS@
     5.9  @ENABLE_STATIC_TRUE@      ;;
    5.10      *)
    5.11        echo "${usage}" 1>&2
     6.1 --- a/sdl2.pc.in	Mon Apr 13 08:05:29 2020 -0700
     6.2 +++ b/sdl2.pc.in	Sat Apr 11 23:38:34 2020 +0100
     6.3 @@ -10,6 +10,5 @@
     6.4  Version: @SDL_VERSION@
     6.5  Requires:
     6.6  Conflicts:
     6.7 -Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@
     6.8 -Libs.private: @SDL_STATIC_LIBS@
     6.9 +Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@ @PKG_CONFIG_LIBS_PRIV@ @SDL_STATIC_LIBS@
    6.10  Cflags: -I${includedir}/SDL2 @SDL_CFLAGS@