]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: respect cflags/libdirs of native pkg-config detections
authorViktor Szakats <commit@vsz.me>
Thu, 22 Aug 2024 15:05:54 +0000 (17:05 +0200)
committerViktor Szakats <commit@vsz.me>
Fri, 23 Aug 2024 08:43:43 +0000 (10:43 +0200)
In Find modules with native pkg-config detection (libgsasl, libidn2,
libssh, libuv, nettle) use the C compiler flags returned by pkg-config.
Also use the library paths, and return the pathless library names.

Also:
- add these library paths to `libcurl.pc`/`curl-config`.
- fix libgsasl detection to use the detected header directory.

FindGSS already did this before this patch.

Fixes #14641

Closes #14652

CMake/FindLibgsasl.cmake
CMake/FindLibidn2.cmake
CMake/FindLibssh.cmake
CMake/FindLibuv.cmake
CMake/FindNettle.cmake
CMakeLists.txt

index 261c0111a8c36b86ea6af94c116a72265aa3d606..ed930ebb766213ba1ac46a0a2850b915b83dcb8b 100644 (file)
@@ -33,6 +33,8 @@
 # LIBGSASL_FOUND         System has libgsasl
 # LIBGSASL_INCLUDE_DIRS  The libgsasl include directories
 # LIBGSASL_LIBRARIES     The libgsasl library names
