cmake: detect libssh via pkg-config

Also:
- fix broken libssh `pkg-config` behaviour on old Linux.
  (when found, `LIBSSH_LINK_LIBRARIES` remains undefined.)

- delete manual libssh config from Old Linux CI job,
  it's no longer necessary.

Closes #14199
This commit is contained in:
Viktor Szakats 2024-07-16 12:48:13 +02:00
parent efce544418
commit e8acb2e55a
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
2 changed files with 14 additions and 5 deletions

View File

@ -89,8 +89,7 @@ jobs:
run: |
mkdir bld-cares
cd bld-cares
cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON -DENABLE_ARES=ON -DCURL_ZSTD=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF \
-DUSE_LIBSSH=ON '-DCMAKE_C_FLAGS=-I/usr/include -L/usr/lib -lssh'
cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON -DENABLE_ARES=ON -DCURL_ZSTD=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=ON
- name: 'build'
run: |

View File

@ -994,11 +994,21 @@ endif()
option(CURL_USE_LIBSSH "Use libssh" OFF)
mark_as_advanced(CURL_USE_LIBSSH)
if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
find_package(libssh CONFIG)
find_package(libssh CONFIG QUIET)
if(libssh_FOUND)
message(STATUS "Found libssh ${libssh_VERSION}")
# Use imported target for include and library paths.
list(APPEND CURL_LIBS ssh)
else()
find_package(PkgConfig QUIET)
pkg_check_modules(LIBSSH "libssh")
if(LIBSSH_FOUND)
include_directories(${LIBSSH_INCLUDE_DIRS})
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()