1- from conans import AutoToolsBuildEnvironment , ConanFile , tools
2- from conans .errors import ConanInvalidConfiguration
31import os
42
5- required_conan_version = ">=1.33.0"
3+ from conan import ConanFile
4+ from conan .tools .cmake import CMakeToolchain , CMakeDeps , CMake
5+ from conan .tools .files import copy , get
6+ from conan .tools .layout import basic_layout
7+ from conan .tools .scm import Version
8+
9+ required_conan_version = ">=1.53.0"
610
711
812class LibRHashConan (ConanFile ):
913 name = "librhash"
1014 description = "Great utility for computing hash sums"
11- topics = ( "rhash" , "hash" , "checksum" )
15+ license = "MIT"
1216 url = "https://github.com/conan-io/conan-center-index"
1317 homepage = "http://rhash.sourceforge.net/"
14- license = "MIT"
18+ topics = ("rhash" , "hash" , "checksum" )
19+
20+ package_type = "library"
1521 settings = "os" , "arch" , "compiler" , "build_type"
1622 options = {
1723 "shared" : [True , False ],
@@ -24,98 +30,64 @@ class LibRHashConan(ConanFile):
2430 "with_openssl" : True ,
2531 }
2632
27- exports_sources = "patches/*"
28- _autotools = None
29-
30- @property
31- def _source_subfolder (self ):
32- return "source_subfolder"
33-
3433 @property
3534 def _settings_build (self ):
3635 return getattr (self , "settings_build" , self .settings )
3736
37+ def export_sources (self ):
38+ copy (self , "CMakeLists.txt" , self .recipe_folder , os .path .join (self .export_sources_folder , "src" , "librhash" ))
39+
3840 def config_options (self ):
3941 if self .settings .os == "Windows" :
4042 del self .options .fPIC
4143
4244 def configure (self ):
4345 if self .options .shared :
44- del self .options .fPIC
45- del self .settings .compiler .cppstd
46- del self .settings .compiler .libcxx
46+ self .options .rm_safe ("fPIC" )
47+ self .settings .rm_safe ("compiler.cppstd" )
48+ self .settings .rm_safe ("compiler.libcxx" )
49+
50+ def layout (self ):
51+ basic_layout (self , src_folder = "src" )
4752
4853 def requirements (self ):
4954 if self .options .with_openssl :
50- self .requires ("openssl/1.1.1q" )
51-
52- def build_requirements (self ):
53- if self ._settings_build .os == "Windows" and not tools .get_env ("CONAN_BASH_PATH" ):
54- self .build_requires ("msys2/cci.latest" )
55-
56- def validate (self ):
57- if self .settings .compiler == "Visual Studio" :
58- raise ConanInvalidConfiguration ("Visual Studio is not supported" )
55+ self .requires ("openssl/[>=1.1 <4]" )
5956
6057 def source (self ):
61- tools .get (** self .conan_data ["sources" ][self .version ],
62- destination = self ._source_subfolder , strip_root = True )
63-
64- def _configure_autotools (self ):
65- if self ._autotools :
66- return self ._autotools
67- self ._autotools = AutoToolsBuildEnvironment (self , win_bash = tools .os_info .is_windows )
68- if self .settings .compiler in ("apple-clang" , ):
69- if self .settings .arch in ("armv7" , ):
70- self ._autotools .link_flags .append ("-arch armv7" )
71- elif self .settings .arch in ("armv8" , ):
72- self ._autotools .link_flags .append ("-arch arm64" )
73- vars = self ._autotools .vars
74- conf_args = [
75- # librhash's configure script does not understand `--enable-opt1=yes`
76- "--enable-openssl" if self .options .with_openssl else "--disable-openssl" ,
77- "--disable-gettext" ,
78- # librhash's configure script is custom and does not understand "--bindir=${prefix}/bin" arguments
79- "--prefix={}" .format (tools .unix_path (self .package_folder )),
80- "--bindir={}" .format (tools .unix_path (os .path .join (self .package_folder , "bin" ))),
81- "--libdir={}" .format (tools .unix_path (os .path .join (self .package_folder , "lib" ))),
82- # the configure script does not use CPPFLAGS, so add it to CFLAGS/CXXFLAGS
83- "--extra-cflags={}" .format ("{} {}" .format (vars ["CFLAGS" ], vars ["CPPFLAGS" ])),
84- "--extra-ldflags={}" .format (vars ["LDFLAGS" ]),
85- ]
86- if self .options .shared :
87- conf_args .extend (["--enable-lib-shared" , "--disable-lib-static" ])
88- else :
89- conf_args .extend (["--disable-lib-shared" , "--enable-lib-static" ])
58+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
9059
91- with tools .environment_append ({
92- "BUILD_TARGET" : tools .get_gnu_triplet (str (self .settings .os ), str (self .settings .arch ), str (self .settings .compiler )),
93- }):
94- self ._autotools .configure (args = conf_args , use_default_install_dirs = False , build = False , host = False )
95- return self ._autotools
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+
66+ def generate (self ):
67+ tc = CMakeToolchain (self )
68+ tc .cache_variables ["USE_OPENSSL" ] = self .options .with_openssl
69+ tc .preprocessor_definitions ["RHASH_XVERSION" ] = self ._xversion
70+ tc .generate ()
71+ deps = CMakeDeps (self )
72+ deps .generate ()
9673
9774 def build (self ):
98- for patch in self .conan_data .get ("patches" , {}).get (self .version , []):
99- tools .patch (** patch )
100- with tools .chdir (self ._source_subfolder ):
101- autotools = self ._configure_autotools ()
102- autotools .make ()
75+ cmake = CMake (self )
76+ cmake .configure (build_script_folder = os .path .join (self .source_folder , "librhash" ))
77+ cmake .build ()
10378
10479 def package (self ):
105- self .copy ("COPYING" , src = self ._source_subfolder , dst = "licenses" )
106- with tools .chdir (self ._source_subfolder ):
107- autotools = self ._configure_autotools ()
108- autotools .install ()
109- autotools .make (target = "install-lib-headers" )
110- with tools .chdir ("librhash" ):
111- if self .options .shared :
112- autotools .make (target = "install-so-link" )
113- tools .rmdir (os .path .join (self .package_folder , "bin" ))
114- tools .rmdir (os .path .join (self .package_folder , "etc" ))
115- tools .rmdir (os .path .join (self .package_folder , "share" ))
80+ copy (self , "COPYING" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
81+ cmake = CMake (self )
82+ cmake .install ()
11683
11784 def package_info (self ):
85+ self .cpp_info .set_property ("cmake_file_name" , "LibRHash" )
86+ self .cpp_info .set_property ("cmake_target_name" , "LibRHash::LibRHash" )
87+ self .cpp_info .set_property ("pkg_config_name" , "librhash" )
88+ self .cpp_info .libs = ["rhash" ]
89+ self .cpp_info .defines .append (f"RHASH_XVERSION={ self ._xversion } " )
90+
91+ # TODO: to remove in conan v2 once cmake_find_package_* generators removed
11892 self .cpp_info .names ["cmake_find_package" ] = "LibRHash"
11993 self .cpp_info .names ["cmake_find_package_multi" ] = "LibRHash"
120- self .cpp_info .names ["pkg_config" ] = "librhash"
121- self .cpp_info .libs = ["rhash" ]
0 commit comments