Repository: conan-io/conan-center-index

Issue:
[question] Using redis-plus-plus with TLS/SSL on
### What is your question?

Hi, I'm having difficulty using Conan to include a version of redis-plus-plus built with TLS enabled in my project. It seems like redis-plus-plus's conan recipe has a `with_tls` option that should enable the support. However, this depends on hiredis being built with SSL enabled. The conan recipe for hiredis seems to have a `with_ssl` option that's supposed to do exactly that, but I could not get it to work. 

Here's my conanfile.py:

```
from conan import ConanFile, tools
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

class HelloConan(ConanFile):
    name = "myproject"
    version = "0.0.1"
    settings = "os", "compiler", "build_type", "arch"


    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.generate()

    def configure(self):
        self.options["hiredis"]["with_ssl"] = True
        self.options["redis-plus-plus"]["with_tls"] = True

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def requirements(self):
        self.requires("redis-plus-plus/1.3.11")
        self.requires("hiredis/1.2.0")
```

The error message I get is 
```
CMake Error at 
/home/ago/.conan2/p/b/redis08573fb8e514a/b/build/Release/generators/cmakedeps_macros.cmake:67 (message):
  Library 'hiredis_ssl' not found in package.  If 'hiredis_ssl' is a system
  library, declare it with 'cpp_info.system_libs' property
```

I also tried not including hiredis in the requirements and/or configure functions in my conanfile.py. The result was 

```
ERROR: There are invalid packages:
redis-plus-plus/1.3.11: Invalid: redis-plus-plus:with_tls=True requires hiredis:with_ssl=True
```

I'd really appreciate if anyone could guide me in the right direction to get redis-plus-plus built with the with_tls option enabled.


Discussion:
Hello @aligirayhanozbay-abex!

You should use `config_options` instead:

```python
def config_options(self):
    self.options["hiredis"].with_ssl = True
    self.options["redis-plus-plus"].with_tls = True
```

More info: https://docs.conan.io/2/reference/conanfile/methods/config_options.html#config-options


Hi @uilianries I tried exactly what you wrote but the result was unfortunately the same. My conanfile.py is now

```
from conan import ConanFile, tools
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

class HelloConan(ConanFile):
    name = "myproject"
    version = "0.0.1"
    settings = "os", "compiler", "build_type", "arch"


    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.generate()

    def config_options(self):
        self.options["hiredis"].with_ssl = True
        self.options["redis-plus-plus"].with_tls = True

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def requirements(self):
        self.requires("redis-plus-plus/1.3.11")
        self.requires("hiredis/1.2.0")
```
As a further piece of information I checked the logs when hiredis was being built, and I can confirm libhiredis_ssl.a is not being built.
@aligirayhanozbay-abex Thank you for reporting, so we have a bug in the recipe. Indeed that option is not checked by the CI service, because is disabled always. Only options `fPIC`, `shared` and `header_only` are checked.


I see, thank you. I will try to use a forked recipe forcing with_ssl=True until this is fixed upstream.

EDIT: This approach did not work. I guess there's something further that's wrong with the recipe.
Worked with hiredis/1.1.0. hiredis/1.2.0 recipe `with_ssl=True` is broken...
@aligirayhanozbay-abex I'm inclined to check this bug, but I would like to know some information first:

- What Conan version are you running?
- What O.S. ? (Windows, Linux, Mac)
- Which compiler? (GCC 7, Clang 13, ...)
Okay, I'm able to reproduce locally (that's the easy part):

