OSX, Xcode 4, Framework

From Allegro Wiki

Jump to: navigation, search

Compiling Allegro and creating the Allegro frameworks

Hopefully pre-compiled and ready to use Allegro frameworks can be downloaded soon, then you can skip this step of getting the Allegro sources and compiling them yourself.

For now you roughly will have to run the following commands from the Terminal. And additionally get a lot of dependencies for the addons.

git clone git://git.code.sf.net/p/alleg/allegro
cd allegro

At this point, you must decide whether to use the allegro 5.0 or 5.1 frameworks. For Allegro-5.0 frameworks, use the following terminal command:

git checkout 5.0

5.1 is the default install, so you can skip that step if you wish.

mkdir build
cd build

At this point, you can either use make or Xcode to compile the source code. Both options should produce the same result.

  • Option 1, use xcode
cmake -G Xcode -DWANT_FRAMEWORKS=1 - ..
xcodebuild
sudo xcodebuild install
  • Option 2, use make
cmake -DWANT_FRAMEWORKS=1 ..
make
sudo make install
  • Dependencies

As for dependencies, you can create a folder named "deps" inside the build folder and put dependencies inside. That is the actual library and header files of the dependencies will be in build/deps/lib and build/deps/include. The cmake build script has those paths hardcoded and will find dependencies there.

Also you can use cmake-gui instead of cmake to adjust additional setting before running make - for example if you want your frameworks to be 32-bit set the CMAKE_OSX_ARCHITECTURES variable to i386. However it means your dependencies also must be 32-bit. Similarly for universal applications you need all dependencies as universal apps and then set all the architectures you want, for example "i386 x86_64" (this will also be the default otherwise).

  • Make sure all frameworks have been installed to /Library/Frameworks (or any other location, it's just what we will use in the following). You can also just leave them in the build folder.

Using the Frameworks

  • Start XCode, create a new empty project (Other->Empty)
  • Add a Cocoa Application target to the project, let's call it MyGame. (Click your project, then the + button at the bottom saying Add target, then Mac OSX->Application->Cocoa.)
  • Select the MyGame target, go to the Build Phases tab and add a new Copy Files Build Phase (+ button down right).
    • Select Frameworks from the dropdown
    • Leave Subpath blank
    • We leave this build phase empty for now, just was a good time to create it.
  • Select the Build Settings tab then:
    • Note: You can change display from Basic to All at the top and use the search box to locate the following settings
    • Change Header Search Paths to (just copy&paste): /Library/Frameworks/Allegro-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroMain-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroAcodec-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroAudio-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroColor-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroDialog-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroFont-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroImage-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroMemfile-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroPhysfs-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroPrimitives-5.0.framework/Versions/Current/Headers /Library/Frameworks/AllegroTTF-5.0.framework/Versions/Current/Headers
      • This is needed to have cross-platform code (#include <allegro5/allegro.h> working - otherwise paths like using #include <Allegro-5.0/allegro5/allegro> would work without changing the search path)
      • If you use another location, one way to save on typing is to double click the input field, then navigate to the Headers folder in each framework and drag it into the xcode input list
    • Delete Prefix Header (Edit->Delete)
      • You can of course use your own prefix headers - but the default Cocoa one will only work with objective C projects that's why we remove it, assuming MyGame is a cross-platform C/C++ project
    • In Framework Search Paths add the location of your frameworks (e.g. /Library/Frameworks).
  • Add all the Allegro frameworks as follows (this can be done in many ways, a group just keeps things tidy):
    • Select the Summary tab
    • Click the + button under Linked Frameworks and Libraries and add all the Allegro frameworks
      • In case they are not listed use the Add Other button and navigate to /Library/Frameworks to find them
    • Go to the Build Phases tab, then in the list to the left select all the Allegro frameworks and drag them to the Copy Files entry which we added before
    • Select all the frameworks again and this time drag them to the Frameworks group to the left (just to have things more tidy)
  • Don't forget to remove the created source files under MyGame and add your own source code instead (note the main.m in Supporting Files for example)
    • Here's a minimal test showing a yellow window for a few seconds
#include <allegro5/allegro.h>
 
int main(int argc, char **argv) {
   al_init();
   al_create_display(640, 480);
   al_clear_to_color(al_map_rgb_f(1, 1, 0));
   al_flip_display();
   al_rest(5.0);
   return 0;
}
  • Compile - It should compile without errors.
  • Run - Should just run your program.
  • Distribute - The resulting .app file should be ready for distribution, with Allegro frameworks embedded. You probably want to package it up as a .pkg file in the usual way, nothing Allegro specific needed.
Personal tools
Adsense