From: Richard Levitte Date: Tue, 13 Feb 2024 05:45:57 +0000 (+0100) Subject: cmake: fix libcurl.pc and curl-config library specifications X-Git-Tag: curl-8_7_0~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=296e855d364525b9775c68754499d1ff045d3a57;p=thirdparty%2Fcurl.git cmake: fix libcurl.pc and curl-config library specifications Letting CMake figure out where libraries are located gives you full paths. When generating libcurl.pc and curl-config, getting libraries as full paths is unusual when one expects to get a list of -l. To meet expectations, an effort is made to convert the full paths into -l, possibly with -L before it. Fixes #6169 Fixes #12748 Closes #12930 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c0f77651..2c69e5628c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1642,6 +1642,30 @@ if(NOT CURL_DISABLE_INSTALL) set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}") set(LIBCURL_LIBS "") set(libdir "${CMAKE_INSTALL_PREFIX}/lib") + + # For processing full path libraries into -L and -l ld options, + # the directories that go with the -L option are cached, so they + # only get added once per such directory. + set(_libcurl_libs_dirs) + # To avoid getting unnecessary -L options for known system directories, + # _libcurl_libs_dirs is seeded with them. + foreach(_libdir ${CMAKE_SYSTEM_PREFIX_PATH}) + if(_libdir MATCHES "/$") + set(_libdir "${_libdir}lib") + else() + set(_libdir "${_libdir}/lib") + endif() + if(IS_DIRECTORY "${_libdir}") + list(APPEND _libcurl_libs_dirs "${_libdir}") + endif() + if(DEFINED CMAKE_LIBRARY_ARCHITECTURE) + set(_libdir "${_libdir}/${CMAKE_LIBRARY_ARCHITECTURE}") + if(IS_DIRECTORY "${_libdir}") + list(APPEND _libcurl_libs_dirs "${_libdir}") + endif() + endif() + endforeach() + foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS}) if(TARGET "${_lib}") set(_libname "${_lib}") @@ -1657,8 +1681,24 @@ if(NOT CURL_DISABLE_INSTALL) continue() endif() endif() - if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-") + if(_lib MATCHES "^-") set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}") + elseif(_lib MATCHES ".*/.*") + # This gets a bit more complex, because we want to specify the + # directory separately, and only once per directory + string(REGEX REPLACE "^(.*)/[^/]*$" "\\1" _libdir "${_lib}") + string(REGEX REPLACE "^.*/([^/.]*).*$" "\\1" _libname "${_lib}") + if(_libname MATCHES "^lib") + list(FIND _libcurl_libs_dirs "${_libdir}" _libdir_index) + if(_libdir_index LESS 0) + list(APPEND _libcurl_libs_dirs "${_libdir}") + set(LIBCURL_LIBS "${LIBCURL_LIBS} -L${_libdir}") + endif() + string(REGEX REPLACE "^lib" "" _libname "${_libname}") + set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_libname}") + else() + set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}") + endif() else() set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}") endif() diff --git a/docs/KNOWN_BUGS b/docs/KNOWN_BUGS index eab7e63897..beaa036231 100644 --- a/docs/KNOWN_BUGS +++ b/docs/KNOWN_BUGS @@ -98,7 +98,6 @@ problems may have been fixed or changed somewhat since this was written. 15.3 unusable tool_hugehelp.c with MinGW 15.6 uses -lpthread instead of Threads::Threads 15.7 generated .pc file contains strange entries - 15.8 libcurl.pc uses absolute library paths 15.11 ExternalProject_Add does not set CURL_CA_PATH 15.13 CMake build with MIT Kerberos does not work @@ -577,14 +576,6 @@ problems may have been fixed or changed somewhat since this was written. See https://github.com/curl/curl/issues/6167 -15.8 libcurl.pc uses absolute library paths - - The libcurl.pc file generated by cmake contains things like Libs.private: - /usr/lib64/libssl.so /usr/lib64/libcrypto.so /usr/lib64/libz.so. The - autotools equivalent would say Libs.private: -lssl -lcrypto -lz - - See https://github.com/curl/curl/issues/6169 - 15.11 ExternalProject_Add does not set CURL_CA_PATH CURL_CA_BUNDLE and CURL_CA_PATH are not set properly when cmake's