From da8b387ed57addf6d048ab5ab6a2e3e0a7200773 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 13 Jun 2024 14:22:54 +0300 Subject: [PATCH] (#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 https://github.com/rhash/RHash/pull/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 --- recipes/librhash/all/CMakeLists.txt | 48 +++++++ recipes/librhash/all/conandata.yml | 7 +- recipes/librhash/all/conanfile.py | 124 +++++++----------- .../0001-1.4.2-fix-compiler-detection.patch | 29 ---- .../librhash/all/test_package/CMakeLists.txt | 5 +- .../librhash/all/test_package/conanfile.py | 23 +++- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../librhash/all/test_v1_package/conanfile.py | 17 +++ recipes/librhash/config.yml | 2 + 9 files changed, 143 insertions(+), 120 deletions(-) create mode 100644 recipes/librhash/all/CMakeLists.txt delete mode 100644 recipes/librhash/all/patches/0001-1.4.2-fix-compiler-detection.patch create mode 100644 recipes/librhash/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/librhash/all/test_v1_package/conanfile.py diff --git a/recipes/librhash/all/CMakeLists.txt b/recipes/librhash/all/CMakeLists.txt new file mode 100644 index 0000000000000..5a8989c04fb68 --- /dev/null +++ b/recipes/librhash/all/CMakeLists.txt @@ -0,0 +1,48 @@ +# Based on https://github.com/rhash/RHash/pull/103 +cmake_minimum_required(VERSION 3.15) +project(rhash LANGUAGES C) + +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../version.h" versionfile) +string(REGEX MATCH "#define VERSION \"([0-9]*)\.([0-9]*)\.([0-9]*)\"" _ ${versionfile}) +set(RHASH_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(RHASH_VERSION_MINOR ${CMAKE_MATCH_2}) +set(RHASH_VERSION_PATCH ${CMAKE_MATCH_3}) +set(RHASH_VERSION "${RHASH_VERSION_MAJOR}.${RHASH_VERSION_MINOR}.${RHASH_VERSION_PATCH}") + +option(USE_OPENSSL "Enable OpenSSL (optimized hash functions) support" ON) + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + +# Get the list of source files from the Makefile +# https://github.com/rhash/RHash/blob/v1.4.4/librhash/Makefile#L6 +file(READ Makefile MAKEFILE_CONTENTS) +if("${MAKEFILE_CONTENTS}" MATCHES "SOURCES *= *([^\n]+)") + string(REPLACE " " ";" SOURCE_FILES ${CMAKE_MATCH_1}) +else() + message(FATAL_ERROR "SOURCES line not found in Makefile") +endif() + +add_library(rhash ${SOURCE_FILES}) + +if(USE_OPENSSL) + find_package(OpenSSL REQUIRED) + target_link_libraries(rhash OpenSSL::Crypto) + target_compile_definitions(rhash PUBLIC USE_OPENSSL) +endif() + +if(MSVC) + target_compile_definitions(rhash PRIVATE _CRT_SECURE_NO_DEPRECATE) +endif() + +set_target_properties(rhash PROPERTIES + COMPILE_DEFINITIONS IN_RHASH + DEFINE_SYMBOL RHASH_EXPORTS + VERSION ${RHASH_VERSION} + SOVERSION ${RHASH_VERSION_MAJOR}) + +install(TARGETS rhash + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +install(FILES "rhash.h" "rhash_torrent.h" DESTINATION include) diff --git a/recipes/librhash/all/conandata.yml b/recipes/librhash/all/conandata.yml index 7551a33f27039..86c6f3d9822c3 100644 --- a/recipes/librhash/all/conandata.yml +++ b/recipes/librhash/all/conandata.yml @@ -1,11 +1,10 @@ sources: + "1.4.4": + url: "https://downloads.sourceforge.net/project/rhash/rhash/1.4.4/rhash-1.4.4-src.tar.gz" + sha256: "8e7d1a8ccac0143c8fe9b68ebac67d485df119ea17a613f4038cda52f84ef52a" "1.4.2": url: "https://downloads.sourceforge.net/project/rhash/rhash/1.4.2/rhash-1.4.2-src.tar.gz" sha256: "600d00f5f91ef04194d50903d3c79412099328c42f28ff43a0bdb777b00bec62" "1.3.9": url: "https://downloads.sourceforge.net/project/rhash/rhash/1.3.9/rhash-1.3.9-src.tar.gz" sha256: "42b1006f998adb189b1f316bf1a60e3171da047a85c4aaded2d0d26c1476c9f6" -patches: - "1.4.2": - - patch_file: "patches/0001-1.4.2-fix-compiler-detection.patch" - base_path: "source_subfolder" diff --git a/recipes/librhash/all/conanfile.py b/recipes/librhash/all/conanfile.py index 5528b9c183b00..a7af280fa7f51 100644 --- a/recipes/librhash/all/conanfile.py +++ b/recipes/librhash/all/conanfile.py @@ -1,17 +1,23 @@ -from conans import AutoToolsBuildEnvironment, ConanFile, tools -from conans.errors import ConanInvalidConfiguration import os -required_conan_version = ">=1.33.0" +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake +from conan.tools.files import copy, get +from conan.tools.layout import basic_layout +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" class LibRHashConan(ConanFile): name = "librhash" description = "Great utility for computing hash sums" - topics = ("rhash", "hash", "checksum") + license = "MIT" url = "https://github.com/conan-io/conan-center-index" homepage = "http://rhash.sourceforge.net/" - license = "MIT" + topics = ("rhash", "hash", "checksum") + + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -24,98 +30,64 @@ class LibRHashConan(ConanFile): "with_openssl": True, } - exports_sources = "patches/*" - _autotools = None - - @property - def _source_subfolder(self): - return "source_subfolder" - @property def _settings_build(self): return getattr(self, "settings_build", self.settings) + def export_sources(self): + copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src", "librhash")) + def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: - del self.options.fPIC - del self.settings.compiler.cppstd - del self.settings.compiler.libcxx + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): if self.options.with_openssl: - self.requires("openssl/1.1.1q") - - def build_requirements(self): - if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): - self.build_requires("msys2/cci.latest") - - def validate(self): - if self.settings.compiler == "Visual Studio": - raise ConanInvalidConfiguration("Visual Studio is not supported") + self.requires("openssl/[>=1.1 <4]") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) - - def _configure_autotools(self): - if self._autotools: - return self._autotools - self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - if self.settings.compiler in ("apple-clang", ): - if self.settings.arch in ("armv7", ): - self._autotools.link_flags.append("-arch armv7") - elif self.settings.arch in ("armv8", ): - self._autotools.link_flags.append("-arch arm64") - vars = self._autotools.vars - conf_args = [ - # librhash's configure script does not understand `--enable-opt1=yes` - "--enable-openssl" if self.options.with_openssl else "--disable-openssl", - "--disable-gettext", - # librhash's configure script is custom and does not understand "--bindir=${prefix}/bin" arguments - "--prefix={}".format(tools.unix_path(self.package_folder)), - "--bindir={}".format(tools.unix_path(os.path.join(self.package_folder, "bin"))), - "--libdir={}".format(tools.unix_path(os.path.join(self.package_folder, "lib"))), - # the configure script does not use CPPFLAGS, so add it to CFLAGS/CXXFLAGS - "--extra-cflags={}".format("{} {}".format(vars["CFLAGS"], vars["CPPFLAGS"])), - "--extra-ldflags={}".format(vars["LDFLAGS"]), - ] - if self.options.shared: - conf_args.extend(["--enable-lib-shared", "--disable-lib-static"]) - else: - conf_args.extend(["--disable-lib-shared", "--enable-lib-static"]) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - with tools.environment_append({ - "BUILD_TARGET": tools.get_gnu_triplet(str(self.settings.os), str(self.settings.arch), str(self.settings.compiler)), - }): - self._autotools.configure(args=conf_args, use_default_install_dirs=False, build=False, host=False) - return self._autotools + @property + def _xversion(self): + # https://github.com/rhash/RHash/blob/v1.4.4/configure#L339 + version = Version(self.version) + return f"0x{version.major.value:02x}{version.minor.value:02x}{version.patch.value:02x}{0:02x}" + + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["USE_OPENSSL"] = self.options.with_openssl + tc.preprocessor_definitions["RHASH_XVERSION"] = self._xversion + tc.generate() + deps = CMakeDeps(self) + deps.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - with tools.chdir(self._source_subfolder): - autotools = self._configure_autotools() - autotools.make() + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, "librhash")) + cmake.build() def package(self): - self.copy("COPYING", src=self._source_subfolder, dst="licenses") - with tools.chdir(self._source_subfolder): - autotools = self._configure_autotools() - autotools.install() - autotools.make(target="install-lib-headers") - with tools.chdir("librhash"): - if self.options.shared: - autotools.make(target="install-so-link") - tools.rmdir(os.path.join(self.package_folder, "bin")) - tools.rmdir(os.path.join(self.package_folder, "etc")) - tools.rmdir(os.path.join(self.package_folder, "share")) + copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() def package_info(self): + self.cpp_info.set_property("cmake_file_name", "LibRHash") + self.cpp_info.set_property("cmake_target_name", "LibRHash::LibRHash") + self.cpp_info.set_property("pkg_config_name", "librhash") + self.cpp_info.libs = ["rhash"] + self.cpp_info.defines.append(f"RHASH_XVERSION={self._xversion}") + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.names["cmake_find_package"] = "LibRHash" self.cpp_info.names["cmake_find_package_multi"] = "LibRHash" - self.cpp_info.names["pkg_config"] = "librhash" - self.cpp_info.libs = ["rhash"] diff --git a/recipes/librhash/all/patches/0001-1.4.2-fix-compiler-detection.patch b/recipes/librhash/all/patches/0001-1.4.2-fix-compiler-detection.patch deleted file mode 100644 index f6e51246e4dea..0000000000000 --- a/recipes/librhash/all/patches/0001-1.4.2-fix-compiler-detection.patch +++ /dev/null @@ -1,29 +0,0 @@ -Revert compiler detection to state of 1.3.9 - ---- configure -+++ configure -@@ -513,14 +513,9 @@ - CC_TMP="$CC" - test -n "$OPT_CC" && OTHER_CC= || OTHER_CC="gcc cc" - for CC in "$CC_TMP" $OTHER_CC; do -- cc_name_tmp= - if run_cmd "$CC -v"; then - cc_name_tmp=$($CC -v 2>&1 | tail -n 1 | cut -d ' ' -f 1) -- elif run_cmd "$CC --version"; then -- cc_name_tmp=$($CC --version 2>&1 | head -n 1 | cut -d ' ' -f 1) -- fi -- if test -n "${cc_name_tmp}"; then -- if echo "$cc_name_tmp" | grep -q "gcc"; then -+ if test "$cc_name_tmp" = "gcc"; then - cc_name=$cc_name_tmp - start_check "$CC version" - cc_vendor=gnu -@@ -544,7 +539,7 @@ - finish_check "$cc_name $cc_version" - break - fi -- if echo "$cc_name_tmp" | grep -q "clang"; then -+ if $CC -v 2>&1 | grep -q "clang"; then - start_check "$CC version" - cc_vendor=clang - cc_version=$($CC -dumpversion 2>&1) diff --git a/recipes/librhash/all/test_package/CMakeLists.txt b/recipes/librhash/all/test_package/CMakeLists.txt index 80f208bb6a15a..f1b9a5e0be249 100644 --- a/recipes/librhash/all/test_package/CMakeLists.txt +++ b/recipes/librhash/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.15) project(test_package C) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(LibRHash CONFIG REQUIRED) add_executable(${PROJECT_NAME} test_package.c) diff --git a/recipes/librhash/all/test_package/conanfile.py b/recipes/librhash/all/test_package/conanfile.py index 2c7657d70d5d9..ef5d7042163ec 100644 --- a/recipes/librhash/all/test_package/conanfile.py +++ b/recipes/librhash/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -class SolaceTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/librhash/all/test_v1_package/CMakeLists.txt b/recipes/librhash/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/librhash/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/librhash/all/test_v1_package/conanfile.py b/recipes/librhash/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..2c7657d70d5d9 --- /dev/null +++ b/recipes/librhash/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class SolaceTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/librhash/config.yml b/recipes/librhash/config.yml index 24eb5d89c9135..334d34ca8c5c1 100644 --- a/recipes/librhash/config.yml +++ b/recipes/librhash/config.yml @@ -1,4 +1,6 @@ versions: + 1.4.4: + folder: all 1.4.2: folder: all 1.3.9: