This is an attempt to provide an up to date guide on how to build Ogre from scratch on a recent Mac platform. We will be using Xcode 4.6, and Mac OS X 10.7.5. Tested on a Mac mini 2011, if that matters.
The motivation for this guide was the result of general frustration of the difficulty of building Ogre the Mac platform. My background is from using Visual Studio 2008, so I wanted a step-by-step guide
on how to build Ogre.
For simplicity, directories will be created in the home directory, although that may not be generally desirable.
Because of my requirements (32 bit only third party library), we will build a static version for i386 only, although it should be easy to identify and tweak those options for your own use.
Although not strictly necessary, Boost is nice for cross platform stuff, and I feel it makes me more productive. However, you sacrifice compile times and binary sizes.
Hopefully the negatives will eventually disappear in the future as compilers get better.
# Download Boost on the official website, at the time this was written, it is 1.53.0 cd tar -xjvpf ~/Downloads/boost_1_53_0.tar.bz2 mv boost_1_53_0 boost # I chose to do this so I don't have to update directories every time in other projects # install the b2 / bjam to ~/boost.build, this is like make and cmake, but for boost cd boost/tools/build/v2 ./booststrap.sh mkdir ~/boost.build (NOTE that ~ doesn't work below to specify home) ./b2 install --prefix=/home/USERNAME/boost.build # make sure you are using the latest compilers, and they refer to the ones inside /Applications/Xcode.app # this is important if you have Xcode 3 and Xcode 4 simulataneously installed $ /usr/bin/g++ --version i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) $ /usr/bin/clang --version Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) Target: x86_64-apple-darwin11.4.2 Thread model: posix # building Boost cd ~/boost ~/boost.build/bin/b2 --layout=versioned --build-type=minimal toolset=darwin link=static architecture=x86 address-model=32 stage
After following these steps, you have lots of *.a files in ~/boost/stage/lib . Since layout=version is specified, they have the suffix -xgcc42-mt-1_53
Pretty simple. Go to their website, download CMake, and install. Also install the command-line tools at the end.
In the terminal, do "cmake --version" to check that the version is at least 220.127.116.11
Also pretty simple. Just use the install inside the DMG.
NVIDIA Cg Download
Since we are building our own version of Boost, we might as well build the Ogre dependencies also.
# get ogredeps source cd hg clone https://bitbucket.org/cabalistic/ogredeps # make temp directory for build cd ogredeps mkdir build cd build cmake -D CMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -D CMAKE_OSX_ARCHITECTURES=i386 .. # this seems to always compile in Release mode by default (i.e. -O3 is used) make # this creates a directory ~/ogredeps/build/ogredeps , and this is where we will tell Ogre to look for dependencies make install
# get OGRE source cd hg clone https://bitbucket.org/sinbad/ogre/ ogre cd ogre # switch to latest stable branch at the time of this writing hg update v1-8 # if you have boost installed via MacPorts, de-activate it for now as the CMake boost finder is buggy and will # try to link to the boost libs in /opt/local/lib even though you explicitly specified a library location # build mkdir build cd build # below command is so long it probably takes 2 lines cmake -D BOOST_ROOT=~/boost -D BOOST_INCLUDEDIR=~/boost -D BOOST_LIBRARYDIR=~/boost/stage/lib -D Boost_DEBUG=1 -D OGRE_DEPENDENCIES_DIR=~/ogredeps/build/ogredeps -D OGRE_STATIC=1 -D CMAKE_OSX_ARCHITECTURES=i386 -D OGRE_BUILD_SAMPLES=0 -G Xcode .. # Explanation of above: # BOOST_ROOT, BOOST_INCLUDEDIR, BOOST_LIBRARYDIR indicate where our custom install of Boost is at. # Boost_DEBUG=1 is to make sure it is using the correct Boost location. # OGRE_DEPENDENCIES_DIR is where the output of the previous step is at # OGRE_BUILD_SAMPLES=0 to disable building of the SampleBrowser for quicker compilation # Note, from browsing the forums, Xcode generator is essential as Makefiles don't work correctly (?) # open OGRE.xcodeproj in Xcode # Product > Scheme > Edit Scheme # change "ALL_BUILD" to Release Build Configuration # change "install" to Release Build Configuration # make sure "Product > Scheme > ALL_BUILD" is selected # Product > Build # select "Product > Scheme > install # Product > Build # NOTE that the build fails complaining that 'FindiOSSDK.cmake' can't be found, but I think we can ignore that.
After performing these steps, you should have a ~/ogre/build/sdk/ directory, which contains the files that you will need to use Ogre in your application.
Download the latest Xcode template by going to http://sourceforge.net/projects/ogre/files/ogre-dependencies-mac/1.8/ and downloading Ogre_Xcode4_Templates_20120621.pkg.zip
Close Xcode and install this pkg file.
Now when you create a new project, under the OS X section there should be an Ogre category with "Mac OS X Application" that has the Ogre head logo. Choose that and create a new project.
The first thing you should notice when you enter project is the missing frameworks. Remove those.
open /System/Library/Frameworks/ and drag AGL.framework, GL.framework, and QuartzCore.framework into the Frameworks folder in Xcode.
open /Library/Frameworks/ and drag Cg.framework into Framworks like above.
Other Linker Flags
-lOIS -lOgreMainStatic -lfreetype -lFreeImage -lboost_thread-xgcc42-mt-1_53 -lboost_system-xgcc42-mt-1_53 -lzziplib -lzlib -lPlugin_CgProgramManagerStatic -lRenderSystem_GLStatic
Important that /Library/Frameworks is added below, otherwise compiler won't be able to find Cg/cg.h
Framework Search Paths
$(inherited) "$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks" /Library/Frameworks
Header Search Paths
~/ogre/build/sdk/include/OGRE ~/ogre/build/sdk/include/OGRE/OSX ~/ogre/build/sdk/include/OGRE/Plugins/CgProgramManager ~/ogre/build/sdk/include/OGRE/RenderSystems/GL ~/ogre/build/sdk/include/OIS ~/boost
Library Search Paths
Below 2 settings are important, otherwise you get mysterious bad codegen, pointer diff errors
Inline Methods Hidden
Symbols Hidden by Default
Add this to the beginning of the Precompiled Header
If you don't do this, you get errors saying how glew.h needs to be included before gl.h and glext.h
Comment out "delete m_pRoot" in OgreFramework::~OgreFramework()
Right now it crashes inside OgreRoot::shutdown(), and I have no idea why. If I have time I will probably investigate later by making Debug builds of Ogre.
Press 'Run' and hopefully everything goes well except for the 'PBXCp Error' that you can ignore and you should have the Config Screen.
Press 'OK' and you should see the famous Ogre head
Press Escape to close the application.