Skip to content

Commit f665585

Browse files
dheaterjcar87
andauthored
(#16504) Update libssh2 for Conan 2.0
* Update libssh2 to Conan 2.x and add support for libssh2 version 1.11.0 * Restore cmake_find_package name to Libssh2 * Revert another attempt to set the cmake_find_package name to Libssh2 (uppercase) to match previous versions of this recipe. I must be doing something dumb, but I cannot reproduce the CI failure on my local machine - I keep getting a failed find_package to taget "Libssh2::libssh2" This reverts commit 401ba0e. * Restore cmake_find_package name to Libssh2 * Revert another attempt to set the cmake_find_package name to Libssh2 (uppercase) to match previous versions of this recipe. I must be doing something dumb, but I cannot reproduce the CI failure on my local machine - I keep getting a failed find_package to taget "Libssh2::libssh2" This reverts commit fbc68d7. * libssh2: cleanup and fixes * remove empty line --------- Co-authored-by: Luis Caro Campos <[email protected]>
1 parent 7797c43 commit f665585

File tree

6 files changed

+75
-83
lines changed

6 files changed

+75
-83
lines changed

recipes/libssh2/all/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

recipes/libssh2/all/conandata.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
sources:
2+
"1.11.0":
3+
sha256: 3736161e41e2693324deb38c26cfdc3efe6209d634ba4258db1cecff6a5ad461
4+
url: https://github.com/libssh2/libssh2/releases/download/libssh2-1.11.0/libssh2-1.11.0.tar.gz
25
"1.10.0":
36
sha256: 2d64e90f3ded394b91d3a2e774ca203a4179f69aebee03003e5a6fa621e41d51
47
url: https://github.com/libssh2/libssh2/releases/download/libssh2-1.10.0/libssh2-1.10.0.tar.gz
@@ -11,16 +14,3 @@ sources:
1114
"1.8.0":
1215
sha256: 39f34e2f6835f4b992cafe8625073a88e5a28ba78f83e8099610a7b3af4676d4
1316
url: https://github.com/libssh2/libssh2/releases/download/libssh2-1.8.0/libssh2-1.8.0.tar.gz
14-
patches:
15-
"1.10.0":
16-
- patch_file: "patches/0001-threads.patch"
17-
base_path: "source_subfolder"
18-
"1.9.0":
19-
- patch_file: "patches/0001-threads.patch"
20-
base_path: "source_subfolder"
21-
"1.8.2":
22-
- patch_file: "patches/0001-threads.patch"
23-
base_path: "source_subfolder"
24-
"1.8.0":
25-
- patch_file: "patches/0001-threads.patch"
26-
base_path: "source_subfolder"

recipes/libssh2/all/conanfile.py

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from conans import ConanFile, CMake, tools
2-
import functools
1+
from conan import ConanFile
2+
from conan.tools.apple import fix_apple_shared_install_name
3+
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
4+
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, collect_libs
5+
from conan.tools.microsoft import is_msvc
36
import os
47

5-
required_conan_version = ">=1.43.0"
8+
required_conan_version = ">=1.53.0"
69

710

811
class Libssh2Conan(ConanFile):
@@ -12,7 +15,7 @@ class Libssh2Conan(ConanFile):
1215
homepage = "https://libssh2.org"
1316
topics = ("libssh", "ssh", "shell", "ssh2", "connection")
1417
license = "BSD-3-Clause"
15-
18+
package_type = "library"
1619
settings = "os", "arch", "compiler", "build_type"
1720
options = {
1821
"shared": [True, False],
@@ -33,85 +36,83 @@ class Libssh2Conan(ConanFile):
3336
"enable_debug_logging": False,
3437
}
3538

36-
generators = "cmake", "cmake_find_package"
39+
def export_sources(self):
40+
export_conandata_patches(self)
3741

38-
@property
39-
def _source_subfolder(self):
40-
return "source_subfolder"
42+
def layout(self):
43+
cmake_layout(self, src_folder="src")
4144

42-
def export_sources(self):
43-
self.copy("CMakeLists.txt")
44-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
45-
self.copy(patch["patch_file"])
45+
def generate(self):
46+
tc = CMakeToolchain(self)
47+
tc.cache_variables["ENABLE_ZLIB_COMPRESSION"] = self.options.with_zlib
48+
tc.cache_variables["ENABLE_CRYPT_NONE"] = self.options.enable_crypt_none
49+
tc.cache_variables["ENABLE_MAC_NONE"] = self.options.enable_mac_none
50+
tc.cache_variables["ENABLE_DEBUG_LOGGING"] = self.options.enable_debug_logging
51+
if self.options.crypto_backend == "openssl":
52+
tc.cache_variables["CRYPTO_BACKEND"] = "OpenSSL"
53+
tc.cache_variables["OPENSSL_ROOT_DIR"] = self.dependencies["openssl"].package_folder.replace("\\", "/")
54+
elif self.options.crypto_backend == "mbedtls":
55+
tc.cache_variables["CRYPTO_BACKEND"] = "mbedTLS"
56+
tc.cache_variables["BUILD_EXAMPLES"] = False
57+
tc.cache_variables['BUILD_TESTING'] = not self.conf.get("tools.build:skip_test", default=True, check_type=bool)
58+
tc.cache_variables["BUILD_STATIC_LIBS"] = not self.options.shared
59+
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
60+
# To install relocatable shared lib on Macos by default
61+
tc.variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
62+
# Workaround until github.com/conan-io/conan/pull/12600 is merged
63+
if is_msvc(self):
64+
tc.cache_variables["CMAKE_TRY_COMPILE_CONFIGURATION"] = str(self.settings.build_type)
65+
tc.generate()
66+
67+
deps = CMakeDeps(self)
68+
deps.generate()
4669

4770
def config_options(self):
4871
if self.settings.os == "Windows":
4972
del self.options.fPIC
5073

5174
def configure(self):
5275
if self.options.shared:
53-
del self.options.fPIC
54-
del self.settings.compiler.libcxx
55-
del self.settings.compiler.cppstd
76+
self.options.rm_safe("fPIC")
77+
# This is a pure C library
78+
self.settings.rm_safe("compiler.libcxx")
79+
self.settings.rm_safe("compiler.cppstd")
5680

5781
def requirements(self):
5882
if self.options.with_zlib:
59-
self.requires("zlib/1.2.12")
83+
self.requires("zlib/1.2.13")
6084
if self.options.crypto_backend == "openssl":
61-
self.requires("openssl/1.1.1q")
85+
self.requires("openssl/1.1.1t")
86+
# Version 3.x not currently working
87+
# self.requires("openssl/[>=1.1 <4]")
6288
elif self.options.crypto_backend == "mbedtls":
6389
# libssh2/<=1.10.0 doesn't support mbedtls/3.x.x
6490
self.requires("mbedtls/2.25.0")
6591

6692
def source(self):
67-
tools.get(**self.conan_data["sources"][self.version],
68-
destination=self._source_subfolder, strip_root=True)
93+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
94+
apply_conandata_patches(self)
6995

70-
def _patch_sources(self):
71-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
72-
tools.patch(**patch)
73-
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
74-
"set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)",
75-
"list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)")
76-
77-
@functools.lru_cache(1)
78-
def _configure_cmake(self):
96+
def build(self):
7997
cmake = CMake(self)
80-
cmake.definitions["ENABLE_ZLIB_COMPRESSION"] = self.options.with_zlib
81-
cmake.definitions["ENABLE_CRYPT_NONE"] = self.options.enable_crypt_none
82-
cmake.definitions["ENABLE_MAC_NONE"] = self.options.enable_mac_none
83-
cmake.definitions["ENABLE_DEBUG_LOGGING"] = self.options.enable_debug_logging
84-
if self.options.crypto_backend == "openssl":
85-
cmake.definitions["CRYPTO_BACKEND"] = "OpenSSL"
86-
cmake.definitions["OPENSSL_ROOT_DIR"] = self.deps_cpp_info["openssl"].rootpath
87-
elif self.options.crypto_backend == "mbedtls":
88-
cmake.definitions["CRYPTO_BACKEND"] = "mbedTLS"
89-
cmake.definitions["BUILD_EXAMPLES"] = False
90-
cmake.definitions["BUILD_TESTING"] = False
91-
# To install relocatable shared lib on Macos by default
92-
cmake.definitions["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
9398
cmake.configure()
94-
return cmake
95-
96-
def build(self):
97-
self._patch_sources()
98-
cmake = self._configure_cmake()
9999
cmake.build()
100100

101101
def package(self):
102-
cmake = self._configure_cmake()
102+
cmake = CMake(self)
103103
cmake.install()
104-
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
105-
tools.rmdir(os.path.join(self.package_folder, "share"))
106-
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
107-
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
104+
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
105+
rmdir(self, os.path.join(self.package_folder, "share")) # only docs and manpages
106+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
107+
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
108+
fix_apple_shared_install_name(self)
108109

109110
def package_info(self):
110111
self.cpp_info.set_property("cmake_file_name", "Libssh2")
111112
self.cpp_info.set_property("cmake_target_name", "Libssh2::libssh2")
112113
self.cpp_info.set_property("pkg_config_name", "libssh2")
113114
# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
114-
self.cpp_info.components["_libssh2"].libs = tools.collect_libs(self)
115+
self.cpp_info.components["_libssh2"].libs = collect_libs(self)
115116
if self.settings.os == "Windows":
116117
self.cpp_info.components["_libssh2"].system_libs.append("ws2_32")
117118
elif self.settings.os in ["Linux", "FreeBSD"]:
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
cmake_minimum_required(VERSION 3.1)
2-
project(test_package C)
3-
4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES C)
63

74
find_package(Libssh2 REQUIRED CONFIG)
85

96
add_executable(${PROJECT_NAME} test_package.c)
10-
target_link_libraries(${PROJECT_NAME} Libssh2::libssh2)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE Libssh2::libssh2)
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMake, cmake_layout
3+
from conan.tools.build import can_run
24
import os
35

46

57
class TestPackageConan(ConanFile):
68
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake", "cmake_find_package_multi"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def requirements(self):
13+
self.requires(self.tested_reference_str)
814

915
def build(self):
1016
cmake = CMake(self)
1117
cmake.configure()
1218
cmake.build()
1319

20+
def layout(self):
21+
cmake_layout(self)
22+
1423
def test(self):
15-
if not tools.cross_building(self):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")

recipes/libssh2/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
versions:
2+
"1.11.0":
3+
folder: all
24
"1.10.0":
35
folder: all
46
"1.9.0":

0 commit comments

Comments
 (0)