Skip to content

Commit 98e5904

Browse files
chewibagder
authored andcommitted
libcurl.pc: Merge 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 libcurl available. This will most likely cause the build to fail due to underlinking unless we merge the Libs fields. Consider that this is what the Meson build system does when it generates pkg-config files. I have also reflected this in the --libs argument of curl-config even though REQUIRE_LIB_DEPS always seems to be "yes" anyway. Closes #5373
1 parent ad64169 commit 98e5904

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,13 +1391,6 @@ set(CONFIGURE_OPTIONS "")
13911391
# TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
13921392
set(CPPFLAG_CURL_STATICLIB "")
13931393
set(CURLVERSION "${CURL_VERSION}")
1394-
if(BUILD_SHARED_LIBS)
1395-
set(ENABLE_SHARED "yes")
1396-
set(ENABLE_STATIC "no")
1397-
else()
1398-
set(ENABLE_SHARED "no")
1399-
set(ENABLE_STATIC "yes")
1400-
endif()
14011394
set(exec_prefix "\${prefix}")
14021395
set(includedir "\${prefix}/include")
14031396
set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
@@ -1410,6 +1403,15 @@ foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
14101403
set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
14111404
endif()
14121405
endforeach()
1406+
if(BUILD_SHARED_LIBS)
1407+
set(ENABLE_SHARED "yes")
1408+
set(ENABLE_STATIC "no")
1409+
set(LIBCURL_NO_SHARED "")
1410+
else()
1411+
set(ENABLE_SHARED "no")
1412+
set(ENABLE_STATIC "yes")
1413+
set(LIBCURL_NO_SHARED "${LIBCURL_LIBS}")
1414+
endif()
14131415
# "a" (Linux) or "lib" (Windows)
14141416
string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
14151417
set(prefix "${CMAKE_INSTALL_PREFIX}")

configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4727,6 +4727,13 @@ dnl to let curl-config output the static libraries correctly
47274727
ENABLE_STATIC="$enable_static"
47284728
AC_SUBST(ENABLE_STATIC)
47294729

4730+
dnl merge the pkg-config Libs.private field into Libs when static-only
4731+
if test "x$enable_shared" = "xno"; then
4732+
LIBCURL_NO_SHARED=$LIBCURL_LIBS
4733+
else
4734+
LIBCURL_NO_SHARED=
4735+
fi
4736+
AC_SUBST(LIBCURL_NO_SHARED)
47304737

47314738
dnl
47324739
dnl For keeping supported features and protocols also in pkg-config file

curl-config.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ while test $# -gt 0; do
160160
else
161161
CURLLIBDIR=""
162162
fi
163-
if test "X@REQUIRE_LIB_DEPS@" = "Xyes"; then
163+
if test "X@ENABLE_SHARED@" = "Xno" -o "X@REQUIRE_LIB_DEPS@" = "Xyes"; then
164164
echo ${CURLLIBDIR}-lcurl @LIBCURL_LIBS@
165165
else
166166
echo ${CURLLIBDIR}-lcurl

libcurl.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ Name: libcurl
3434
URL: https://curl.haxx.se/
3535
Description: Library to transfer files with ftp, http, etc.
3636
Version: @CURLVERSION@
37-
Libs: -L${libdir} -lcurl
37+
Libs: -L${libdir} -lcurl @LIBCURL_NO_SHARED@
3838
Libs.private: @LIBCURL_LIBS@
3939
Cflags: -I${includedir} @CPPFLAG_CURL_STATICLIB@

0 commit comments

Comments
 (0)