【问题标题】:How to get right values from requirements in Conan recipe to be used as CMake parameters?如何从柯南食谱中的要求中获取正确的值以用作 CMake 参数?
【发布时间】:2017-08-29 14:42:22
【问题描述】:

我正在编写为rabbitmq-c 库创建包的方法。当 cmake中 enable_sl_support 选项时,检查它需要 openssl 库的构建。

如提供的屏幕路径所示,指向 libeay.libssleay.libDebugRelease 版本> 文件是必需的。

在我的conanfile.py for rabbitmq-c 库中,我有以下描述依赖关系的代码。

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

如何从所需的 OpenSSL 包中获取正确的值以在 CMake 配置选项中为 RabbitMQ-C 配方设置它们?

OpenSSL/1.0.2l@bobeff/stable 可以使用不同的设置和选项构建。在构建 RabbitMQ-C 时如何选择使用哪个?例如,如何选择静态或动态版本的 OpenSSL 用于链接 RabbitMQ-C dll 文件?

【问题讨论】:

  • 如果你的意思是,如何访问依赖模型,从消费者配方 (RabbitMQ) 你可以通过self.deps_cpp_info["OpenSSL"] 访问它。该对象将包含include_pathslib_paths 等的信息。您可以查看:conanio.readthedocs.io/en/latest/integrations/other.html。请告诉我这是否有意义,我将详细说明一个扩展答案
  • @drodri +1 10x 这很有意义,但这里还需要两个不同的 OpenSSL 包。一个用于调试,一个用于发布。现在我正在为 RabbitMQ-C 的 Debug 和 Release 变体创建不同的包,因此我可以使用相同的值,但是如果我要为 RabbitMQ-C 的调试和发布版本创建一个包,如何处理这个问题?

标签: c cmake conan rabbitmq-c


【解决方案1】:

您可以完全访问 build() 方法中的依赖模型,因此您可以访问:

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)

此外,如果您想访问聚合值(针对所有依赖项/要求),您可以这样做:

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

因此,鉴于这些值,您可以将它们传递给您的构建系统,对于 CMake,您可以执行以下操作:

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]

这将被转换为包含-DSSL_INCLUDE_PATH=<path to openssl include> 标志的 cmake 命令。

如果您选择多配置包,可以查看 (http://docs.conan.io/en/latest/packaging/package_info.html#multi-configuration-packages)。他们将定义debug, release 配置,您以后也可以在模型中使用:

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

【讨论】:

  • 如果 OpenSSL 不是多配置包,而是在我正在创建的包配方中,我需要 OpenSSL 的调试和发布版本怎么办?
  • 这在模型中是不可能的。一些技巧可能是可能的,例如使用cmake_multi 生成器并安装调试和发布依赖项,但这很复杂且容易出错。所以基本上,多配置必须在依赖图中保持一致,如果你正在构建的包是多配置的,那么依赖关系必须是多配置的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-05
  • 2017-08-09
  • 2021-12-15
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多