From BlenderWiki
Building 2.5 for OSX
Building Blender for OSX needs a bit of preparation. However the steps are not very complicated and if you follow the instructions carefully you should be able to build Blender.
Build steps in a nutshell
System Preparation:
- Install OSX dev Tools (Xcode 4)
- Install cmake (if you do not use scons)
- Fetch sources from svn
- Fetch external libs from svn
Building:
- Create build environment
- Build
System Preparation
Install OSX dev Tools (Xcode 4)
An older version of the OSX dev tools is included in the OSX DVDs and it should work for our purposes. But you can also download the new Xcode 4 package from the Mac App Store for free. Detailed info about Xcode 4 can be found at
http://developer.apple.com/technologies/tools/
However the full package has a download size 4.5 GBytes so you'd better get prepared for a few hours of download time.
Install Subversion
TODO
Install cmake
cmake is a tool for generating build environments and it supports make and Xcode (among others). If you plan to build using scons, then you can skip this step. You can get cmake from here:
http://www.cmake.org/cmake/resources/software.html
Fetch sources from svn
Now you are ready to get the latest Blender source code from Blender.org's SVN repository.
Copy and paste the following instructions into a terminal window (or any command line, unix shell).
These will create a blender-build folder off your home directory and download the latest trunk (main) source code. An internet connection is needed.
cd ~ mkdir blender-build cd blender-build svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/blender
Fetch external libs from svn
The external libs needed for building blender have been precompiled for ppc & intel 32bit 10.4 & 10.5, and intel 64bit 10.5. Depending on the type of build you want to make checkout the specific libraries into your blender-build folder:
For PowerPC, Intel 32bit & 64bit 10.5 and later:
cd ~/blender-build mkdir lib cd lib svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/darwin-9.x.universal
For Intel 32bit 10.4 and later:
cd ~/blender-build mkdir lib cd lib svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/darwin-8.x.i386
For PowerPC 32bit 10.4 and later:
cd ~/blender-build mkdir lib cd lib svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/darwin-8.0.0-powerpc
Make sure that you create the library folder in the correct parent folder, as the build scripts will look for it only in a specific location. After this step, you should have a folder structure resembling the following:
- blender-build
- blender
- lib (containing the correct version of darwin-X.X.XXXX)
If you later want to update your svn checkout to the latest source:
cd ~/blender-build svn update blender svn update lib/darwin-8.x.i386
Building
Create build environment
You can perform the build using either scons or cmake.
A.) Scons
Copy blender/config/darwin-config.py into the blender folder and rename the file to user-config.py:
cd ~/blender-build/blender cp build_files/scons/config/darwin-config.py user-config.py
Then open user-config.py and change the flags at the very top to match your needs ( Do never(!) change darwin-config.py directly ) :
- MACOSX_ARCHITECTURE needs to be set to the correct architecture : ppc, i386 (Intel 32bit) or x86_64 (Intel 64bit)
After a first successful build, you can afterwards ("expert mode") tweak the other settings to make an optimized build.
- Note that 32bit architectures (ppc & i386) are built by default with 10.4SDK. If you are using OSX 10.6, you may need to install the 10.4 SDK that is an optional package in xcode install.
Then launch the build:
python scons/scons.py -j 2
Change "2" to the actual number of CPU cores you have in your system to accelerate the build process.
If everything went fine, the resulting blender.app will reside here: blender-build/install/darwin/blender.app
B.) CMake
CMake itself does not build blender, but it generates the build environment for blender. Basically you have 2 supported choices with blender: Either generate for "Unix Make" or Generate "XCode Project files". We will show you in detail how to proceed and when to choose your build environment.
One general recommendation: Please do an out of source build, this means building to a location other than the source folder. This nicely separates the build artifacts from the actual source distribution and it lets you create multiple build configurations from the same source folder.
Start Up the CMake GUI
CMake comes with a command line interface as well as a the graphical user interface. Skip to the next section if you want to use Terminal only. You find the CMake App in your Application folder. Double click on it to start it. The CMake Window shows up:
As you can see all you have to enter is the location of the sources in ~blender-build/blender and a destination directory which i have chosen to be ~blender-build/cmake (any location outside of the source directory is allowed).
Configure the Project
Now Press the "Configure" Button. You get another Popup:
Here you can select which Generator you want to use (Unix Makefiles or CMake in our case). I have selected Xcode here. Note that you also can select which compiler you want to use. If you are unsure about what that means, don't worry and use the default native compilers.
Now press the "Done" Button. You get back to the previous screen but now you will see a big red list of options. You can scroll throught the option list and set parameters to your needs. Please ensure that the following settings are correct for your build:
| parameter | value |
|---|---|
| CMAKE_BUILD_TYPE | "Release" (for release build with optimizations) or "Debug" (to get debug info for gdb) |
| CMAKE_OSX_ARCHITECTURES | ppc, i386, x86_64 (x86_64 for all recent OS X versions)
Note: x86_64 (64 bits) is default, only newer hardware support it. If your build stops with error "Bad CPU type in executable" you have to switch cpu type to i386 or ppc (32 bits). |
| CMAKE_OSX_DEPLOYMENT_TARGET | OSX version you want to build for (10.4, 10.5, 10.6, 10.7) |
| CMAKE_OSX_SYSROOT | the OSX SDK of the OSX version you specified the line above, e.g. for 10.5: "/Developer/SDKs/MacOSX10.5.sdk"
Note: When you have installed Xcode 4 then you always must(!) use "/Developer/SDKs/MacOSX10.6.sdk" or above because XCode 4 does not work with older SDKs. |
| WITH_LIBS10.5 | set to ON if you want to build for 10.5, 10.6 or 10.7 using the darwin-9.x.universal libs you downloaded |
| USE_QTKIT | must be set to ON if you want Quicktime with a 64bit build |
| WITH_COCOA | set to ON if you are using 10.5, 10.6 or 10.7. |
| WITH_FFMPEG | set to ON if you want FFMPEG support. |
| CMAKE_CXX_FLAGS_DEBUG | (advanced mode) set to "-g3 -O0 -fno-inline" for best gdb code stepping |
Click Configure again and the red highlighting should disappear. Then click Generate and your build environment will be created into the build folder.
The next steps depend on the type of build files you generated.
Configure CMake via Terminal command line
cd to the directory where the blender/ and lib/ directories are. Then do the following:
mkdir cmake cd cmake cmake ../blender/
This will create all Makefiles in the cmake directory, as an "out of source build"
Then run
ccmake .
Which starts the terminal 'curses' app to configure build settings. Check the section above for important settings. End with the commands "c" (configure) and "g" (generate). Note that you have to carefully check cpu type and osx version.
Generate Unix Makefiles and Build
Open up a Terminal and navigate to the build directory you created (e.g. cmake). Then just run:
make make install
| Parallel Builds | |
| For multi-core / multi processor systems you can build much faster by passing the jobs argument to make: -j(1+number_of_cores). For example put "-j3" if you have a dual-core or "-j5" if you have a quad-core. Note that it may build faster, but make your system lag in the meanwhile. |
Once this completes you should end up with a blender.app in the directory blender-build/cmake/bin.
Generate XCode Project files
Open XCode (Use the "Open other ..." Button) and load the project located in cmake/Blender.xcodeproj
Set the Active Target to Install:
And now build (click on the "Run" Button shown in the image)!
Note: you need to set in the build preferences panel to use gcc 4.0 instead of gcc4.2 if you want to build for 10.4
When Xcode is finished, change the Active Target to Blender and click "Run" again. Now your freshly made blender should get linked and started automatically.
Activating Breakpoints in Xcode
The Xcode project generated by CMake as described above, while debugging, ignores any breakpoints set. This makes debugging impossible from within XCode (unless you use terminal and debug on the command line since the project is indeed built using the debug flags and the debug info is available in the generated binary.)
To fix this, go to your Xcode preferences, and in the Debugging section, uncheck the Load symbols lazily check-box under Symbol Loading Options. Note that doing this might increase the time taken to load executables to the debugger for other large projects, since the 'Load symbols lazily' option (when activated) makes gdb postpone symbol reading until when the symbols are needed.
Ranlib
Sometimes you might need to run ranlib from the command line on libraries that have not been updated, but are still in SVN. Ranlib builds an index of all the functions inside the library so the compiler can find them. If a library has not been indexed you will receive a message during link stating "could not read symbols: Archive has no index; run ranlib..." or something to that effect.
You can run ranlib from the command line for single libraries easily:
ranlib libfoo.a
If you need to run ranlib on multiple directories, however, this can be a hassle. The following Python script can be run from the command line and can recursively run ranlib on all libraries that need it within your chosen architecture. You will need to chmod +x this script in order to run it, or save it to a file and use the command line python interpreter. Don't forget to change the base directory so that it points to your chosen architecture.
#!/usr/bin/python # runranlib.py import os base = './lib/darwin-8.x.i386/' paths = os.listdir(base) print "" libsToMod = [] for p in paths: # special case if p == "python": continue if p[0] != '.': try: libs = os.listdir(base + p + "/lib/") except: continue for l in libs: if l[0] != '.': libsToMod.append(p + "/lib/" + l) libsToMod.append("python/lib/python3.1/libpython3.1.a") for l in libsToMod: print("Fixing: %s..." % l) os.system('ranlib %s%s' % (base, l)) print("... done.\n")


