11import os
22
33from conan import ConanFile
4- from conan .errors import ConanInvalidConfiguration
5- from conan .tools .build import cross_building
6- from conan .tools .env import VirtualBuildEnv , VirtualRunEnv
7- from conan .tools .files import apply_conandata_patches , chdir , copy , export_conandata_patches , get , rmdir
8- from conan .tools .gnu import Autotools , AutotoolsToolchain , AutotoolsDeps
4+ from conan .tools .cmake import CMakeToolchain , CMakeDeps , CMake
5+ from conan .tools .files import copy , get
96from conan .tools .layout import basic_layout
10- from conan .tools .microsoft import is_msvc , unix_path
7+ from conan .tools .scm import Version
118
129required_conan_version = ">=1.53.0"
1310
@@ -38,7 +35,7 @@ def _settings_build(self):
3835 return getattr (self , "settings_build" , self .settings )
3936
4037 def export_sources (self ):
41- export_conandata_patches (self )
38+ copy (self , "CMakeLists.txt" , src = self . recipe_folder , dst = self . export_sources_folder )
4239
4340 def config_options (self ):
4441 if self .settings .os == "Windows" :
@@ -57,78 +54,39 @@ def requirements(self):
5754 if self .options .with_openssl :
5855 self .requires ("openssl/1.1.1w" )
5956
60- def validate (self ):
61- if is_msvc (self ):
62- raise ConanInvalidConfiguration ("Visual Studio is not supported" )
63-
64- def build_requirements (self ):
65- if self ._settings_build .os == "Windows" :
66- self .win_bash = True
67- if not self .conf .get ("tools.microsoft.bash:path" , check_type = str ):
68- self .tool_requires ("msys2/cci.latest" )
69-
7057 def source (self ):
7158 get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
7259
60+ @property
61+ def _xversion (self ):
62+ # https://github.com/rhash/RHash/blob/v1.4.4/configure#L339
63+ version = Version (self .version )
64+ return f"0x{ version .major .value :02x} { version .minor .value :02x} { version .patch .value :02x} { 0 :02x} "
65+
7366 def generate (self ):
74- env = VirtualBuildEnv (self )
75- env .generate ()
76-
77- if not cross_building (self ):
78- env = VirtualRunEnv (self )
79- env .generate (scope = "build" )
80-
81- tc = AutotoolsToolchain (self )
82- if self .settings .compiler in ("apple-clang" ,):
83- if self .settings .arch == "armv7" :
84- tc .build_type_link_flags .append ("-arch armv7" )
85- elif self .settings .arch == "armv8" :
86- tc .build_type_link_flags .append ("-arch arm64" )
87- tc .configure_args = [
88- # librhash's configure script does not understand `--enable-opt1=yes`
89- "--{}-openssl" .format ("enable" if self .options .with_openssl else "disable" ),
90- "--disable-gettext" ,
91- ]
92- if self .options .shared :
93- tc .configure_args += ["--enable-lib-shared" , "--disable-lib-static" ]
94- else :
95- tc .configure_args += ["--disable-lib-shared" , "--enable-lib-static" ]
96- tc .make_args += [
97- f"INCDIR={ unix_path (self , os .path .join (self .package_folder , 'include' ))} " ,
98- f"BINDIR={ unix_path (self , os .path .join (self .package_folder , 'bin' ))} " ,
99- f"LIBDIR={ unix_path (self , os .path .join (self .package_folder , 'lib' ))} " ,
100- f"SO_DIR={ unix_path (self , os .path .join (self .package_folder , 'lib' ))} " ,
101- ]
67+ tc = CMakeToolchain (self )
68+ tc .cache_variables ["USE_OPENSSL" ] = self .options .with_openssl
69+ tc .preprocessor_definitions ["RHASH_XVERSION" ] = self ._xversion
10270 tc .generate ()
103-
104- deps = AutotoolsDeps (self )
71+ deps = CMakeDeps (self )
10572 deps .generate ()
10673
10774 def build (self ):
108- apply_conandata_patches (self )
109- with chdir (self , self .source_folder ):
110- autotools = Autotools (self )
111- autotools .configure ()
112- autotools .make ()
75+ cmake = CMake (self )
76+ cmake .configure (build_script_folder = self .source_path .parent )
77+ cmake .build ()
11378
11479 def package (self ):
11580 copy (self , "COPYING" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
116- with chdir (self , self .source_folder ):
117- autotools = Autotools (self )
118- autotools .install ()
119- autotools .make (target = "install-lib-headers" )
120- with chdir (self , "librhash" ):
121- if self .options .shared :
122- autotools .make (target = "install-so-link" )
123- for path in self .package_path .iterdir ():
124- if path .is_dir () and path .name not in ["include" , "lib" , "licenses" ]:
125- rmdir (self , path )
81+ cmake = CMake (self )
82+ cmake .install ()
12683
12784 def package_info (self ):
12885 self .cpp_info .set_property ("cmake_file_name" , "LibRHash" )
12986 self .cpp_info .set_property ("cmake_target_name" , "LibRHash::LibRHash" )
13087 self .cpp_info .set_property ("pkg_config_name" , "librhash" )
13188 self .cpp_info .libs = ["rhash" ]
89+ self .cpp_info .defines .append (f"RHASH_XVERSION={ self ._xversion } " )
13290
13391 # TODO: to remove in conan v2 once cmake_find_package_* generators removed
13492 self .cpp_info .names ["cmake_find_package" ] = "LibRHash"
0 commit comments