将Conan和Cocoapods一起使用 /合并两个XCCONFIG文件

发布于 2025-01-22 10:42:36 字数 488 浏览 4 评论 0原文

我有一个C ++库,我使用[conan] https://conan.io 来管理库依赖项。我想在React Native应用程序中使用该库。为了使用本机模块桥,您需要使用[cocoapods] https://cocoapods.orgs.org 。 Cocoapods和Conan都想在Xcode中设置XCCONFIG以配置搜索路径。有什么方法可以合并两者,或者使用两个工具组合使用?现在,我将合并文件合并,这些文件有效,但显然不是理想的。

我宁愿不要将所有内容切换到可可录,因为此库将在iOS/可可以外的其他平台上使用。另外,我依赖的库都是基于自动工具的,并且在柯南中更容易处理。另外,还有一种简单的方法可以将柯南包装在可可录中吗?

I have a C++ library that I've written using [Conan]https://conan.io to manage library dependencies. I'd like to use that library in a React Native app. In order to use the Native Modules Bridge, you need to use [CocoaPods]https://cocoapods.org. Both CocoaPods and Conan want to set an xcconfig in XCode to configure search paths. Is there any way to merge the two, or to use both tools in combination? Right now I'm hand merging the files, which works but is obviously not ideal.

I'd rather not switch everything over to CocoaPods, as this library will be used on platforms other than iOS/Cocoa. Also, the libraries I depend on are all autotools based and are a lot easier to deal with in Conan. Alternatively, is there an easy way to wrap a Conan package in CocoaPods?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戈亓 2025-01-29 10:42:36

我最终通过制作了一个当地的可可录podspec来解决此问题,该podspec刚刚结束了柯南项目并为此产生了可可蛋白狗。在我的情况下,这效果很好,因为我只需要一个柯南的依赖。我想我还可以制作一个柯南项目,该项目只能输出所需的所有标题和库,如果我需要更多的库,这可能会很好。我确实在我的柯南软件包中添加了一个选项,以将所有因库复制到构建文件夹中,因此我也不必为它们制作单独的豆荚。这大约是我的podspec的外观:

Pod::Spec.new do |spec|
    spec.name = "Project"
    spec.summary = "..."
    spec.homepage = 'https://github.com/...'
    spec.authors = "..."
    spec.license = { :type => 'LGPL' }
    spec.source = { :git => 'https://github.com/...' }

    spec.version = "0.0.1"
  
    spec.platform = :ios
    spec.ios.deployment_target = '12.0'
  
    spec.prepare_command = <<-CMD
    conan install . -if build_ios-sim -pr:b=default -pr:h=ios-sim -b=missing -o copy_libs=True
    conan build . -bf build_ios-sim
    conan install . -if build_ios -pr:b=default -pr:h=ios -b=missing -o copy_libs=True
    conan build . -bf build_ios
    mkdir lib
    for i in build_ios-sim/lib/*.a; do
      f=`basename "$i"`
      ls {build_ios,build_ios-sim}/lib/"$f"
      lipo -create -output "lib/$f" {build_ios,build_ios-sim}/lib/"$f"
    done
    mkdir include
    cp src/libname.h include/
  CMD
  
    spec.source_files = "include/*.h"
    spec.ios.vendored_libraries = "lib/*.a"
    spec.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
    spec.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
  end
  

这种技术比将柯南直接整合到Xcode中的优势是您可以生产通用库。我认为我已经正确使用了Lipo来做到这一点,尽管我实际上还没有部署到iOS设备来测试它。

I ended up solving this by making a local CocoaPod podspec that just wraps up the Conan project and produces a CocoaPod for it. This worked well in my case, since I only need the one Conan dependency. I suppose I could have also produced a Conan project that just outputs all of the headers and libraries needed, which would probably work well if I needed more libraries. I did add an option to my Conan package to copy ("import") all of the dependent libraries into the build folder so I don't have to make separate pods for them too. Here's roughly what my podspec looks like:

Pod::Spec.new do |spec|
    spec.name = "Project"
    spec.summary = "..."
    spec.homepage = 'https://github.com/...'
    spec.authors = "..."
    spec.license = { :type => 'LGPL' }
    spec.source = { :git => 'https://github.com/...' }

    spec.version = "0.0.1"
  
    spec.platform = :ios
    spec.ios.deployment_target = '12.0'
  
    spec.prepare_command = <<-CMD
    conan install . -if build_ios-sim -pr:b=default -pr:h=ios-sim -b=missing -o copy_libs=True
    conan build . -bf build_ios-sim
    conan install . -if build_ios -pr:b=default -pr:h=ios -b=missing -o copy_libs=True
    conan build . -bf build_ios
    mkdir lib
    for i in build_ios-sim/lib/*.a; do
      f=`basename "$i"`
      ls {build_ios,build_ios-sim}/lib/"$f"
      lipo -create -output "lib/$f" {build_ios,build_ios-sim}/lib/"$f"
    done
    mkdir include
    cp src/libname.h include/
  CMD
  
    spec.source_files = "include/*.h"
    spec.ios.vendored_libraries = "lib/*.a"
    spec.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
    spec.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
  end
  

One advantage of this technique over integrating Conan directly into XCode is that you can produce universal libraries. I think I've used lipo correctly to do that, though I haven't actually deployed to an iOS device yet to test it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文