Skip to content

Commit da8b387

Browse files
valgurmemsharded
authored andcommitted
(conan-io#18986) librhash: migrate to Conan v2
* librhash: migrate to Conan v2 * librhash: use OpenSSL v1 * librhash: bump deps * librhash: fix installation * librhash: downgrade OpenSSL * librhash: switch to custom CMakeLists.txt The build scripts in the project are quite non-standard and not too portable. Based on rhash/RHash#103 * librhash: bump openssl * librhash: add v1.4.4 * librhash: fix the list of sources used in CMakeLists.txt * librhash: fix missing lib prefix for libs * librhash: don't use PROJECT_NAME
1 parent 66693ed commit da8b387

File tree

9 files changed

+143
-120
lines changed

9 files changed

+143
-120
lines changed

recipes/librhash/all/CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Based on https://github.com/rhash/RHash/pull/103
2+
cmake_minimum_required(VERSION 3.15)
3+
project(rhash LANGUAGES C)
4+
5+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../version.h" versionfile)
6+
string(REGEX MATCH "#define VERSION \"([0-9]*)\.([0-9]*)\.([0-9]*)\"" _ ${versionfile})
7+
set(RHASH_VERSION_MAJOR ${CMAKE_MATCH_1})
8+
set(RHASH_VERSION_MINOR ${CMAKE_MATCH_2})
9+
set(RHASH_VERSION_PATCH ${CMAKE_MATCH_3})
10+
set(RHASH_VERSION "${RHASH_VERSION_MAJOR}.${RHASH_VERSION_MINOR}.${RHASH_VERSION_PATCH}")
11+
12+
option(USE_OPENSSL "Enable OpenSSL (optimized hash functions) support" ON)
13+
14+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
15+
16+
# Get the list of source files from the Makefile
17+
# https://github.com/rhash/RHash/blob/v1.4.4/librhash/Makefile#L6
18+
file(READ Makefile MAKEFILE_CONTENTS)
19+
if("${MAKEFILE_CONTENTS}" MATCHES "SOURCES *= *([^\n]+)")
20+
string(REPLACE " " ";" SOURCE_FILES ${CMAKE_MATCH_1})
21+
else()
22+
message(FATAL_ERROR "SOURCES line not found in Makefile")
23+
endif()
24+
25+
add_library(rhash ${SOURCE_FILES})
26+
27+
if(USE_OPENSSL)
28+
find_package(OpenSSL REQUIRED)
29+
target_link_libraries(rhash OpenSSL::Crypto)
30+
target_compile_definitions(rhash PUBLIC USE_OPENSSL)
31+
endif()
32+
33+
if(MSVC)
34+
target_compile_definitions(rhash PRIVATE _CRT_SECURE_NO_DEPRECATE)
35+
endif()
36+
37+
set_target_properties(rhash PROPERTIES
38+
COMPILE_DEFINITIONS IN_RHASH
39+
DEFINE_SYMBOL RHASH_EXPORTS
40+
VERSION ${RHASH_VERSION}
41+
SOVERSION ${RHASH_VERSION_MAJOR})
42+
43+
install(TARGETS rhash
44+
RUNTIME DESTINATION bin
45+
LIBRARY DESTINATION lib
46+
ARCHIVE DESTINATION lib)
47+
48+
install(FILES "rhash.h" "rhash_torrent.h" DESTINATION include)

recipes/librhash/all/conandata.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
sources:
2+
"1.4.4":
3+
url: "https://downloads.sourceforge.net/project/rhash/rhash/1.4.4/rhash-1.4.4-src.tar.gz"
4+
sha256: "8e7d1a8ccac0143c8fe9b68ebac67d485df119ea17a613f4038cda52f84ef52a"
25
"1.4.2":
36
url: "https://downloads.sourceforge.net/project/rhash/rhash/1.4.2/rhash-1.4.2-src.tar.gz"
47
sha256: "600d00f5f91ef04194d50903d3c79412099328c42f28ff43a0bdb777b00bec62"
58
"1.3.9":
69
url: "https://downloads.sourceforge.net/project/rhash/rhash/1.3.9/rhash-1.3.9-src.tar.gz"
710
sha256: "42b1006f998adb189b1f316bf1a60e3171da047a85c4aaded2d0d26c1476c9f6"
8-
patches:
9-
"1.4.2":
10-
- patch_file: "patches/0001-1.4.2-fix-compiler-detection.patch"
11-
base_path: "source_subfolder"

recipes/librhash/all/conanfile.py

+48-76
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
from conans import AutoToolsBuildEnvironment, ConanFile, tools
2-
from conans.errors import ConanInvalidConfiguration
31
import 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

812
class 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"]

recipes/librhash/all/patches/0001-1.4.2-fix-compiler-detection.patch

-29
This file was deleted.

recipes/librhash/all/test_package/CMakeLists.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
cmake_minimum_required(VERSION 3.3)
1+
cmake_minimum_required(VERSION 3.15)
22
project(test_package C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
6-
74
find_package(LibRHash CONFIG REQUIRED)
85

96
add_executable(${PROJECT_NAME} test_package.c)
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.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
24
import os
35

46

5-
class SolaceTestConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake", "cmake_find_package_multi"
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def requirements(self):
13+
self.requires(self.tested_reference_str)
14+
15+
def layout(self):
16+
cmake_layout(self)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

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.bindir, "test_package")
26+
self.run(bin_path, env="conanrun")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class SolaceTestConan(ConanFile):
6+
settings = "os", "compiler", "build_type", "arch"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
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)

recipes/librhash/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
versions:
2+
1.4.4:
3+
folder: all
24
1.4.2:
35
folder: all
46
1.3.9:

0 commit comments

Comments
 (0)