mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
build: Generate better pkg-config files for static-only builds
pkg-config supports `Requires.private` and `Libs.private` fields for static linking. However, if you're building a dynamic binary, then pkg-config will use the non-private fields, even if just the static libxml2 is available. This will result in libxml2 being underlinked, causing the build to fail. The solution is to fold the private fields into the non-private fields when the shared libxml2 is not being built. This works for Autotools and CMake. Meson also knows how to handle this when it automatically generates pkg-config files.
This commit is contained in:
parent
4640ccac85
commit
93e8bb2a40
@ -348,11 +348,6 @@ add_library(LibXml2::LibXml2 ALIAS LibXml2)
|
||||
|
||||
target_compile_definitions(LibXml2 PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(LibXml2 PUBLIC LIBXML_STATIC)
|
||||
set(XML_CFLAGS "-DLIBXML_STATIC")
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Wshadow \
|
||||
-Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return \
|
||||
@ -654,6 +649,16 @@ set(XML_LIBS "-lxml2")
|
||||
set(XML_PRIVATE_LIBS "${Z_LIBS} ${LZMA_LIBS} ${THREAD_LIBS} ${ICONV_LIBS} ${ICU_LIBS} ${LIBM} ${WINSOCK_LIBS}")
|
||||
set(XML_PC_LIBS "${XML_PRIVATE_LIBS}")
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(XML_PC_PRIVATE ".private")
|
||||
set(XML_PC_LIBS_PRIVATE "
|
||||
Libs.private:")
|
||||
else()
|
||||
target_compile_definitions(LibXml2 PUBLIC LIBXML_STATIC)
|
||||
set(XML_CFLAGS "-DLIBXML_STATIC")
|
||||
set(XML_PRIVATE_LIBS_NO_SHARED "${XML_PRIVATE_LIBS}")
|
||||
endif()
|
||||
|
||||
file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
|
||||
string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}")
|
||||
|
||||
|
20
configure.ac
20
configure.ac
@ -1173,6 +1173,26 @@ XML_LIBTOOLLIBS="libxml2.la"
|
||||
XML_PRIVATE_LIBS="${XML_PRIVATE_LIBS} $THREAD_LIBS $ICONV_LIBS $LIBM $NET_LIBS"
|
||||
XML_PRIVATE_CFLAGS="${XML_PRIVATE_CFLAGS} $THREAD_CFLAGS $ICONV_CFLAGS"
|
||||
|
||||
dnl When static-only:
|
||||
dnl * Duplicate xml-config static --libs into --dynamic.
|
||||
dnl * Fold pkg-config private fields into main fields.
|
||||
if test "x$enable_shared" = "xno"; then
|
||||
XML_PRIVATE_LIBS_NO_SHARED="${XML_PRIVATE_LIBS}"
|
||||
XML_PC_PRIVATE=
|
||||
XML_PC_LIBS_PRIVATE=
|
||||
else
|
||||
XML_PRIVATE_LIBS_NO_SHARED=
|
||||
XML_PC_PRIVATE=".private"
|
||||
XML_PC_LIBS_PRIVATE="
|
||||
Libs.private:"
|
||||
fi
|
||||
AC_SUBST(XML_PRIVATE_LIBS_NO_SHARED)
|
||||
AC_SUBST(XML_PC_PRIVATE)
|
||||
AC_SUBST(XML_PC_LIBS_PRIVATE)
|
||||
AM_SUBST_NOTMAKE(XML_PRIVATE_LIBS_NO_SHARED)
|
||||
AM_SUBST_NOTMAKE(XML_PC_PRIVATE)
|
||||
AM_SUBST_NOTMAKE(XML_PC_LIBS_PRIVATE)
|
||||
|
||||
AC_SUBST(XML_PC_LIBS)
|
||||
AC_SUBST(XML_PC_CFLAGS)
|
||||
AC_SUBST(XML_PC_REQUIRES)
|
||||
|
@ -7,7 +7,6 @@ modules=@WITH_MODULES@
|
||||
Name: libXML
|
||||
Version: @VERSION@
|
||||
Description: libXML library version2.
|
||||
Requires: @XML_PC_REQUIRES@
|
||||
Libs: -L${libdir} @XML_LIBS@
|
||||
Libs.private: @XML_PC_LIBS@ @LIBS@
|
||||
Requires@XML_PC_PRIVATE@: @XML_PC_REQUIRES@
|
||||
Libs: -L${libdir} @XML_LIBS@ @XML_PC_LIBS_PRIVATE@ @XML_PC_LIBS@ @LIBS@
|
||||
Cflags: @XML_INCLUDEDIR@ @XML_CFLAGS@ @XML_PC_CFLAGS@
|
||||
|
@ -7,7 +7,6 @@ modules=@WITH_MODULES@
|
||||
Name: libXML
|
||||
Version: @VERSION@
|
||||
Description: libXML library version2.
|
||||
Requires: @XML_PC_REQUIRES@
|
||||
Libs: -L${libdir} @XML_LIBS@
|
||||
Libs.private: @XML_PC_LIBS@ @LIBS@
|
||||
Requires@XML_PC_PRIVATE@: @XML_PC_REQUIRES@
|
||||
Libs: -L${libdir} @XML_LIBS@ @XML_PC_LIBS_PRIVATE@ @XML_PC_LIBS@ @LIBS@
|
||||
Cflags: @XML_INCLUDEDIR@ @XML_CFLAGS@ @XML_PC_CFLAGS@
|
||||
|
@ -84,7 +84,7 @@ while test $# -gt 0; do
|
||||
--libs)
|
||||
if [ "$2" = "--dynamic" ]; then
|
||||
shift
|
||||
libs="@XML_LIBS@"
|
||||
libs="@XML_LIBS@ @XML_PRIVATE_LIBS_NO_SHARED@"
|
||||
else
|
||||
libs="@XML_LIBS@ @XML_PRIVATE_LIBS@ @MODULE_PLATFORM_LIBS@ @LIBS@"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user