2

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.

Mavro
  • 571
  • 8
  • 19

1 Answers1

1

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.

Vadim Eisenberg
  • 3,337
  • 1
  • 18
  • 14
  • Will give that a try -- I'm assuming this process will work for a MacOS Cocoa app -- I don't need it for my iOS project (I have a multi-target project) -- this is just for the MacOS app... I see it generates x64 bits so I should be ok. – Mavro Nov 08 '17 at 15:46
  • I'm closer!! It compiled the bits for iOS -- but I need MacOS -- is there a doBuildCurl.sh with MacOS platforms? – Mavro Nov 08 '17 at 17:18
  • For MacOS libcurl should be already installed, no need to build it. The library should be in `/usr/lib/libcurl.dlyb`, the headers in `/usr/include/curl`. – Vadim Eisenberg Nov 08 '17 at 18:00
  • Thanks for the quick response -- I think we're almost there -- so how exactly do I import that library? Do I do it In my cocoa application project or the HAP project that is utilizing the Kitura framework? Any projects that illustrate this? I have updated the main post above with a screenshot of where I "Link Binary With Libraries" adding, libcurl.4.dylib -- still no dice! – Mavro Nov 08 '17 at 19:39
  • I think you should add the library to the both projects. When we embed Kitura n iOS projects, we add the curl library to `Library Search Paths`, its headers to `Header Search Paths`, and also specify `-lz` in `Other Linker Flags`. – Vadim Eisenberg Nov 08 '17 at 20:10
  • OK -- did that still same error -- I think the only different I see between the iOS and my example is that there is target of CCurl (see above) -- how do I replicate that in my project? – Mavro Nov 08 '17 at 20:19
  • Another option could be to run the scripts in https://github.com/IBM-Swift/Kitura-Builder-iOS that will create an Xcode Workspace with your project and HAP, instead of running Cocoa Pods. In your case HAP is the ServerSide and your project is the ClientSide, for SharedServerClientProject just create some empty Xcode project. You can change the libcurl parameters in https://github.com/IBM-Swift/Kitura-Builder-iOS/blob/master/Scripts/constants.rb . Then you can run https://github.com/IBM-Swift/Kitura-Builder-iOS/blob/master/Scripts/fixXcodeProjects.sh. – Vadim Eisenberg Nov 08 '17 at 21:57
  • I got it working -- will update above but the issue is that my Cocoa project could see the modulemap for Curl, CHTTPParser, etc. I had to create those in my app and now it compiles... not sure there is an easier way/automated way, but it's now working! – Mavro Nov 08 '17 at 22:08
  • Congratulations! – Vadim Eisenberg Nov 08 '17 at 22:14