From 0b200ba14947a189898af4fd5f4236594e777215 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 6 Nov 2023 09:39:14 +0200 Subject: [PATCH] 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 --- recipes/librhash/all/CMakeLists.txt | 47 +++++++++++ recipes/librhash/all/conandata.yml | 3 - recipes/librhash/all/conanfile.py | 82 +++++-------------- .../0001-1.4.2-fix-compiler-detection.patch | 29 ------- 4 files changed, 67 insertions(+), 94 deletions(-) create mode 100644 recipes/librhash/all/CMakeLists.txt delete mode 100644 recipes/librhash/all/patches/0001-1.4.2-fix-compiler-detection.patch diff --git a/recipes/librhash/all/CMakeLists.txt b/recipes/librhash/all/CMakeLists.txt new file mode 100644 index 0000000000000..539da828d8f90 --- /dev/null +++ b/recipes/librhash/all/CMakeLists.txt @@ -0,0 +1,47 @@ +# Based on https://github.com/rhash/RHash/pull/103 +cmake_minimum_required(VERSION 3.15) +project(librhash LANGUAGES C) + +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/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) + +set(SRC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/src/librhash") +file(GLOB SOURCE_FILES "${SRC_ROOT}/*.c") +file(GLOB HEADER_FILES "${SRC_ROOT}/*.h") + +add_library(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES}) +set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}") + +if(USE_OPENSSL) + find_package(OpenSSL REQUIRED) + target_link_libraries(${PROJECT_NAME} OpenSSL::Crypto) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_OPENSSL) +endif() + +if(MSVC) + target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_DEPRECATE) +endif() + +set_target_properties(${PROJECT_NAME} PROPERTIES + COMPILE_DEFINITIONS IN_RHASH + DEFINE_SYMBOL RHASH_EXPORTS + PREFIX "" + IMPORT_PREFIX "" + VERSION ${RHASH_VERSION} + SOVERSION ${RHASH_VERSION_MAJOR}) + +install(TARGETS ${PROJECT_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +install(FILES "${SRC_ROOT}/rhash.h" "${SRC_ROOT}/rhash_torrent.h" + DESTINATION include) diff --git a/recipes/librhash/all/conandata.yml b/recipes/librhash/all/conandata.yml index 0b04af27e7c8e..0011393212a7f 100644 --- a/recipes/librhash/all/conandata.yml +++ b/recipes/librhash/all/conandata.yml @@ -5,6 +5,3 @@ sources: "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" diff --git a/recipes/librhash/all/conanfile.py b/recipes/librhash/all/conanfile.py index 1db0d2521c21e..0890bac8535e4 100644 --- a/recipes/librhash/all/conanfile.py +++ b/recipes/librhash/all/conanfile.py @@ -1,13 +1,10 @@ import os from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.build import cross_building -from conan.tools.env import VirtualBuildEnv, VirtualRunEnv -from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, rmdir -from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +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.microsoft import is_msvc, unix_path +from conan.tools.scm import Version required_conan_version = ">=1.53.0" @@ -38,7 +35,7 @@ def _settings_build(self): return getattr(self, "settings_build", self.settings) def export_sources(self): - export_conandata_patches(self) + copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) def config_options(self): if self.settings.os == "Windows": @@ -57,78 +54,39 @@ def requirements(self): if self.options.with_openssl: self.requires("openssl/1.1.1w") - def validate(self): - if is_msvc(self): - raise ConanInvalidConfiguration("Visual Studio is not supported") - - def build_requirements(self): - if self._settings_build.os == "Windows": - self.win_bash = True - if not self.conf.get("tools.microsoft.bash:path", check_type=str): - self.tool_requires("msys2/cci.latest") - def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) + @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): - env = VirtualBuildEnv(self) - env.generate() - - if not cross_building(self): - env = VirtualRunEnv(self) - env.generate(scope="build") - - tc = AutotoolsToolchain(self) - if self.settings.compiler in ("apple-clang",): - if self.settings.arch == "armv7": - tc.build_type_link_flags.append("-arch armv7") - elif self.settings.arch == "armv8": - tc.build_type_link_flags.append("-arch arm64") - tc.configure_args = [ - # librhash's configure script does not understand `--enable-opt1=yes` - "--{}-openssl".format("enable" if self.options.with_openssl else "disable"), - "--disable-gettext", - ] - if self.options.shared: - tc.configure_args += ["--enable-lib-shared", "--disable-lib-static"] - else: - tc.configure_args += ["--disable-lib-shared", "--enable-lib-static"] - tc.make_args += [ - f"INCDIR={unix_path(self, os.path.join(self.package_folder, 'include'))}", - f"BINDIR={unix_path(self, os.path.join(self.package_folder, 'bin'))}", - f"LIBDIR={unix_path(self, os.path.join(self.package_folder, 'lib'))}", - f"SO_DIR={unix_path(self, os.path.join(self.package_folder, 'lib'))}", - ] + tc = CMakeToolchain(self) + tc.cache_variables["USE_OPENSSL"] = self.options.with_openssl + tc.preprocessor_definitions["RHASH_XVERSION"] = self._xversion tc.generate() - - deps = AutotoolsDeps(self) + deps = CMakeDeps(self) deps.generate() def build(self): - apply_conandata_patches(self) - with chdir(self, self.source_folder): - autotools = Autotools(self) - autotools.configure() - autotools.make() + cmake = CMake(self) + cmake.configure(build_script_folder=self.source_path.parent) + cmake.build() def package(self): copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) - with chdir(self, self.source_folder): - autotools = Autotools(self) - autotools.install() - autotools.make(target="install-lib-headers") - with chdir(self, "librhash"): - if self.options.shared: - autotools.make(target="install-so-link") - for path in self.package_path.iterdir(): - if path.is_dir() and path.name not in ["include", "lib", "licenses"]: - rmdir(self, path) + 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" 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)