```
% conan create all --version=1.2.0 -o "hiredis/*:with_ssl=True"

======== Exporting recipe to the cache ========
hiredis/1.2.0: Exporting package recipe: /Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/conanfile.py
hiredis/1.2.0: exports: File 'conandata.yml' found. Exporting it...
hiredis/1.2.0: Calling export_sources()
hiredis/1.2.0: Copied 1 '.py' file: conanfile.py
hiredis/1.2.0: Copied 1 '.yml' file: conandata.yml
hiredis/1.2.0: Copied 1 '.patch' file: 0002-fix-aix.patch
hiredis/1.2.0: Exported to cache folder: /Users/uilian/.conan2/p/hiredc0567340802e6/e
hiredis/1.2.0: Exported: hiredis/1.2.0#c4ebebdaa8ea15a37a64dfae9da8931a (2024-02-13 13:26:06 UTC)

======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=17
compiler.libcxx=libc++
compiler.version=15
os=Macos
[options]
hiredis/*:with_ssl=True

Profile build:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=17
compiler.libcxx=libc++
compiler.version=15
os=Macos


======== Computing dependency graph ========
Graph root
    cli
Requirements
    hiredis/1.2.0#c4ebebdaa8ea15a37a64dfae9da8931a - Cache
    openssl/3.2.1#b4eee5a6a5167d66ffd428ea790c631e - Cache
    zlib/1.3.1#af8f2ef3d8e0fddf1975281d7fe43bf6 - Cache
Resolved version ranges
    openssl/[>=1.1 <4]: openssl/3.2.1
    zlib/[>=1.2.11 <2]: zlib/1.3.1

======== Computing necessary packages ========
hiredis/1.2.0: Forced build from source
Requirements
    hiredis/1.2.0#c4ebebdaa8ea15a37a64dfae9da8931a:b785b6a05a8df1968fd4e28cee74e28c76b7aeca - Build
    openssl/3.2.1#b4eee5a6a5167d66ffd428ea790c631e:6c5be3e8c24780ce8840a294f99c0b01b1fd0686#6c2b99d4121e5a07284f25b3176b3017 - Cache
    zlib/1.3.1#af8f2ef3d8e0fddf1975281d7fe43bf6:2ee39e692ca4177b4b689b15bc1f2cfdf8f83706#449e4b6ca0875934a81a85489323ca4e - Cache

======== Installing packages ========
zlib/1.3.1: Already installed! (1 of 3)
openssl/3.2.1: Already installed! (2 of 3)

-------- Installing package hiredis/1.2.0 (3 of 3) --------
hiredis/1.2.0: Building from source
hiredis/1.2.0: Package hiredis/1.2.0:b785b6a05a8df1968fd4e28cee74e28c76b7aeca
hiredis/1.2.0: Copying sources to build folder
hiredis/1.2.0: Building your package in /Users/uilian/.conan2/p/b/hired3eef92a774b08/b
hiredis/1.2.0: Calling generate()
hiredis/1.2.0: Generators folder: /Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release/generators
hiredis/1.2.0: CMakeToolchain generated: conan_toolchain.cmake
hiredis/1.2.0: CMakeToolchain generated: CMakePresets.json
hiredis/1.2.0: CMakeToolchain generated: ../../../src/CMakeUserPresets.json
hiredis/1.2.0: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(OpenSSL)
    target_link_libraries(... openssl::openssl)
hiredis/1.2.0: Generating aggregated env files
hiredis/1.2.0: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
hiredis/1.2.0: Calling build()
hiredis/1.2.0: Apply patch (portability): support AIX build
hiredis/1.2.0: WARN: /Users/uilian/.conan2/p/hiredc0567340802e6/s/patches/0002-fix-aix.patch: file 1/1:	 b'fmacros.h'
hiredis/1.2.0: WARN: /Users/uilian/.conan2/p/hiredc0567340802e6/s/patches/0002-fix-aix.patch:  hunk no.1 doesn't match source file at line 4
hiredis/1.2.0: WARN: /Users/uilian/.conan2/p/hiredc0567340802e6/s/patches/0002-fix-aix.patch:   expected: b'#define _XOPEN_SOURCE 600'
hiredis/1.2.0: WARN: /Users/uilian/.conan2/p/hiredc0567340802e6/s/patches/0002-fix-aix.patch:   actual  : b'#ifndef _AIX'
hiredis/1.2.0: WARN: /Users/uilian/.conan2/p/hiredc0567340802e6/s/patches/0002-fix-aix.patch: already patched  b'fmacros.h'
hiredis/1.2.0: Running CMake.configure()
hiredis/1.2.0: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/Users/uilian/.conan2/p/b/hired3eef92a774b08/p" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/.conan2/p/b/hired3eef92a774b08/b/src"
Detected version: 1.2.0
-- Using Conan toolchain: /Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is AppleClang 15.0.0.15000100
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release

hiredis/1.2.0: Running CMake.build()
hiredis/1.2.0: RUN: cmake --build "/Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release" -- -j10
[ 10%] Building C object CMakeFiles/hiredis.dir/alloc.c.o
[ 20%] Building C object CMakeFiles/hiredis.dir/async.c.o
[ 30%] Building C object CMakeFiles/hiredis.dir/hiredis.c.o
[ 40%] Building C object CMakeFiles/hiredis.dir/read.c.o
[ 50%] Building C object CMakeFiles/hiredis.dir/net.c.o
[ 60%] Building C object CMakeFiles/hiredis.dir/sds.c.o
[ 70%] Building C object CMakeFiles/hiredis.dir/sockcompat.c.o
[ 80%] Linking C static library libhiredis.a
[ 80%] Built target hiredis
[ 90%] Building C object CMakeFiles/hiredis-test.dir/test.c.o
[100%] Linking C executable hiredis-test
[100%] Built target hiredis-test

hiredis/1.2.0: Package 'b785b6a05a8df1968fd4e28cee74e28c76b7aeca' built
hiredis/1.2.0: Build folder /Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release
hiredis/1.2.0: Generating the package
hiredis/1.2.0: Packaging in folder /Users/uilian/.conan2/p/b/hired3eef92a774b08/p
hiredis/1.2.0: Calling package()
hiredis/1.2.0: Running CMake.install()
hiredis/1.2.0: RUN: cmake --install "/Users/uilian/.conan2/p/b/hired3eef92a774b08/b/build/Release" --prefix "/Users/uilian/.conan2/p/b/hired3eef92a774b08/p"
-- Install configuration: "Release"
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/lib/libhiredis.a
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/build/native/hiredis.targets
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/hiredis.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/read.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/sds.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/async.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/alloc.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/sockcompat.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/redismoduleapi.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/glib.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/libev.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/libsdevent.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/ae.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/libevent.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/libhv.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/libuv.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/macosx.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/poll.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/qt.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/include/hiredis/adapters/ivykis.h
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/lib/pkgconfig/hiredis.pc
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/lib/cmake/hiredis/hiredis-targets.cmake
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/lib/cmake/hiredis/hiredis-targets-release.cmake
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/lib/cmake/hiredis/hiredis-config.cmake
-- Installing: /Users/uilian/.conan2/p/b/hired3eef92a774b08/p/lib/cmake/hiredis/hiredis-config-version.cmake

hiredis/1.2.0: package(): Packaged 1 file: COPYING
hiredis/1.2.0: package(): Packaged 18 '.h' files
hiredis/1.2.0: package(): Packaged 1 '.a' file: libhiredis.a
hiredis/1.2.0: Created package revision a24e9810d92e9165b171ac6b21435852
hiredis/1.2.0: Package 'b785b6a05a8df1968fd4e28cee74e28c76b7aeca' created
hiredis/1.2.0: Full package reference: hiredis/1.2.0#c4ebebdaa8ea15a37a64dfae9da8931a:b785b6a05a8df1968fd4e28cee74e28c76b7aeca#a24e9810d92e9165b171ac6b21435852
hiredis/1.2.0: Package folder /Users/uilian/.conan2/p/b/hired3eef92a774b08/p
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: hiredis/1.2.0, zlib/1.3.1, openssl/3.2.1
WARN: deprecated:     'cpp_info.build_modules' used in: openssl/3.2.1
WARN: deprecated:     'env_info' used in: openssl/3.2.1

======== Launching test_package ========

======== Computing dependency graph ========
Graph root
    hiredis/1.2.0 (test package): /Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/conanfile.py
Requirements
    hiredis/1.2.0#c4ebebdaa8ea15a37a64dfae9da8931a - Cache
    openssl/3.2.1#b4eee5a6a5167d66ffd428ea790c631e - Cache
    zlib/1.3.1#af8f2ef3d8e0fddf1975281d7fe43bf6 - Cache

======== Computing necessary packages ========
Requirements
    hiredis/1.2.0#c4ebebdaa8ea15a37a64dfae9da8931a:b785b6a05a8df1968fd4e28cee74e28c76b7aeca#a24e9810d92e9165b171ac6b21435852 - Cache
    openssl/3.2.1#b4eee5a6a5167d66ffd428ea790c631e:6c5be3e8c24780ce8840a294f99c0b01b1fd0686#6c2b99d4121e5a07284f25b3176b3017 - Cache
    zlib/1.3.1#af8f2ef3d8e0fddf1975281d7fe43bf6:2ee39e692ca4177b4b689b15bc1f2cfdf8f83706#449e4b6ca0875934a81a85489323ca4e - Cache

======== Installing packages ========
zlib/1.3.1: Already installed! (1 of 3)
openssl/3.2.1: Already installed! (2 of 3)
hiredis/1.2.0: Already installed! (3 of 3)
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: hiredis/1.2.0, zlib/1.3.1, openssl/3.2.1
WARN: deprecated:     'cpp_info.build_modules' used in: openssl/3.2.1
WARN: deprecated:     'env_info' used in: openssl/3.2.1

======== Testing the package ========
Removing previously existing 'test_package' build folder: /Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release
hiredis/1.2.0 (test package): Test package build: build/apple-clang-15-armv8-17-release
hiredis/1.2.0 (test package): Test package build folder: /Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release
hiredis/1.2.0 (test package): Writing generators to /Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release/generators
hiredis/1.2.0 (test package): Generator 'VirtualRunEnv' calling 'generate()'
hiredis/1.2.0 (test package): Generator 'CMakeToolchain' calling 'generate()'
hiredis/1.2.0 (test package): CMakeToolchain generated: conan_toolchain.cmake
hiredis/1.2.0 (test package): CMakeToolchain generated: CMakePresets.json
hiredis/1.2.0 (test package): CMakeToolchain generated: ../../../CMakeUserPresets.json
hiredis/1.2.0 (test package): Generator 'CMakeDeps' calling 'generate()'
hiredis/1.2.0 (test package): CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(hiredis)
    target_link_libraries(... hiredis::hiredis_all_unofficial)
hiredis/1.2.0 (test package): Generating aggregated env files
hiredis/1.2.0 (test package): Generated aggregated env files: ['conanrun.sh', 'conanbuild.sh']

======== Testing the package: Building ========
hiredis/1.2.0 (test package): Calling build()
hiredis/1.2.0 (test package): Running CMake.configure()
hiredis/1.2.0 (test package): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package"
-- Using Conan toolchain: /Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- The C compiler identification is AppleClang 15.0.0.15000100
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Conan: Component target declared 'hiredis::hiredis'
-- Conan: Component target declared 'hiredis::hiredis_ssl'
-- Conan: Target declared 'hiredis::hiredis_all_unofficial'
CMake Error at build/apple-clang-15-armv8-17-release/generators/cmakedeps_macros.cmake:67 (message):
  Library 'hiredis_ssl' not found in package.  If 'hiredis_ssl' is a system
  library, declare it with 'cpp_info.system_libs' property
Call Stack (most recent call first):
  build/apple-clang-15-armv8-17-release/generators/hiredis-Target-release.cmake:24 (conan_package_library_targets)
  build/apple-clang-15-armv8-17-release/generators/hiredisTargets.cmake:26 (include)
  build/apple-clang-15-armv8-17-release/generators/hiredis-config.cmake:16 (include)
  CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release/CMakeFiles/CMakeOutput.log".
See also "/Users/uilian/Development/conan/conan-center-index/recipes/hiredis/all/test_package/build/apple-clang-15-armv8-17-release/CMakeFiles/CMakeError.log".

ERROR: hiredis/1.2.0 (test package): Error in build() method, line 20
	cmake.configure()
	ConanException: Error 1 while executing

```

I'll investigate it.

Resolving patch:
diff --git a/recipes/hiredis/all/conanfile.py b/recipes/hiredis/all/conanfile.py
--- a/recipes/hiredis/all/conanfile.py
+++ b/recipes/hiredis/all/conanfile.py
@@ -56,9 +56,9 @@ def generate(self):
         # Since 1.2.0, BUILD_SHARED_LIBS has been defined by option()
         if Version(self.version) >= "1.2.0":
             tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
-        tc.variables["ENABLE_SSL"] = self.options.with_ssl
-        tc.variables["DISABLE_TESTS"] = True
-        tc.variables["ENABLE_EXAMPLES"] = False
+        tc.cache_variables["ENABLE_SSL"] = self.options.with_ssl
+        tc.cache_variables["DISABLE_TESTS"] = True
+        tc.cache_variables["ENABLE_EXAMPLES"] = False
         tc.generate()
         deps = CMakeDeps(self)
         deps.generate()


Test patch: