Mavro
Mavro

Reputation: 571

Embedding Frameworks from SwiftPM into Cocoa Application (XCODE)

I'm using a project called "HAP" (https://github.com/Bouke/HAP) that is built using SwiftPM.

The included example "HAP-server", works great from Command Line and I have used the params "swift package generate-xcodeproj" to create an XCODE project.

I can also load the HAP in XCODE and build/debug the target "HAP-server".

I'd like to use this framework in my Cocoa Application and have added the HAP.xcodeproj into my project. I added the produced files as "Embedded Binaries" and "Linked Frameworks and Libraries".

That allows me to "import HAP" into my view controller class. enter image description here

However, when I try to build my Cocoa target, I get the following message -- seems related to the dependency "Kitura-net" from the HAP project...

"Missing required modules: 'CCurl', 'CHTTPParser'"

enter image description here enter image description here

What is the best way to use frameworks from a SwiftPM in my project?

I assume it has something to do with Search headers... anyone have an idea?

UPDATE #1:

I have tried adding to my Cocoa Project that is importing the library that is using Kitura by "Link Binary With Libraries", libcurl.4.dylib from usr/lib/ but it still gives me the same error.

enter image description here

UPDATE #2:

enter image description here

UPDATE #3

I ended up figuring it out by using this method: Importing CommonCrypto in a Swift framework

I needed to create a modulemap for each of the items it was throwing a fit about, in my case: CCURL & CHTTPParser. Once I did that, I could compile.

Upvotes: 2

Views: 712

Answers (1)

Vadim Eisenberg
Vadim Eisenberg

Reputation: 3427

You can see an example of embedding Kitura in an Xcode project in this repo https://github.com/IBM-Swift/Kitura-HelloWorld-iOS. Makefile in this repo runs build scripts to fix an Xcode Project to run Kitura on iOS. You need to compile curl for iOS - see instructions in the README.

From what I remember, you need to add the directory with curl headers to Header Search Paths, the directory with libcurl.a to Library Search Paths, and also add -lz flag to Other Linker Flags.

Upvotes: 1

Related Questions