How to use OpenSSL with swift in a framework target - xcode

Since Bridging, Headers are not supported in framework targets,
I've tried to import OpenSSL headers in the framework umbrella header. But the headers need to be public and I don't know how to make them public. I've added the OpenSSL framework as a reference folder. So my question is how to make them public?
Another approach I've been trying to add a file called "module.modulemap", which as the name implies creates a swift module that can be imported to be used by the framework. I can build my framework target successfully, but when I try to build my OSX Application which uses my framework, a swift error pops up saying that it cannot find the OpenSSL headers.
I've worked around this issue by adding to the OSX Application build settings headers search path, the path for OpenSSL headers it works. Not sure what is going on here, can someone explain why is this happening and a suggestion for best practice on how to achieve using swift with open SSL in a framework?
This is the contents of the modulemap file:
module OpenSSL [system] {
header "../OpenSSL/include/openssl/pkcs7.h"
header "../OpenSSL/include/openssl/objects.h"
header "../OpenSSL/include/openssl/ssl.h"
header "../pkcs7_union_accessors.h"
link "ssl"
link "crypto"
}

Related

Adding CommonCrypto to custom Swift framework

I’m building a Swift framework which seems relatively simple. Then I needed to import CommonCrypto.
In the framework’s .h file I added the line
#import <CommonCrypto/CommonCrypto.h>
and included Security.framework in Link Binary with Libraries for the framework’s target.
When I build I get the following build error:
Include of non-modular header inside framework module ‘MyKit'
I’ve tried changing the Allow Non-modular Includes In Framework Modules to YES and NO and tried every combination for both the framework target and the project with no luck.
The MyKit.h’s Target Membership is set to Public and is ticked for MyKit too.
In Xcode 10.0 you'll be able to import CommonCrypto. As a work around I suggest inverting that dependency with a protocol and importing CommonCrypto in your framework client.

Using libusb in open frameworks on OS X

I wanted to try some things with openFrameworks but got stuck trying to use libusb, which is not available as of addon.
I copied it in the "other" folder but don't no how to include it in the project.
The included ofxKinect addon includes compiled libusb and headers. If you add that add-on via the project generator, you'll have access to libusb.

Add dynamic library to firebreath

I'm developing a plugin for mac. I'm trying to use afnetworking and other frameworks which needs arc. I'm trying to create a .a(library) for the framework and access it in firebreath. I tried adding the directory which contains .a using include_directories in projectdef.cmake then linking it in target_link_libraries. Please lemme know how to add this and whether the framework can be used in firebreath without any pitfalls
I have used external libraries in firebreath. Though I have used editors to link the libraries. You need to specify .h files for the function prototypes, along with .a files which will dynamically link to .dylib
Try adding these via Xcode and see if that works.

Using header files from the static library in project

I'm developing application in OSX 10.9 and Xcode 5.0.2
I'm using making workspace. It separates on two parts. Static library and bundle application.
Bundle application should link static library and includes headers for the static library which I added to the Public header group in the Build Phase of the Target. Also I've prescribed $(PRODUCT_BUILD_DIR)/usr/local/include in the header search path of the bundle app.
But problem - bundle app target doesn't see header files of static library target.
I found answer. Predefined path was set as user header search path but in code I used #import "" instead of #import <>. So right answer - use proper import syntax.

Step into OpenSSL code using XCode 4.3.2

I found this project on the internet: https://github.com/x2on/OpenSSL-for-iPhone.
It has a demo app which calculates MD5 values and takes text input from an editbox. Within the demo app I can step into the OpenSSL code which calculates the MD5 value.
I am using XCode 4.3.2. I have a project which also uses OpenSSL. Within the project something goes wrong with the SSL handshake (this code is executed within OpenSSL).
Though I have built the libraries (libcrypto.a and libssl.a) using the build script from "x2on" and added these libraries to my project I am unable to step into calls to OpenSSL methods from within my own project.
Also I could not discover any relevant setting which is present in the demo app (from "x2on") when I compare the settings with my own app. If I try to step into the OpenSSL call, then execution just moves on to the next line (I do not get into .asm code and also not in the OpenSSL code). Also if I use the right mouse button and choose "Jump to Definition" it brings me to the OpenSSL header file instead of the implementation (.c).
Could somebody give some hints here? How is "stepping into" supposed to work in general? Do the libraries (.a) contains a reference to the location of the source code? Where can you set the search path for source code in XCode? How can you enforce that XCode will re-index the code including the OpenSSL code and make "Jump to Definition" work?
Any help is appreciated as I did discover more people who are or have been struggling with this problem.
ADDITION:
I created a small test app, added libcrypto.a and libssl.a to the Frameworks folder and included the path to the header files for OpenSSL into the Build Settings | Header Search Paths. No problem to step into a piece of OpenSSL code/methods ...
However, when I apply the same strategy to my huge project, then it steps over the OpenSSL call instead of stepping into the OpenSSL call ... I heard that each project should reference a static library only once? If the project references a static library multiple times, then would this break the functionality to step into the code of that library ...?
Forgot to add: for the small test app there was no need to indicate the location of the source files for OpenSSL. So my tentative conclusion is that the .a libs contain a reference to the source files for OpenSSL (how could XCode otherwise know the location of the source files?).
To share some further information: both in my huge project and in the test application it is not possible to jump to the source code by selecting "Jump to Definition". So stepping into the code and "Jump to Definition" seem/are unrelated.

Resources