How to get right values from requirements in Conan recipe to be used as CMake parameters?

958 views Asked by At

I'm writing recipe for creating package for rabbitmq-c library. When ENABLE_SSL_SUPPORT option in its CMake script is checked it requires OpenSSL library for its build.

RabbitMQ C client library CMake GUI screen

As it shown on provided screen paths to Debug and Release versions of libeay.lib and ssleay.lib files are required.

In my conanfile.py for rabbitmq-c library I have the following code which describes the dependency.

def requirements(self):
    if self.options.ssl_support:
        self.requires("OpenSSL/1.0.2l@bobeff/stable")

How to get right values from required OpenSSL package to set them in CMake configure options for RabbitMQ-C recipe?

The package OpenSSL/1.0.2l@bobeff/stable can be build with different settings and options. How to choose which to be used when I'm building RabbitMQ-C? For example how to choose whether static or dynamic version of OpenSSL to be used for linking with RabbitMQ-C dll files?

1

There are 1 answers

2
drodri On BEST ANSWER

You have full access to the dependencies model inside your build() method, so you can access:

def build(self):
    print(self.deps_cpp_info["OpenSSL"].rootpath)
    print(self.deps_cpp_info["OpenSSL"].include_paths)
    print(self.deps_cpp_info["OpenSSL"].lib_paths)
    print(self.deps_cpp_info["OpenSSL"].bin_paths)
    print(self.deps_cpp_info["OpenSSL"].libs)
    print(self.deps_cpp_info["OpenSSL"].defines)
    print(self.deps_cpp_info["OpenSSL"].cflags)
    print(self.deps_cpp_info["OpenSSL"].cppflags)
    print(self.deps_cpp_info["OpenSSL"].sharedlinkflags)
    print(self.deps_cpp_info["OpenSSL"].exelinkflags)

Also if you want to access the aggregated values (for all the dependencies/requirements), you can do:

def build(self):
   print(self.deps_cpp_info.include_paths)
   print(self.deps_cpp_info.lib_paths)
   ...

So, given those values, you can pass them to your build system, in the case of CMake you could do something like:

def build(self):
    cmake = CMake(self)
    # Assuming there is only 1 include path, otherwise, we could join it
    cmake.definitions["SSL_INCLUDE_PATH"] = self.deps_cpp_info["OpenSSL"].include_paths[0]

That will be translated to a cmake command including the -DSSL_INCLUDE_PATH=<path to openssl include> flag.

If you go for multi-configuration packages, you can check (http://docs.conan.io/en/latest/packaging/package_info.html#multi-configuration-packages). They will define debug, release configs, that you can also later use in your model:

def build(self):
    # besides the above values, that will contain data for both configs
    # you can access information specific for each configuration
    print(self.deps_cpp_info["OpenSSL"].debug.rootpath)
    print(self.deps_cpp_info["OpenSSL"].debug.include_paths)
    ...
    print(self.deps_cpp_info["OpenSSL"].release.rootpath)
    print(self.deps_cpp_info["OpenSSL"].release.include_paths)
    ...