Skip to content

Building with XCode

Tommaso Checchi edited this page Jul 9, 2014 · 1 revision

Building with XCode should be pretty straightforward, with everything set up correctly. Just try to not stumble into those XCode moments where nothing will work for no reason at all. And if in doubt, Clean and rebuild!

Caution May contain C++11: to build correctly against the dependencies you will need the latest XCode (at the time of writing, 4.6). Download it from the App Store!

Setting up

  • First, get the source code (be it from hg, or downloading a source package) and place it in a folder that we'll call dojo from now on.
  • download the OSX/iOS https://bitbucket.org/tommo89/dojo/downloads from the download page, and place them in dojo/.

Now, you have two ways to go: you can either drop Dojo into your game's XCode workspace, or you can use dojo/dojo.xcodeproj to build it once and for all like any other dependency.

Integrating with your project

  • Create a new Cocoa Application project, and follow the wizard. Other templates will change in subtle ways so I can't guarantee that they'll work with this guide, but feel free to try.
  • Optional: add Dojo.xcodeproj to your workspace; this way it will be auto-rebuilt each time it changes (eg- hg update).
  • Now, drag libdojo-osx.a or libdojo-ios.a}}} to your project Build Phases, in Link Binary with Libraries; this will ensure that your game is linked against Dojo. If you included Dojo in your workspace, drag the libdojo-*.a found in the Products filter, this will tell XCode that your project depends on that.
  • Still in the Link Binary with Libraries section, click "+" and add OpenAL and OpenGL to your project.
  • Go to the "Build Settings" tab, look for "Header Search Paths" and add (your-dojo-dir)/include and (your-dojo-dir)/dependencies-OSX/include to the field (obviously switch iOS with OSX when building for iOS)
  • And as a last thing, you will need to enable the newest runtime on XCode: look for C++ Standard Library, and set it to libc++

Now hit build, and it should compile and link! :D

Adding assets to your app

Adding assets that Dojo can find is no different from adding them to any other XCode-built app: add the folder to the project with the option "Create folder references...", that will add a nice blue folder to your project's file list.
The files added in this way will end in the Resource Path of your app bundle, so that, eg, a folder named data/ added to the project can be loaded by using addFolder( "data" );.

after that, including and using dojo is a charm:

#include <dojo.h>

it's a good idea to add the include to the precompiled header (pch) that XCode creates for you to to speed up building, and don't forget to use "namespace Dojo"!

You can check if you set up everything correctly with a simple main.cpp like this one, which just instances and then kills Dojo:

#include <dojo.h>
using namespace Dojo;

int main( int argc, char** argv )
{
	Platform::create();	
	Platform::shutdownPlatform();
	
	return 0;
}

The mostly uninteresting stuff that goes on between create() and shutdown() is covered in the next tutorial,
Placing a ninja on screen, from scratch!

Clone this wiki locally