Repository: conan-io/conan-center-index

Issue:
[request] hiredis/0.14.0
### Package Details
  * Package Name/Version: hiredis/0.14.0
  * Website: https://github.com/redis/hiredis
  * Source code: https://github.com/redis/hiredis


### Description Of The Library / Tool
Hiredis is a minimalistic C client library for the Redis database.


Discussion:
Hello @andre-cunha !

Would you like to contribute with this recipe? I've found two Conan recipes for this project when Googling. We you can help you! 

Resolving patch:
diff --git a/recipes/hiredis/0.14.1/conanfile.py b/recipes/hiredis/0.14.1/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/hiredis/0.14.1/conanfile.py
@@ -0,0 +1,81 @@
+from conans import AutoToolsBuildEnvironment, ConanFile, tools
+from conans.errors import ConanInvalidConfiguration
+
+import os
+
+
+class HiredisConan(ConanFile):
+    name = "hiredis"
+    version = "0.14.1"
+
+    description = "Minimalistic C client for Redis >= 1.2"
+    topics = "conan", "c", "redis"
+
+    license = "BSD-3-Clause"
+    settings = "os", "arch", "compiler", "build_type"
+
+    homepage = "https://github.com/redis/hiredis"
+    url = "https://github.com/conan-io/conan-center-index"
+
+    options = {
+        "fPIC": [True, False],
+        "shared": [True, False]
+    }
+    default_options = {
+        "fPIC": True,
+        "shared": False
+    }
+
+    def _configure_autotools(self):
+        autoTools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
+        return autoTools
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def configure(self):
+        del self.settings.compiler.cppstd
+        del self.settings.compiler.libcxx
+
+        if self.settings.os == "Windows":
+            raise ConanInvalidConfiguration("hiredis %s is not supported on Windows." % self.version)
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_folder = self.name + "-" + self.version
+        os.rename(extracted_folder, self._source_subfolder)
+
+    def build(self):
+        # update makefile
+        makefile = os.path.join(self.source_folder, self._source_subfolder, "Makefile")
+        tools.replace_in_file(makefile, "-fPIC ", "", strict=False)
+
+        with tools.chdir(os.path.join(self.source_folder, self._source_subfolder)):
+            autoTools = self._configure_autotools()
+            autoTools.make()
+
+    def package(self):
+        with tools.chdir(os.path.join(self.source_folder, self._source_subfolder)):
+            autoTools = self._configure_autotools()
+            autoTools.install(vars={
+                "DESTDIR": os.path.join(self.build_folder),
+                "PREFIX": ""
+            })
+
+        # headers
+        self.copy("*.h", dst=os.path.join("include", "hiredis"), src=os.path.join("include", "hiredis"))
+
+        # libs
+        if self.options.shared:
+            self.copy("*.dylib", dst="lib", keep_path=False)
+            self.copy("*.so", dst="lib", keep_path=False)
+            self.copy("*.so.*", dst="lib", keep_path=False)
+        else:
+            self.copy("*.a", dst="lib", keep_path=False)
+
+        # licenses
+        self.copy("COPYING", dst="licenses", src=self._source_subfolder)
+
+    def package_info(self):
+        self.cpp_info.libs = tools.collect_libs(self)


Test patch:
diff --git a/recipes/hiredis/0.14.1/test_package/CMakeLists.txt b/recipes/hiredis/0.14.1/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/hiredis/0.14.1/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.8.11)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} src/main.cpp)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/hiredis/0.14.1/test_package/conanfile.py b/recipes/hiredis/0.14.1/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/hiredis/0.14.1/test_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestHiredisConan(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):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/hiredis/0.14.1/test_package/src/main.cpp b/recipes/hiredis/0.14.1/test_package/src/main.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/hiredis/0.14.1/test_package/src/main.cpp
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include <iostream>
+
+#include <hiredis/hiredis.h>
+
+int main()
+{
+    std::cout << "hiredis version: " << HIREDIS_MAJOR << "."
+              << HIREDIS_MINOR << "."
+              << HIREDIS_PATCH << std::endl;
+
+    const char *hostname = "127.0.0.1";
+    int port = 6379;
+
+    redisContext *c = redisConnect(hostname, port);
+    if (c == NULL)
+    {
+        printf("Error: Can't allocate redis context\n");
+        return EXIT_FAILURE;
+    }
+
+    return EXIT_SUCCESS;
+}