+# LIBGSASL_LIBRARY_DIRS  The libgsasl library directories
+# LIBGSASL_CFLAGS        Required compiler flags
 # LIBGSASL_VERSION       Version of libgsasl
 
 if(CURL_USE_PKGCONFIG AND
@@ -43,7 +45,7 @@ if(CURL_USE_PKGCONFIG AND
 endif()
 
 if(LIBGSASL_FOUND)
-  set(LIBGSASL_LIBRARIES ${LIBGSASL_LINK_LIBRARIES})
+  string(REPLACE ";" " " LIBGSASL_CFLAGS "${LIBGSASL_CFLAGS}")
   message(STATUS "Found Libgsasl (via pkg-config): ${LIBGSASL_INCLUDE_DIRS} (found version \"${LIBGSASL_VERSION}\")")
 else()
   find_path(LIBGSASL_INCLUDE_DIR NAMES "gsasl.h")
index c51600bf6fc7b18fbdfac548cbdf5391e4721024..47d4a58623e37fd586f16c75128f4aa4d04a753b 100644 (file)
@@ -33,6 +33,8 @@
 # LIBIDN2_FOUND         System has libidn2
 # LIBIDN2_INCLUDE_DIRS  The libidn2 include directories
 # LIBIDN2_LIBRARIES     The libidn2 library names
+# LIBIDN2_LIBRARY_DIRS  The libidn2 library directories
+# LIBIDN2_CFLAGS        Required compiler flags
 # LIBIDN2_VERSION       Version of libidn2
 
 if(CURL_USE_PKGCONFIG AND
@@ -43,7 +45,7 @@ if(CURL_USE_PKGCONFIG AND
 endif()
 
 if(LIBIDN2_FOUND)
-  set(LIBIDN2_LIBRARIES ${LIBIDN2_LINK_LIBRARIES})
+  string(REPLACE ";" " " LIBIDN2_CFLAGS "${LIBIDN2_CFLAGS}")
   message(STATUS "Found Libidn2 (via pkg-config): ${LIBIDN2_INCLUDE_DIRS} (found version \"${LIBIDN2_VERSION}\")")
 else()
   find_path(LIBIDN2_INCLUDE_DIR NAMES "idn2.h")
index 3627ffe14de791081b360af264c2035a56811402..7dc019be7564fc853fe114aabf89902960686f61 100644 (file)
@@ -33,6 +33,8 @@
 # LIBSSH_FOUND         System has libssh
 # LIBSSH_INCLUDE_DIRS  The libssh include directories
 # LIBSSH_LIBRARIES     The libssh library names
+# LIBSSH_LIBRARY_DIRS  The libssh library directories
+# LIBSSH_CFLAGS        Required compiler flags
 # LIBSSH_VERSION       Version of libssh
 
 if(CURL_USE_PKGCONFIG AND
@@ -43,10 +45,7 @@ if(CURL_USE_PKGCONFIG AND
 endif()
 
 if(LIBSSH_FOUND)
-  if(NOT DEFINED LIBSSH_LINK_LIBRARIES)
-    set(LIBSSH_LINK_LIBRARIES ${LIBSSH_LIBRARIES})  # Workaround for some systems (seen on Old Linux CI)
-  endif()
-  set(LIBSSH_LIBRARIES ${LIBSSH_LINK_LIBRARIES})
+  string(REPLACE ";" " " LIBSSH_CFLAGS "${LIBSSH_CFLAGS}")
   message(STATUS "Found Libssh (via pkg-config): ${LIBSSH_INCLUDE_DIRS} (found version \"${LIBSSH_VERSION}\")")
 else()
   find_path(LIBSSH_INCLUDE_DIR NAMES "libssh/libssh.h")
index 78ec4d32aa0f708da1f2659e5ce8e7262f4243d6..d4dfa2450332d8f9b1ee45bc24e344eab669fe28 100644 (file)
@@ -33,6 +33,8 @@
 # LIBUV_FOUND         System has libuv
 # LIBUV_INCLUDE_DIRS  The libuv include directories
 # LIBUV_LIBRARIES     The libuv library names
+# LIBUV_LIBRARY_DIRS  The libuv library directories
+# LIBUV_CFLAGS        Required compiler flags
 # LIBUV_VERSION       Version of libuv
 
 if(CURL_USE_PKGCONFIG AND
@@ -43,7 +45,7 @@ if(CURL_USE_PKGCONFIG AND
 endif()
 
 if(LIBUV_FOUND)
-  set(LIBUV_LIBRARIES ${LIBUV_LINK_LIBRARIES})
+  string(REPLACE ";" " " LIBUV_CFLAGS "${LIBUV_CFLAGS}")
   message(STATUS "Found Libuv (via pkg-config): ${LIBUV_INCLUDE_DIRS} (found version \"${LIBUV_VERSION}\")")
 else()
   find_path(LIBUV_INCLUDE_DIR NAMES "uv.h")
index 8451e7750770933b07b667556dc5914cbb49357c..b5da05bf79a7fcb59427b42d21d0e10c3facf56c 100644 (file)
@@ -33,6 +33,8 @@
 # NETTLE_FOUND         System has nettle
 # NETTLE_INCLUDE_DIRS  The nettle include directories
 # NETTLE_LIBRARIES     The nettle library names
+# NETTLE_LIBRARY_DIRS  The nettle library directories
+# NETTLE_CFLAGS        Required compiler flags
 # NETTLE_VERSION       Version of nettle
 
 if(CURL_USE_PKGCONFIG AND
@@ -43,7 +45,7 @@ if(CURL_USE_PKGCONFIG AND
 endif()
 
 if(NETTLE_FOUND)
-  set(NETTLE_LIBRARIES ${NETTLE_LINK_LIBRARIES})
+  string(REPLACE ";" " " NETTLE_CFLAGS "${NETTLE_CFLAGS}")
   message(STATUS "Found Nettle (via pkg-config): ${NETTLE_INCLUDE_DIRS} (found version \"${NETTLE_VERSION}\")")
 else()
   find_path(NETTLE_INCLUDE_DIR NAMES "nettle/sha2.h")
index 20d6f68dfe497f1fcba30f7efcdf2b720e7bfada..dfe2974d9a8292ad78618715a8186a331007a952 100644 (file)
@@ -219,6 +219,7 @@ option(CURL_USE_PKGCONFIG "Enable pkg-config to detect dependencies" ${_curl_use
 
 # Initialize CURL_LIBS
 set(CURL_LIBS "")
+set(CURL_LIBDIRS "")
 set(LIBCURL_PC_REQUIRES_PRIVATE "")
 
 if(ENABLE_ARES)
@@ -621,8 +622,13 @@ if(CURL_USE_GNUTLS)
   set(_ssl_enabled ON)
   set(USE_GNUTLS ON)
   list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} ${NETTLE_LIBRARIES})
+  list(APPEND CURL_LIBDIRS ${NETTLE_LIBRARY_DIRS})
   list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "gnutls" "nettle")
   include_directories(${GNUTLS_INCLUDE_DIRS} ${NETTLE_INCLUDE_DIRS})
+  link_directories(${NETTLE_LIBRARY_DIRS})
+  if(NETTLE_CFLAGS)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NETTLE_CFLAGS}")
+  endif()
 
   if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls")
     set(_valid_default_ssl_backend TRUE)
@@ -999,8 +1005,13 @@ if(USE_LIBIDN2)
   find_package(Libidn2)
   if(LIBIDN2_FOUND)
     set(CURL_LIBS "${LIBIDN2_LIBRARIES};${CURL_LIBS}")
+    list(APPEND CURL_LIBDIRS ${LIBIDN2_LIBRARY_DIRS})
     set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
     include_directories(${LIBIDN2_INCLUDE_DIRS})
+    link_directories(${LIBIDN2_LIBRARY_DIRS})
+    if(LIBIDN2_CFLAGS)
+      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBIDN2_CFLAGS}")
+    endif()
     set(HAVE_IDN2_H 1)
     set(HAVE_LIBIDN2 1)
   endif()
@@ -1071,8 +1082,13 @@ if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
   find_package(Libssh REQUIRED)
   if(LIBSSH_FOUND)
     list(APPEND CURL_LIBS ${LIBSSH_LIBRARIES})
+    list(APPEND CURL_LIBDIRS ${LIBSSH_LIBRARY_DIRS})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh")
     include_directories(${LIBSSH_INCLUDE_DIRS})
+    link_directories(${LIBSSH_LIBRARY_DIRS})
+    if(LIBSSH_CFLAGS)
+      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBSSH_CFLAGS}")
+    endif()
     set(USE_LIBSSH ON)
   endif()
 endif()
@@ -1101,7 +1117,13 @@ if(CURL_USE_GSASL)
   find_package(Libgsasl REQUIRED)
   if(LIBGSASL_FOUND)
     list(APPEND CURL_LIBS ${LIBGSASL_LIBRARIES})
+    list(APPEND CURL_LIBDIRS ${LIBGSASL_LIBRARY_DIRS})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libgsasl")
+    include_directories(${LIBGSASL_INCLUDE_DIRS})
+    link_directories(${LIBGSASL_LIBRARY_DIRS})
+    if(LIBGSASL_CFLAGS)
+      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBGSASL_CFLAGS}")
+    endif()
     set(USE_GSASL ON)
   endif()
 endif()
@@ -1175,8 +1197,13 @@ if(CURL_USE_LIBUV)
   find_package(Libuv REQUIRED)
   if(LIBUV_FOUND)
     list(APPEND CURL_LIBS ${LIBUV_LIBRARIES})
+    list(APPEND CURL_LIBDIRS ${LIBUV_LIBRARY_DIRS})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libuv")
     include_directories(${LIBUV_INCLUDE_DIRS})
+    link_directories(${LIBUV_LIBRARY_DIRS})
+    if(LIBUV_CFLAGS)
+      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUV_CFLAGS}")
+    endif()
     set(USE_LIBUV ON)
     set(HAVE_UV_H ON)
   endif()
@@ -1936,6 +1963,10 @@ if(NOT CURL_DISABLE_INSTALL)
     endif()
   endforeach()
 
+  foreach(_lib IN LISTS CURL_LIBDIRS)
+    set(LIBCURL_PC_LIBS_PRIVATE "${LIBCURL_PC_LIBS_PRIVATE} -L${_lib}")
+  endforeach()
+
   foreach(_lib IN LISTS CMAKE_C_IMPLICIT_LINK_LIBRARIES CURL_LIBS)
     if(TARGET "${_lib}")
       set(_libname "${_lib}")