aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/libssh2
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/libssh2
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/ports/libssh2')
-rw-r--r--vcpkg/ports/libssh2/pkgconfig.diff103
-rw-r--r--vcpkg/ports/libssh2/portfile.cmake61
-rw-r--r--vcpkg/ports/libssh2/usage9
-rw-r--r--vcpkg/ports/libssh2/vcpkg.json44
4 files changed, 217 insertions, 0 deletions
diff --git a/vcpkg/ports/libssh2/pkgconfig.diff b/vcpkg/ports/libssh2/pkgconfig.diff
new file mode 100644
index 0000000..cf31593
--- /dev/null
+++ b/vcpkg/ports/libssh2/pkgconfig.diff
@@ -0,0 +1,103 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 6b51ac6..d8d5701 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -310,6 +310,8 @@ if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
+ list(APPEND LIBSSH2_LIBS OpenSSL::Crypto)
+ list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "libcrypto")
+
++ endif()
++ if(0) # covered by OpenSSL wrapper
+ if(WIN32)
+ # Statically linking to OpenSSL requires crypt32 for some Windows APIs.
+ # This should really be handled by FindOpenSSL.cmake.
+diff --git a/cmake/libssh2-config.cmake.in b/cmake/libssh2-config.cmake.in
+index edc86d7..905e4a2 100644
+--- a/cmake/libssh2-config.cmake.in
++++ b/cmake/libssh2-config.cmake.in
+@@ -14,7 +14,7 @@ elseif("@CRYPTO_BACKEND@" STREQUAL "mbedTLS")
+ find_dependency(MbedTLS)
+ endif()
+
+-if(@ZLIB_FOUND@)
++if(@ENABLE_ZLIB_COMPRESSION@)
+ find_dependency(ZLIB)
+ endif()
+
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 512c64e..c50ce6a 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -63,7 +63,8 @@ if(ENABLE_ZLIB_COMPRESSION)
+ find_package(ZLIB REQUIRED)
+
+ list(APPEND libssh2_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
+- list(APPEND LIBSSH2_LIBS ${ZLIB_LIBRARIES})
++ # Avoid multi-config string. Same pattern as in curl.
++ list(APPEND LIBSSH2_LIBS ZLIB::ZLIB)
+ list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "zlib")
+ if(ZLIB_FOUND)
+ list(APPEND _libssh2_definitions "LIBSSH2_HAVE_ZLIB")
+@@ -229,6 +230,7 @@ foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
+ endforeach()
+
+ foreach(_libdir IN LISTS LIBSSH2_LIBDIRS)
++ cmake_path(SET _libdir NORMALIZE "${_libdir}")
+ list(FIND _sys_libdirs "${_libdir}" _libdir_index)
+ if(_libdir_index LESS 0)
+ list(APPEND _ldflags "-L${_libdir}")
+@@ -240,7 +242,13 @@ if(NOT MINGW AND NOT UNIX)
+ set(_implicit_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES})
+ endif()
+
+-foreach(_lib IN LISTS _implicit_libs LIBSSH2_LIBS)
++find_package(PkgConfig)
++pkg_check_modules(LIBSSH2_PC_REQUIRED REQUIRED ${LIBSSH2_PC_REQUIRES_PRIVATE})
++# Libs which are resolved by pkg-config via Requires (LIBSSH2_PC_REQUIRES_PRIVATE)
++# don't need to be written to `libssh2.pc` (LIBSSH2_PC_LIBS_PRIVATE)
++list(REMOVE_ITEM LIBSSH2_LIBS ZLIB::ZLIB OpenSSL::Crypto)
++
++foreach(_lib IN LISTS LIBSSH2_LIBS)
+ if(TARGET "${_lib}")
+ set(_libname "${_lib}")
+ get_target_property(_imported "${_libname}" IMPORTED)
+@@ -255,6 +263,9 @@ foreach(_lib IN LISTS _implicit_libs LIBSSH2_LIBS)
+ continue()
+ endif()
+ endif()
++ if(_lib IN_LIST LIBSSH2_PC_REQUIRED_LINK_LIBRARIES)
++ continue()
++ endif()
+ if(_lib MATCHES "^-")
+ list(APPEND _ldflags "${_lib}")
+ elseif(_lib MATCHES ".*/.*")
+@@ -263,12 +274,19 @@ foreach(_lib IN LISTS _implicit_libs LIBSSH2_LIBS)
+ get_filename_component(_libdir ${_lib} DIRECTORY)
+ get_filename_component(_libname ${_lib} NAME_WE)
+ if(_libname MATCHES "^lib")
++ cmake_path(SET _libdir NORMALIZE "${_libdir}")
+ list(FIND _sys_libdirs "${_libdir}" _libdir_index)
+ if(_libdir_index LESS 0)
+ list(APPEND _ldflags "-L${_libdir}")
+ endif()
+ string(REGEX REPLACE "^lib" "" _libname "${_libname}")
+ list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-l${_libname}")
++ if(TARGET "${LIB_STATIC}" AND _libdir IN_LIST CMAKE_C_IMPLICIT_LINK_DIRECTORIES)
++ # Avoid absolute path to system lib in exported CMake config
++ get_target_property(static_link_libs "${LIB_STATIC}" INTERFACE_LINK_LIBRARIES)
++ string(REPLACE "${_lib}" "${_libname}" static_link_libs "${static_link_libs}")
++ set_target_properties("${LIB_STATIC}" PROPERTIES INTERFACE_LINK_LIBRARIES "${static_link_libs}")
++ endif()
+ else()
+ list(APPEND LIBSSH2_PC_LIBS_PRIVATE "${_lib}")
+ endif()
+@@ -296,8 +314,7 @@ if(BUILD_SHARED_LIBS)
+ set(LIBSSH2_PC_REQUIRES "")
+ set(LIBSSH2_PC_LIBS "")
+ else()
+- set(LIBSSH2_PC_REQUIRES "${LIBSSH2_PC_REQUIRES_PRIVATE}")
+- set(LIBSSH2_PC_LIBS "${LIBSSH2_PC_LIBS_PRIVATE}")
++ # (processing by vcpkg_fixup_pkgconfig)
+ endif()
+
+ set(prefix "${CMAKE_INSTALL_PREFIX}")
diff --git a/vcpkg/ports/libssh2/portfile.cmake b/vcpkg/ports/libssh2/portfile.cmake
new file mode 100644
index 0000000..2f0bea4
--- /dev/null
+++ b/vcpkg/ports/libssh2/portfile.cmake
@@ -0,0 +1,61 @@
+vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO libssh2/libssh2
+ REF "libssh2-${VERSION}"
+ SHA512 616efcd7f5c1fb1046104ebce70549e4756e2a55150efa2df5bb7123051d3bf336023cedcbfe932cd7c690a0b4d1f1a93c760ea39f1dba50c2b06d0945dca958
+ HEAD_REF master
+ PATCHES
+ pkgconfig.diff
+)
+
+vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
+ FEATURES
+ zlib ENABLE_ZLIB_COMPRESSION
+)
+if("openssl" IN_LIST FEATURES)
+ list(APPEND FEATURE_OPTIONS "-DCRYPTO_BACKEND=OpenSSL")
+elseif(VCPKG_TARGET_IS_WINDOWS)
+ list(APPEND FEATURE_OPTIONS "-DCRYPTO_BACKEND=WinCNG")
+else()
+ message(FATAL_ERROR "Port ${PORT} only supports OpenSSL and WinCNG crypto backends.")
+endif()
+if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
+ list(APPEND FEATURE_OPTIONS "-DBUILD_STATIC_LIBS:BOOL=OFF")
+endif()
+
+vcpkg_find_acquire_program(PKGCONFIG)
+
+vcpkg_cmake_configure(
+ SOURCE_PATH "${SOURCE_PATH}"
+ OPTIONS
+ "-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
+ -DBUILD_EXAMPLES=OFF
+ -DBUILD_TESTING=OFF
+ -DENABLE_DEBUG_LOGGING=OFF
+ ${FEATURE_OPTIONS}
+)
+
+vcpkg_cmake_install()
+vcpkg_copy_pdbs()
+vcpkg_fixup_pkgconfig()
+vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/libssh2)
+
+if (VCPKG_TARGET_IS_WINDOWS)
+ if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
+ vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/libssh2.h" "defined(_WINDLL)" "1")
+ endif()
+ if(VCPKG_TARGET_STATIC_LIBRARY_PREFIX STREQUAL "")
+ vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libssh2.pc" " -lssh2" " -llibssh2")
+ if(NOT VCPKG_BUILD_TYPE)
+ vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libssh2.pc" " -lssh2" " -llibssh2")
+ endif()
+ endif()
+endif()
+
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/doc")
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/man")
+
+file(INSTALL "${CURRENT_PORT_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
+vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")
diff --git a/vcpkg/ports/libssh2/usage b/vcpkg/ports/libssh2/usage
new file mode 100644
index 0000000..36fc70f
--- /dev/null
+++ b/vcpkg/ports/libssh2/usage
@@ -0,0 +1,9 @@
+libssh2 provides CMake targets:
+
+ find_package(libssh2 CONFIG REQUIRED)
+ target_link_libraries(main PRIVATE libssh2::libssh2)
+
+libssh2 provides pkg-config modules:
+
+ # Library for SSH-based communication
+ libssh2
diff --git a/vcpkg/ports/libssh2/vcpkg.json b/vcpkg/ports/libssh2/vcpkg.json
new file mode 100644
index 0000000..31e616a
--- /dev/null
+++ b/vcpkg/ports/libssh2/vcpkg.json
@@ -0,0 +1,44 @@
+{
+ "name": "libssh2",
+ "version": "1.11.1",
+ "port-version": 1,
+ "description": "libssh2 is a client-side C library implementing the SSH2 protocol.",
+ "homepage": "https://www.libssh2.org",
+ "license": "BSD-3-Clause",
+ "dependencies": [
+ {
+ "name": "libssh2",
+ "default-features": false,
+ "features": [
+ "openssl"
+ ],
+ "platform": "!windows"
+ },
+ {
+ "name": "vcpkg-cmake",
+ "host": true
+ },
+ {
+ "name": "vcpkg-cmake-config",
+ "host": true
+ }
+ ],
+ "default-features": [
+ "openssl",
+ "zlib"
+ ],
+ "features": {
+ "openssl": {
+ "description": "Use the openssl crypto backend",
+ "dependencies": [
+ "openssl"
+ ]
+ },
+ "zlib": {
+ "description": "Use compression via zlib",
+ "dependencies": [
+ "zlib"
+ ]
+ }
+ }
+}