Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add static library to podspec

My podspec requires a static library (OpenSSL). For convenience, I'm shipping the library with the pod.

The static library contains:

  • Binaries: MyPod/openssl/bin/libcrypto.a and MyPod/openssl/bin/libsll.a
  • Headers: MyPod/openssl/include/openssl/*.h
  • Its own license (in addition to my project's license): MyPod/openssl/include/LICENSE

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?

like image 737
hpique Avatar asked Oct 20 '13 18:10

hpique


People also ask

What is Podspec in CocoaPods?

A specification describes a version of Pod library. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description. A stub specification file can be generated by the pod spec create command.

Are CocoaPods static or dynamic?

CocoaPods pod-linkage plugin. In SwiftKey, we have a dynamic framework that we use to share code between the app and the keyboard extension, and all the pods are linked statically except for some of them that are linked dynamically because they are linked to the app and keyboard extension too.


2 Answers

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.

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 

The resulting subspec would be:

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 

Line by line:

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' 

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' 

Includes the libraries in "Other Linker Flags".

openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/libraries/openssl-1.0.1e/include/**" } 

Tells the project where to find the headers. We cannot use public_header_files because this is a subspec.

like image 198
hpique Avatar answered Sep 19 '22 18:09

hpique


You can try do it like it's done here https://github.com/krzak/OpenSSL, or just use this Pod with you project if you find it convienence

pod 'OpenSSL', :podspec => 'https://raw.github.com/krzak/OpenSSL/master/OpenSSL.podspec' 
like image 32
Marcin Avatar answered Sep 20 '22 18:09

Marcin