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
3
6
import os
4
7
5
- required_conan_version = ">=1.43 .0"
8
+ required_conan_version = ">=1.53 .0"
6
9
7
10
8
11
class Libssh2Conan (ConanFile ):
@@ -12,7 +15,7 @@ class Libssh2Conan(ConanFile):
12
15
homepage = "https://libssh2.org"
13
16
topics = ("libssh" , "ssh" , "shell" , "ssh2" , "connection" )
14
17
license = "BSD-3-Clause"
15
-
18
+ package_type = "library"
16
19
settings = "os" , "arch" , "compiler" , "build_type"
17
20
options = {
18
21
"shared" : [True , False ],
@@ -33,85 +36,83 @@ class Libssh2Conan(ConanFile):
33
36
"enable_debug_logging" : False ,
34
37
}
35
38
36
- generators = "cmake" , "cmake_find_package"
39
+ def export_sources (self ):
40
+ export_conandata_patches (self )
37
41
38
- @property
39
- def _source_subfolder (self ):
40
- return "source_subfolder"
42
+ def layout (self ):
43
+ cmake_layout (self , src_folder = "src" )
41
44
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 ()
46
69
47
70
def config_options (self ):
48
71
if self .settings .os == "Windows" :
49
72
del self .options .fPIC
50
73
51
74
def configure (self ):
52
75
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" )
56
80
57
81
def requirements (self ):
58
82
if self .options .with_zlib :
59
- self .requires ("zlib/1.2.12 " )
83
+ self .requires ("zlib/1.2.13 " )
60
84
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]")
62
88
elif self .options .crypto_backend == "mbedtls" :
63
89
# libssh2/<=1.10.0 doesn't support mbedtls/3.x.x
64
90
self .requires ("mbedtls/2.25.0" )
65
91
66
92
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 )
69
95
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 ):
79
97
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"
93
98
cmake .configure ()
94
- return cmake
95
-
96
- def build (self ):
97
- self ._patch_sources ()
98
- cmake = self ._configure_cmake ()
99
99
cmake .build ()
100
100
101
101
def package (self ):
102
- cmake = self . _configure_cmake ( )
102
+ cmake = CMake ( self )
103
103
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 )
108
109
109
110
def package_info (self ):
110
111
self .cpp_info .set_property ("cmake_file_name" , "Libssh2" )
111
112
self .cpp_info .set_property ("cmake_target_name" , "Libssh2::libssh2" )
112
113
self .cpp_info .set_property ("pkg_config_name" , "libssh2" )
113
114
# 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 )
115
116
if self .settings .os == "Windows" :
116
117
self .cpp_info .components ["_libssh2" ].system_libs .append ("ws2_32" )
117
118
elif self .settings .os in ["Linux" , "FreeBSD" ]:
0 commit comments