[futurebasic] Re: Private Frameworks with FB5

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2009 : Group Archive : Group : All Groups

From: Dave Warker <dave@...>
Date: Wed, 11 Nov 2009 12:08:07 -0500
Robert P. wrote:
> I don't think anyone has attempted to include a framework in an FB5  
> build. Try along these lines.
> [1] Tell FB5 to put Foo.framework inside the app, at <app_name>/ 
> Contents/Resources/.
> include resources "Foo.framework"
> [2] Get the function pointers as you do currently.
> dim as pointer  gBar
> gBar = fn MyGetFuncPointer( "Bar" ) // or whatever
> [3] Instead of horrible FB4 assembler glue, simply declare prototypes  
> for your functions, with a 'using' clause to specify the function  
> pointer.
> def fn Bar( param as SomeType ) as SomeOtherType using gBar
> Your framework will be in <app_name>/Contents/Resources/ instead of  
> <app_name>/Contents/Frameworks/, which may or may not be a problem.

Thanks for your response Robert, very much appreciated. I didn't know about the "using" syntax for function declarations, that's nice!

I've been doing some experimenting and discovered that I don't have to manually fetch the function pointers from the bundle. It is possible to link directly against the framework in FB5 and include it in the application bundle. Here's what worked for me:

[1] Copy Foo.framework into the project folder

[2] Add 'include resources "Foo.framework"' to copy it into the app's Resources folder.
(Just dragging the framework into the project's Resources group also works.)

[3] Add 'include library "Foo"'
So FB5 includes the dependency on Foo.framework along to the C compiler by adding a '-framework Foo' argument to the compiler invocation. This also does an implicit #include <Foo/Foo.h>.

[4] Add TOOLBOX and TOOLBOX FN definitions for the framework functions you want to use and declare any special constants and datatypes with the corresponding FB datatypes.

[5] In the FB5 Build Settings dialog add the string "-F../" (dash, capital F, period, period, slash) to More compiler options. The "-F" adds a path to the list of folders where the compiler looks for frameworks. The compiler is invoked with build_temp as the current directory so this option tells the compiler to look one level up, in the project folder, for additional frameworks.

Build and go and you should be all set. It links directly against the framework with no glue or special declarations needed. Steps 3, 4 and 5 can be wrapped in a handy FB5 include file to simplify re-using the framework in other projects.

One restriction though: the framework *must* be explicitly built to run from the Resources folder. You'd normally build a private framework in Xcode with an Installation Directory setting of "@executable_path/../Frameworks" so it runs from the app's Frameworks folder. That must be changed to "@executable_path/../Resources" so the OS knows where to find it when the app launches. This would be a problem if you can't build your own copy of the framework but in my case that's not an issue.

This approach has worked out well for my current needs. If private frameworks are something more people want to use I think proper support could be added with just a few minor changes to FB5:

- The "include library" command could look in the project folder to see if the framework exists there, or support a syntax like "include local library" to make it explicit. The -F flag could then be automatically passed to the compiler. It could also assume it should be included in the app and copy it to Frameworks (or Resources or PrivateFrameworks as appropriate by extracting the installation path from the framework executable.)

- Or FB5 could support an explicit Frameworks group in the project window as it does for Resources. Adding a framework to that group would trigger a copy to the corresponding folder in the app bundle and setting the -F option.

I know I'm throwing a lot up in the air here but hopefully someone else will find this useful.

Dave Warker <dave@...>