Wrapping an existing C library as a Framework

Viewed 261

I am trying to find a way of wrapping an existing C library with an Apple .framework structure. The key sticking point is avoiding the need to specify the Search Headers field in Settings.

Typically in a framework you specify something like:

#import <Foundation/Foundation.h>

where Foundation is the framework name and the .h file is an umbrella header.

When testing with existing code, for the sake of argument OpenSSL, the project is using #include <openssl/file.h> internally to refer to its files. Once you want to place this inside a framework for convenience every include naturally needs to be changed to <NameOfFramwork/openssl/file.h> or you must add the $(SRCROOT)/Path/To/Frameworks/NameOfFramework.framework/Headers to the search path. This is terribly inconvenient and kills a lot of the value of the framework format. It only becomes worse when you want to wrap multiple SDK versions of the library in an XCFramework.

I'm wondering specifically if the ModuleMap can help avoid the need to change the #includes? I've added a modulemap I'm creating as a test.

Experimental module.modulemap

framework module LibreSSL [extern_c] {
    umbrella header "LibreSSL.h"
    export *
    module * { export * }
    
    explicit module LibreSSL_Private [extern_c] {
        umbrella "Headers/include"
        link "LibreSSL"
        export *
    }
}
1 Answers

One unsatisfying solution is to switch to an XCFramework comprised of Libraries instead of Frameworks.

xcodebuild \
    -create-xcframework \
    -library <path/to/library> \
    -header <path/to/headers> \
    -output MyCool.xcframework

Then header search paths work correctly, but you lose the .modulemap and the nice framework structure that keeps everything together neatly per SDK build.

Related