将静态库添加到podspec [英] Add static library to podspec
问题描述
我的podspec需要一个静态库(OpenSSL)。为方便起见,我发布了带有pod的库。
My podspec requires a static library (OpenSSL). For convenience, I'm shipping the library with the pod.
静态库包含:
- 二进制文件:
MyPod / openssl / bin / libcrypto.a
和MyPod / openssl / bin / libsll.a
- 标题:
MyPod / openssl / include / openssl / *。h
- 它自己的许可证(除了我的项目许可证):
MyPod / openssl / include / LICENSE
- Binaries:
MyPod/openssl/bin/libcrypto.a
andMyPod/openssl/bin/libsll.a
- Headers:
MyPod/openssl/include/openssl/*.h
- Its own license (in addition to my project's license):
MyPod/openssl/include/LICENSE
在我的podspec中表达这个的正确方法是什么?我见过各种使用以下属性组合的示例,我正在尝试不同的组合:
What is the proper way of expressing this in my podspec? I've seen various example that use combinations of the following properties and I'm currently trying different combinations:
source_files
public_header_files
private_header_files
preserve_paths
libraries
xcconfig
vendored_libraries
甚至更好,我可以在子规范中定义这个静态库吗?
Or even better, can I define this static library in a subspec?
推荐答案
我设法添加了静态库为 subspec
。我更喜欢这种方法,因为它默认使用我的pod附带的版本,并且还允许用户在他们想要的时候提供他们自己的版本。
I managed to add the static library as a subspec
. I prefer this approach because it uses the build shipped with my pod by default, and also enables users to provide their own build if they so desire.
如上所述,静态库是OpenSSL,但以下内容适用于任何静态库。我正在使用以下目录结构:
As mentioned, the static library is OpenSSL but the following applies to any static library. I'm using the following directory structure:
libraries/openssl-1.0.1e/include/openssl/*.h
libraries/openssl-1.0.1e/LICENSE
libraries/openssl-1.0.1e/lib/*.a
得到的子规则是:
s.subspec 'OpenSSL' do |openssl|
openssl.preserve_paths = 'libraries/openssl-1.0.1e/include/openssl/*.h', 'libraries/openssl-1.0.1e/include/LICENSE'
openssl.vendored_libraries = 'libraries/openssl-1.0.1e/lib/libcrypto.a', 'libraries/openssl-1.0.1e/lib/libssl.a'
openssl.libraries = 'ssl', 'crypto'
openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/libraries/openssl-1.0.1e/include/**" }
end
逐行:
openssl.preserve_paths = 'libraries/openssl-1.0.1e/include/openssl/*.h', 'libraries/openssl-1.0.1e/include/LICENSE'
保留标头和许可证文件。我们将使用下面的标题。
Preserve headers and the license file. We will use the headers below.
openssl.vendored_libraries = 'libraries/openssl-1.0.1e/lib/libcrypto.a', 'libraries/openssl-1.0.1e/lib/libssl.a'
告诉CocoaPods我们是在pod中运送上述静态库。这将保留文件,并相应地修改 LIBRARY_SEARCH_PATHS
。
Tell CocoaPods that we are shipping the above static libraries in the pod. This will preserve the files, as well as modifying LIBRARY_SEARCH_PATHS
accordingly.
openssl.libraries = 'ssl', 'crypto'
包含Other Linker Flags中的库。
Includes the libraries in "Other Linker Flags".
openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/libraries/openssl-1.0.1e/include/**" }
告诉项目在哪里找到标题。我们不能使用 public_header_files
,因为这是 subspec
。
Tells the project where to find the headers. We cannot use public_header_files
because this is a subspec
.
这篇关于将静态库添加到podspec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!