Repository: conan-io/conan-center-index

Issue:
[request] redis-plus-plus/1.2.1
### Package Details
  * Package Name/Version: **redis-plus-plus/1.2.1**
  * Source code: **https://github.com/sewenew/redis-plus-plus**

### Description Of The Library / Tool
A C++ client for Redis. It's based on hiredis, and written in C++ 11 / C++ 17.


#### Notes
* I'm an EAP member and I'm already working on this recipe.
* I have an early version working locally. 
* My early version does not yet support all of the CMake options, e.g. building with TLS support, Windows builds, etc. 
 * If anyone else is working on it, and would like to fork my branch, leave me a note here. 


Discussion:

Resolving patch:
diff --git a/recipes/redis-plus-plus/all/conanfile.py b/recipes/redis-plus-plus/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/redis-plus-plus/all/conanfile.py
@@ -0,0 +1,93 @@
+from conans import ConanFile, CMake, tools
+from conans.errors import ConanInvalidConfiguration
+import os
+
+required_conan_version = ">=1.32.0"
+
+
+class RedisPlusPlusConan(ConanFile):
+    name = "redis-plus-plus"
+    homepage = "https://github.com/sewenew/redis-plus-plus"
+    description = "Redis client written in C++"
+    topics = ("conan", "database", "redis", "client", "tls")
+    url = "https://github.com/conan-io/conan-center-index"
+    license = "Apache-2.0"
+    exports_sources = ["CMakeLists.txt", "patches/**"]
+    generators = "cmake", "cmake_find_package_multi"
+    settings = "os", "compiler", "build_type", "arch"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "with_tls": [True, False]
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "with_tls": False
+    }
+
+    _cmake = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+        if self.settings.compiler.get_safe("cppstd"):
+            tools.check_min_cppstd(self, 11)
+
+    def requirements(self):
+        self.requires("hiredis/1.0.0")
+
+    def validate(self):
+        if self.options.with_tls != self.options["hiredis"].with_ssl:
+            raise ConanInvalidConfiguration("with_tls must match hiredis.with_ssl option")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = self.name + "-" + self.version
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def _configure_cmake(self):
+        if not self._cmake:
+            self._cmake = CMake(self)
+            self._cmake.definitions["REDIS_PLUS_PLUS_USE_TLS"] = self.options.with_tls
+            self._cmake.definitions["REDIS_PLUS_PLUS_BUILD_TEST"] = False
+            self._cmake.definitions["REDIS_PLUS_PLUS_BUILD_STATIC"] = not self.options.shared
+            self._cmake.definitions["REDIS_PLUS_PLUS_BUILD_SHARED"] = self.options.shared
+            self._cmake.configure(build_folder=self._build_subfolder)
+        return self._cmake
+
+    def _patch_sources(self):
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            tools.patch(**patch)
+        tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
+                              "set_target_properties(${STATIC_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON)",
+                              "")
+
+    def build(self):
+        self._patch_sources()
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
+        cmake = self._configure_cmake()
+        cmake.install()
+
+    def package_info(self):
+        suffix = "_static" if self.settings.os == "Windows" and not self.options.shared else ""
+        self.cpp_info.libs = ["redis++" + suffix]
+        self.cpp_info.requires = ["hiredis::hiredislib"]
+        if self.options.with_tls:
+            self.cpp_info.requires.append("hiredis::hiredis_ssl")


Test patch:
diff --git a/recipes/redis-plus-plus/all/test_package/CMakeLists.txt b/recipes/redis-plus-plus/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/redis-plus-plus/all/test_package/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
+set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
diff --git a/recipes/redis-plus-plus/all/test_package/conanfile.py b/recipes/redis-plus-plus/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/redis-plus-plus/all/test_package/conanfile.py
@@ -0,0 +1,16 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class TestPackageConan(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)
diff --git a/recipes/redis-plus-plus/all/test_package/test_package.cpp b/recipes/redis-plus-plus/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/redis-plus-plus/all/test_package/test_package.cpp
@@ -0,0 +1,16 @@
+#include <sw/redis++/redis++.h>
+
+using namespace sw::redis;
+
+int main() {
+    try{
+        auto redis = Redis("tcp://127.0.0.1:6379");
+        redis.set("key", "val");
+        redis.rpush("list", {"a", "b", "c"});
+    }
+    catch(...)
+    {
+    }
+
+    return 0;
+}