Skip to content

Commit

Permalink
Add librhash/1.3.9 recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Jan 25, 2020
1 parent 2eece86 commit afb731c
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/librhash/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.3.9":
sha256: 42b1006f998adb189b1f316bf1a60e3171da047a85c4aaded2d0d26c1476c9f6
url: https://downloads.sourceforge.net/project/rhash/rhash/1.3.9/rhash-1.3.9-src.tar.gz
100 changes: 100 additions & 0 deletions recipes/librhash/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import os
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration


class LibRHashConan(ConanFile):
name = "librhash"
description = "Great utility for computing hash sums"
topics = ("conan", "rhash", "hash", "checksum")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://rhash.sourceforge.net/"
license = "MIT"
exports_sources = "CMakeLists.txt",
generators = "cmake",
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_openssl": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_openssl": True,
}

_autotools = None
@property
def _source_subfolder(self):
return "source_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("Visual Studio is not supported")
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
if self.options.shared:
del self.options.fPIC

def build_requirements(self):
if tools.os_info.is_windows and "CONAN_BASH_PATH" not in os.environ:
self.build_requires("msys2/20190524")

def requirements(self):
if self.options.with_openssl:
self.requires("openssl/1.1.1d")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_folder = "RHash-{}".format(self.version)
os.rename(extracted_folder, self._source_subfolder)

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
conf_args = [
"--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"))),
"--extra-cflags={}".format(self._autotools.vars["CPPFLAGS"]),
"--extra-ldflags={}".format(self._autotools.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"])

self._autotools.configure(args=conf_args, use_default_install_dirs=False)
return self._autotools

def build(self):
with tools.chdir(self._source_subfolder):
autotools = self._configure_autotools()
autotools.make()

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"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "LibRHash"
self.cpp_info.names["cmake_find_package_multi"] = "LibRHash"
self.cpp_info.libs = tools.collect_libs(self)
11 changes: 11 additions & 0 deletions recipes/librhash/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.3)
project(test_package CXX)

set(CMAKE_VERBOSE_MAKEFILE ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
set(CMAKE_CXX_STANDARD 11)

add_executable(${PROJECT_NAME} example.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
16 changes: 16 additions & 0 deletions recipes/librhash/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from conans import ConanFile, CMake, tools


class SolaceTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
self.run(os.path.join("bin", "test_package"), run_environment=True)
20 changes: 20 additions & 0 deletions recipes/librhash/all/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "rhash.h"

#include <cstdio>
#include <cstring>

#define MSG "hello world"
#define SHA256_REF "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"

int main() {
rhash_library_init();
unsigned char rhash_bin_buffer[128];
char rhash_char_buffer[128];
rhash_msg(RHASH_SHA256, MSG, strlen(MSG), rhash_bin_buffer);
int nb = rhash_print_bytes(rhash_char_buffer, rhash_bin_buffer, rhash_get_hash_length(RHASH_SHA256), RHPR_HEX);
rhash_char_buffer[rhash_get_hash_length(RHASH_SHA256)] = '\0';
printf("calculated SHA256 hash= %s\n", rhash_char_buffer);

printf("reference SHA256 hash= %s\n", SHA256_REF);
return strcmp(rhash_char_buffer, SHA256_REF);
}
3 changes: 3 additions & 0 deletions recipes/librhash/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
1.3.9:
folder: all

0 comments on commit afb731c

Please sign in to comment.