博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Blender源码在Mac OS X上的编译(英)
阅读量:6980 次
发布时间:2019-06-27

本文共 8982 字,大约阅读时间需要 29 分钟。

hot3.png

Install Xcode Development Tools

It is recommended to download the newest Xcode package from the Mac App Store for your system (it's free).

For Xcode 4, you need to install the command line tools additionally. This is done by starting Xcode, going into Preferences.. > Download and installing them. For Xcode 5 this should no longer be needed.

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.

Download sources from Git

Now you are ready to get the latest Blender source code from Blender.org's Git repository. Copy and paste the following instructions into a terminal window. These will create a blender-build folder off your home directory and download the latest source code.

mkdir ~/blender-buildcd ~/blender-buildgit clone http://git.blender.org/blender.gitcd blendergit submodule update --init --recursivegit submodule foreach git checkout mastergit submodule foreach git pull --rebase origin master

For additional information on using Git with Blender's sources, see:

Download external libraries from Subversion

The external libraries needed for building blender have been precompiled for Intel 32 bit and 64 bit and OS X 10.5+, and can be download with these commands:

cd ~/blender-buildmkdir libcd libsvn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/darwin-9.x.universal

Updating sources and external libraries

If you later want to update your git and svn checkout to the latest version:

cd ~/blender-build/blendergit pull --rebasegit submodule foreach git pull --rebase origin mastercd ~/blender-build/lib/darwin-9.x.universalsvn update

Run CMake To Create makefiles and XCode Project

CMake itself does not build blender, but it generates the build environment for Blender. You can either generate Unix Makefiles that can be used from the terminal (easy), or generate XCode Project Files if you like to work in XCode.

Quick Build with a Single Command

The easiest and fastest solution is to build Blender with the default settings, and simply run this in the Terminal:

cd ~/blender-build/blendermake

After the build finished, you will find blender.app ready to run in ~/blender-build/build_darwin/bin.

Read on if you want to do more advanced configuration.

Configure a New Build with CMake GUI

Note: For CMake to determine the proper location of Xcode build, it's important that your active version of Xcode be located at /Applications/Xcode.app.

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).

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 through 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 You can restrict the OSX version you want to build for (10.5, 10.6, 10.7, 10.8, 10.9), but a nice default is 10.6.
CMAKE_OSX_SYSROOT It is recommended to always use the highest sdk available.
WITH_CODEC_QUICKTIME must be set to ON if you want to use Apple media services ( actual QTKit, AVKit soon )
WITH_CODEC_FFMPEG set to ON if you want FFMPEG support.
CMAKE_CXX_FLAGS_DEBUG, CMAKE_C_FLAGS_DEBUG (advanced mode) set to "-g3 -O0 -fno-inline" for best gdb code stepping

Note: 'gcc' is a symbolic link to the default compiler used by the desired Xcode version. Since XCode5 this means CLANG, formerly it was llvm-gcc

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.

Configuring a New Build From With CMake From the Command Line

cd to the directory where the blender/ and lib/ directories are. Then do the following:

mkdir build_darwincd build_darwincmake ../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.

Building Blender

At this point you should have your build environment set up via CMake. Now you can build the actual executable in two different way: From the Command Line with Make, or With XCode.

Build with Unix Makefiles

Open up a Terminal and navigate to the build directory you created (e.g. build_darwin). Then just run:

makemake 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.

For Shell-scripts use GNU-Syntax: expr `nproc` + 1 or Bash-Syntax: $((`nproc`+1))

If it's still not using all your CPU power, leave out the number: "-j" to spawn as many as possible build processes (usually 64).
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/build_darwin/bin.

Building with XCode  

Assuming you followed the steps above and configured CMake to build into its own folder inside a folder named "blender-build", there will be an XCode project located in "cmake/Blender.xcodeproj".

Double click it to open XCode.

XCode 4

Set the Active Target to Install:

Open the scheme for "Install" target and set "Release" or "Debug", set executable to "Blender.app"

And now build (click on the "Run" Button shown in the image)!

When Xcode is finished, Blender will start automatically for testing.

XCode 5

1. Change the Active Scheme popup in the upper left corner of the XCode 5 project window from ALL_BUILD to Install

2. Select menu Product->Scheme->Edit Scheme

  • Edit Scheme is located all the way at the bottom of the list of targets. Or just Press Command-<.

3. Select the Run item from the left view and you will see something like this:

4. Select the Blender App from the Executable popup menu.

  • You may leave the Debugger options at the defaults.

5. Click OK to save changes.

Now clicking the Run triangle next to the Active Scheme popup should now build the application and launch Blender under the debugger.

Building with SCons

!!! Scons was refactored in november 2013 !!!

Scons will setup all needed flags automatically depending on the defined architecture.

  • Default is to build 64bit_intel (x86_64) and cuda binaries disabled.

If you want change desired variables just create an user-config.py in the blender source root dir and add the variables you want affect.

  • Variables set in user-config will override the darwin-config correspondants

Example: For compiling 32bit_intel with cuda binaries precompiled, save the following text in user-config.py:

MACOSX_ARCHITECTURE = 'i386' # valid archs: ppc, i386, ppc64, x86_64WITH_BF_CYCLES_CUDA_BINARIES = True
  • 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.

Then launch the build:

python scons/scons.py -j x

Change "x" 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

Expert tip:

You can have multiple specialized configs prepared and just use them with:

python scons/scons.py BF_CONFIG=
 -j x

After drastic changes in the source directory structure, you may need to clean your build/install files to overcome build issues:

python scons/scons.py clean

转载于:https://my.oschina.net/u/2306127/blog/373347

你可能感兴趣的文章
DataTable快速定制之Expression属性表达式
查看>>
C#特性杂谈
查看>>
Mybatis Generator insert useGeneratedKeys keyProperty
查看>>
AVC1与H264的差别
查看>>
C++ Primer中文本查询演示样例Query的实现
查看>>
UVALive 4863 Balloons 贪心/费用流
查看>>
CoreData概略
查看>>
[禅悟人生]如春风般吹开他人冬眠的良心
查看>>
【leetcode】3Sum Closest(middle)
查看>>
memcache的一致性hash算法使用
查看>>
Oracle Hints具体解释
查看>>
《沉静领导》读书笔记
查看>>
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
查看>>
Laravel4中的Validator
查看>>
Linux Web服务器网站故障分析常用的命令
查看>>
logistic回归
查看>>
SeaJS 模块化加载框架使用
查看>>
MongoDB 索引相关知识
查看>>
Windows上模拟Linux环境
查看>>
LPEG
查看>>