]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: migrate dependency detections to Find modules
authorViktor Szakats <commit@vsz.me>
Mon, 19 Aug 2024 12:27:51 +0000 (14:27 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 20 Aug 2024 09:38:40 +0000 (11:38 +0200)
For: libgsasl, libidn2, libssh, libuv.

The new Find modules retain using `pkg-config` natively, not as a "hint"
for the CMake-native detection. Of the pre-existing Find modules, only
FindNettle, and FindGSS (with customized code) work this way. Align
detection code for the new modules and add version detection for the
CMake-native paths.

Also, add CMake-native detection for `libgsasl`.

The remaining outlier in `CMakeLists.txt` is GnuTLS, which has
a CMake built-in Find module, but which lacks `pkg-config` support,
required for vcpkg. It remains unchanged.

Another part-outlier is `libssh`, which keeps requiring the trick
`find_package(libssh CONFIG QUIET)` for reasons I could not yet figure
out.

Closes #14555

CMake/FindLibgsasl.cmake [new file with mode: 0644]
CMake/FindLibidn2.cmake [new file with mode: 0644]
CMake/FindLibssh.cmake [new file with mode: 0644]
CMake/FindLibuv.cmake [new file with mode: 0644]
CMakeLists.txt
Makefile.am

diff --git a/CMake/FindLibgsasl.cmake b/CMake/FindLibgsasl.cmake
new file mode 100644 (file)
index 0000000..bac8682
--- /dev/null
@@ -0,0 +1,76 @@
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+# Find the libgsasl library
+#
+# Input variables:
+#
+# LIBGSASL_INCLUDE_DIR   The libgsasl include directory
+# LIBGSASL_LIBRARY       Path to libgsasl library
+#
+# Result variables:
+#
+# LIBGSASL_FOUND         System has libgsasl
+# LIBGSASL_INCLUDE_DIRS  The libgsasl include directories
+# LIBGSASL_LIBRARIES     The libgsasl library names
+# LIBGSASL_VERSION       Version of libgsasl
+
+if(CURL_USE_PKGCONFIG AND
+   NOT DEFINED LIBGSASL_INCLUDE_DIR AND
+   NOT DEFINED LIBGSASL_LIBRARY)
+  find_package(PkgConfig QUIET)
+  pkg_check_modules(LIBGSASL "libgsasl")
+endif()
+
+if(LIBGSASL_FOUND)
+  set(LIBGSASL_LIBRARIES ${LIBGSASL_LINK_LIBRARIES})
+  message(STATUS "Found Libgsasl (via pkg-config): ${LIBGSASL_INCLUDE_DIRS} (Found version \"${LIBGSASL_VERSION}\")")
+else()
+  find_path(LIBGSASL_INCLUDE_DIR NAMES "gsasl.h")
+  find_library(LIBGSASL_LIBRARY NAMES "gsasl" "libgsasl")
+
+  if(LIBGSASL_INCLUDE_DIR AND EXISTS "${LIBGSASL_INCLUDE_DIR}/gsasl-version.h")
+    set(_version_regex "#[\t ]*define[\t ]+GSASL_VERSION[\t ]+\"([^\"]*)\"")
+    file(STRINGS "${LIBGSASL_INCLUDE_DIR}/gsasl-version.h" _version_str REGEX "${_version_regex}")
+    string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
+    set(LIBGSASL_VERSION "${_version_str}")
+    unset(_version_regex)
+    unset(_version_str)
+  endif()
+
+  include(FindPackageHandleStandardArgs)
+    find_package_handle_standard_args(Libgsasl
+    REQUIRED_VARS
+      LIBGSASL_INCLUDE_DIR
+      LIBGSASL_LIBRARY
+    VERSION_VAR
+      LIBGSASL_VERSION
+  )
+
+  if(LIBGSASL_FOUND)
+    set(LIBGSASL_INCLUDE_DIRS ${LIBGSASL_INCLUDE_DIR})
+    set(LIBGSASL_LIBRARIES    ${LIBGSASL_LIBRARY})
+  endif()
+
+  mark_as_advanced(LIBGSASL_INCLUDE_DIR LIBGSASL_LIBRARY)
+endif()
diff --git a/CMake/FindLibidn2.cmake b/CMake/FindLibidn2.cmake
new file mode 100644 (file)
index 0000000..d7b79cf
--- /dev/null
@@ -0,0 +1,76 @@
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+# Find the libidn2 library
+#
+# Input variables:
+#
+# LIBIDN2_INCLUDE_DIR   The libidn2 include directory
+# LIBIDN2_LIBRARY       Path to libidn2 library
+#
+# Result variables:
+#
+# LIBIDN2_FOUND         System has libidn2
+# LIBIDN2_INCLUDE_DIRS  The libidn2 include directories
+# LIBIDN2_LIBRARIES     The libidn2 library names
+# LIBIDN2_VERSION       Version of libidn2
+
+if(CURL_USE_PKGCONFIG AND
+   NOT DEFINED LIBIDN2_INCLUDE_DIR AND
+   NOT DEFINED LIBIDN2_LIBRARY)
+  find_package(PkgConfig QUIET)
+  pkg_check_modules(LIBIDN2 "libidn2")
+endif()
+
+if(LIBIDN2_FOUND)
+  set(LIBIDN2_LIBRARIES ${LIBIDN2_LINK_LIBRARIES})
+  message(STATUS "Found Libidn2 (via pkg-config): ${LIBIDN2_INCLUDE_DIRS} (Found version \"${LIBIDN2_VERSION}\")")
+else()
+  find_path(LIBIDN2_INCLUDE_DIR NAMES "idn2.h")
+  find_library(LIBIDN2_LIBRARY NAMES "idn2" "libidn2")
+
+  if(LIBIDN2_INCLUDE_DIR AND EXISTS "${LIBIDN2_INCLUDE_DIR}/idn2.h")
+    set(_version_regex "#[\t ]*define[\t ]+IDN2_VERSION[\t ]+\"([^\"]*)\"")
+    file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" _version_str REGEX "${_version_regex}")
+    string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
+    set(LIBIDN2_VERSION "${_version_str}")
+    unset(_version_regex)
+    unset(_version_str)
+  endif()
+
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(Libidn2
+    REQUIRED_VARS
+      LIBIDN2_INCLUDE_DIR
+      LIBIDN2_LIBRARY
+    VERSION_VAR
+      LIBIDN2_VERSION
+  )
+
+  if(LIBIDN2_FOUND)
+    set(LIBIDN2_INCLUDE_DIRS ${LIBIDN2_INCLUDE_DIR})
+    set(LIBIDN2_LIBRARIES    ${LIBIDN2_LIBRARY})
+  endif()
+
+  mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARY)
+endif()
diff --git a/CMake/FindLibssh.cmake b/CMake/FindLibssh.cmake
new file mode 100644 (file)
index 0000000..a9cb0f5
--- /dev/null
@@ -0,0 +1,89 @@
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+# Find the libssh library
+#
+# Input variables:
+#
+# LIBSSH_INCLUDE_DIR   The libssh include directory
+# LIBSSH_LIBRARY       Path to libssh library
+#
+# Result variables:
+#
+# LIBSSH_FOUND         System has libssh
+# LIBSSH_INCLUDE_DIRS  The libssh include directories
+# LIBSSH_LIBRARIES     The libssh library names
+# LIBSSH_VERSION       Version of libssh
+
+if(CURL_USE_PKGCONFIG AND
+   NOT DEFINED LIBSSH_INCLUDE_DIR AND
+   NOT DEFINED LIBSSH_LIBRARY)
+  find_package(PkgConfig QUIET)
+  pkg_check_modules(LIBSSH "libssh")
+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})
+  message(STATUS "Found Libssh (via pkg-config): ${LIBSSH_INCLUDE_DIRS} (Found version \"${LIBSSH_VERSION}\")")
+else()
+  find_path(LIBSSH_INCLUDE_DIR NAMES "libssh/libssh.h")
+  find_library(LIBSSH_LIBRARY NAMES "ssh" "libssh")
+
+  if(LIBSSH_INCLUDE_DIR AND EXISTS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h")
+    set(_version_regex1 "#[\t ]*define[\t ]+LIBSSH_VERSION_MAJOR[\t ]+([0-9]+).*")
+    set(_version_regex2 "#[\t ]*define[\t ]+LIBSSH_VERSION_MINOR[\t ]+([0-9]+).*")
+    set(_version_regex3 "#[\t ]*define[\t ]+LIBSSH_VERSION_MICRO[\t ]+([0-9]+).*")
+    file(STRINGS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h" _version_str1 REGEX "${_version_regex1}")
+    file(STRINGS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h" _version_str2 REGEX "${_version_regex2}")
+    file(STRINGS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h" _version_str3 REGEX "${_version_regex3}")
+    string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
+    string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
+    string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
+    set(LIBSSH_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
+    unset(_version_regex1)
+    unset(_version_regex2)
+    unset(_version_regex3)
+    unset(_version_str1)
+    unset(_version_str2)
+    unset(_version_str3)
+  endif()
+
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(Libssh
+    REQUIRED_VARS
+      LIBSSH_INCLUDE_DIR
+      LIBSSH_LIBRARY
+    VERSION_VAR
+      LIBSSH_VERSION
+  )
+
+  if(LIBSSH_FOUND)
+    set(LIBSSH_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR})
+    set(LIBSSH_LIBRARIES    ${LIBSSH_LIBRARY})
+  endif()
+
+  mark_as_advanced(LIBSSH_INCLUDE_DIR LIBSSH_LIBRARY)
+endif()
diff --git a/CMake/FindLibuv.cmake b/CMake/FindLibuv.cmake
new file mode 100644 (file)
index 0000000..2b01838
--- /dev/null
@@ -0,0 +1,86 @@
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+# Find the libuv library
+#
+# Input variables:
+#
+# LIBUV_INCLUDE_DIR   The libuv include directory
+# LIBUV_LIBRARY       Path to libuv library
+#
+# Result variables:
+#
+# LIBUV_FOUND         System has libuv
+# LIBUV_INCLUDE_DIRS  The libuv include directories
+# LIBUV_LIBRARIES     The libuv library names
+# LIBUV_VERSION       Version of libuv
+
+if(CURL_USE_PKGCONFIG AND
+   NOT DEFINED LIBUV_INCLUDE_DIR AND
+   NOT DEFINED LIBUV_LIBRARY)
+  find_package(PkgConfig QUIET)
+  pkg_check_modules(LIBUV "libuv")
+endif()
+
+if(LIBUV_FOUND)
+  set(LIBUV_LIBRARIES ${LIBUV_LINK_LIBRARIES})
+  message(STATUS "Found Libuv (via pkg-config): ${LIBUV_INCLUDE_DIRS} (Found version \"${LIBUV_VERSION}\")")
+else()
+  find_path(LIBUV_INCLUDE_DIR NAMES "uv.h")
+  find_library(LIBUV_LIBRARY NAMES "uv" "libuv")
+
+  if(LIBUV_INCLUDE_DIR AND EXISTS "${LIBUV_INCLUDE_DIR}/uv/version.h")
+    set(_version_regex1 "#[\t ]*define[\t ]+UV_VERSION_MAJOR[\t ]+([0-9]+).*")
+    set(_version_regex2 "#[\t ]*define[\t ]+UV_VERSION_MINOR[\t ]+([0-9]+).*")
+    set(_version_regex3 "#[\t ]*define[\t ]+UV_VERSION_PATCH[\t ]+([0-9]+).*")
+    file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" _version_str1 REGEX "${_version_regex1}")
+    file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" _version_str2 REGEX "${_version_regex2}")
+    file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" _version_str3 REGEX "${_version_regex3}")
+    string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
+    string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
+    string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
+    set(LIBUV_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
+    unset(_version_regex1)
+    unset(_version_regex2)
+    unset(_version_regex3)
+    unset(_version_str1)
+    unset(_version_str2)
+    unset(_version_str3)
+  endif()
+
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(Libuv
+    REQUIRED_VARS
+      LIBUV_INCLUDE_DIR
+      LIBUV_LIBRARY
+    VERSION_VAR
+      LIBUV_VERSION
+  )
+
+  if(LIBUV_FOUND)
+    set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR})
+    set(LIBUV_LIBRARIES    ${LIBUV_LIBRARY})
+  endif()
+
+  mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
+endif()
index a4b6fb4678a26220e0b66ecffbbcc78adbfa0ce7..a944685b65fbc1081e9aa138b66083fb001e4165 100644 (file)
@@ -991,28 +991,16 @@ if(CURL_DISABLE_LDAP)
   endif()
 endif()
 
-# Check for idn2
+# Check for libidn2
 option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
 if(USE_LIBIDN2)
-  check_library_exists("idn2" "idn2_lookup_ul" "" HAVE_LIBIDN2)
-  if(HAVE_LIBIDN2)
-    set(LIBIDN2_LINK_LIBRARIES "idn2")
-    check_include_file_concat("idn2.h" HAVE_IDN2_H)
-  endif()
-  if(NOT HAVE_LIBIDN2 OR NOT HAVE_IDN2_H)
-    if(CURL_USE_PKGCONFIG)
-      find_package(PkgConfig QUIET)
-      pkg_check_modules(LIBIDN2 "libidn2")
-    endif()
-    if(LIBIDN2_FOUND)
-      include_directories(${LIBIDN2_INCLUDE_DIRS})
-      set(HAVE_LIBIDN2 ON)
-      set(HAVE_IDN2_H ON)
-    endif()
-  endif()
-  if(HAVE_LIBIDN2 AND HAVE_IDN2_H)
-    set(CURL_LIBS "${LIBIDN2_LINK_LIBRARIES};${CURL_LIBS}")
+  find_package(Libidn2)
+  if(LIBIDN2_FOUND)
+    set(CURL_LIBS "${LIBIDN2_LIBRARIES};${CURL_LIBS}")
     set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
+    include_directories(${LIBIDN2_INCLUDE_DIRS})
+    set(HAVE_IDN2_H 1)
+    set(HAVE_LIBIDN2 1)
   endif()
 else()
   set(HAVE_LIBIDN2 OFF)
@@ -1081,21 +1069,15 @@ if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
   find_package(libssh CONFIG QUIET)
   if(libssh_FOUND)
     message(STATUS "Found libssh ${libssh_VERSION}")
-  elseif(CURL_USE_PKGCONFIG)
-    find_package(PkgConfig QUIET)
-    pkg_check_modules(LIBSSH "libssh")
+  else()
+    find_package(Libssh REQUIRED)
     if(LIBSSH_FOUND)
+      list(APPEND CURL_LIBS ${LIBSSH_LIBRARIES})
+      list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh")
       include_directories(${LIBSSH_INCLUDE_DIRS})
+      set(USE_LIBSSH ON)
     endif()
   endif()
-  if(libssh_FOUND OR LIBSSH_FOUND)
-    if(NOT DEFINED LIBSSH_LINK_LIBRARIES)
-      set(LIBSSH_LINK_LIBRARIES "ssh")  # for find_package() with broken pkg-config (e.g. linux-old CI workflow)
-    endif()
-    list(APPEND CURL_LIBS ${LIBSSH_LINK_LIBRARIES})
-    list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh")
-    set(USE_LIBSSH ON)
-  endif()
 endif()
 
 # wolfSSH
@@ -1116,17 +1098,12 @@ if(NOT USE_LIBSSH2 AND NOT USE_LIBSSH AND CURL_USE_WOLFSSH)
   endif()
 endif()
 
-option(CURL_USE_GSASL "Use GSASL implementation" OFF)
+option(CURL_USE_GSASL "Use libgsasl implementation" OFF)
 mark_as_advanced(CURL_USE_GSASL)
 if(CURL_USE_GSASL)
-  if(CURL_USE_PKGCONFIG)
-    find_package(PkgConfig REQUIRED)
-    pkg_check_modules(GSASL REQUIRED "libgsasl")
-  else()
-    message(WARNING "GSASL has been requested but requires a platform with pkg-config support. Skipping.")
-  endif()
-  if(GSASL_FOUND)
-    list(APPEND CURL_LIBS ${GSASL_LINK_LIBRARIES})
+  find_package(Libgsasl REQUIRED)
+  if(LIBGSASL_FOUND)
+    list(APPEND CURL_LIBS ${LIBGSASL_LINK_LIBRARIES})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libgsasl")
     set(USE_GSASL ON)
   endif()
@@ -1201,12 +1178,9 @@ if(CURL_USE_LIBUV)
   if(NOT ENABLE_DEBUG)
     message(FATAL_ERROR "Using libuv without debug support enabled is useless")
   endif()
-  if(CURL_USE_PKGCONFIG)
-    find_package(PkgConfig QUIET)
-    pkg_check_modules(LIBUV "libuv")
-  endif()
+  find_package(Libuv REQUIRED)
   if(LIBUV_FOUND)
-    list(APPEND CURL_LIBS ${LIBUV_LINK_LIBRARIES})
+    list(APPEND CURL_LIBS ${LIBUV_LIBRARIES})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libuv")
     include_directories(${LIBUV_INCLUDE_DIRS})
     set(USE_LIBUV ON)
index a9db8c0f98cd5abbc233fe81bd058d78c2825532..e6ebb99a57d1e0d5e727b605cb457aa9ca6a684c 100644 (file)
@@ -36,10 +36,15 @@ CMAKE_DIST =                                    \
  CMake/FindBrotli.cmake                         \
  CMake/FindCares.cmake                          \
  CMake/FindGSS.cmake                            \
+ CMake/FindLibgsasl.cmake                       \
+ CMake/FindLibidn2.cmake                        \
  CMake/FindLibpsl.cmake                         \
+ CMake/FindLibssh.cmake                         \
  CMake/FindLibssh2.cmake                        \
+ CMake/FindLibuv.cmake                          \
  CMake/FindMbedTLS.cmake                        \
  CMake/FindMSH3.cmake                           \
+ CMake/FindMbedTLS.cmake                        \
  CMake/FindNGHTTP2.cmake                        \
  CMake/FindNGHTTP3.cmake                        \
  CMake/FindNGTCP2.cmake                         \