Template:Building Blender/Linux/cmake

Manual CMake Setup

If you want to have more control over your build configuration or have multiple build directories for a single source directory. You can follow these steps.

Typically useful for developers, who build frequently.

CMake Setup

Now you have to choose a location for CMake build files, currently in-source builds in Blender aren't supported.

Out-of-source build

By doing an "out-of-source" build you create a CMake's directory aside from ~/blender-git/blender, for example ~/blender-git/build:

mkdir ~/blender-git/build
cd ~/blender-git/build
cmake ../blender

This will generate makefiles in the build directory (~/blender-git/build).


As said above, in-source-builds where you build blender from the source code directory are not supported.
If CMake finds a CMakeCache.txt in the source code directory, it uses that instead of using ~/blender-git/build/CMakeCache.txt.

If you have tried to do an in-source build, you should remove any CMakeCache.txt from the source code directory before actually running the out-of-source build:

rm ~/blender-git/blender/CMakeCache.txt

Building Blender

After changes have been done and you have generated the makefiles, you can compile using the make command inside the build directory:

cd ~/blender-git/build
make install

Also notice the install target is used, this will copy scripts and documentation into ~/blender-git/build/bin

For future builds you can simply update the repository and re-run make.

cd ~/blender-git/blender
make update
cd ~/blender-git/build
make install

Build Options

By default Blender builds will be similar to official releases. Many Build Options are available for debugging, faster builds, and to enable or disable various features.

System Installation

Portable installation is the default where scripts and data files will be copied into the build '~/blender-git/build/bin' directory and can be moved to other systems easily.

To install Blender into the system directories, a system installation can be used instead. Disable WITH_INSTALL_PORTABLE to install into CMAKE_INSTALL_PREFIX which uses a typical Unix FHS layout: bin/, share/blender/, man/ etc.

Optimize Rebuilds

Now that you can build Blender and run Blender, there are changes you can make which greatly increase the speed of build times.

Use one of the CMake configuration editors (ccmake or cmake-gui), see Editing CMake Parameters

For really fast rebuilds you can disable Every option with the WITH_ prefix, except for WITH_PYTHON which is needed for the UI. This speeds up linking and gives a smaller binary.

Remove the files created by make install since they will become stale. However, Blender still needs to be able to find its scripts or you will have a very minimalist looking interface. This can be solved by linking the source directory to your Blender binary path so copying isn't needed and scripts are always up to date.

rm -r ~/blender-git/build/bin/*.*
ln -s ~/blender-git/blender/release ~/blender-git/build/bin/

For convenient access, create this symlink to run blender from the source directory:

 ln -s ~/blender-git/build/bin/blender ~/blender-git/blender/blender.bin

You can add any files created this way to ~/blender-git/blender/.git/info/exclude so they won't count as untracked files for git. Add your local files here, instead of in .gitignore, because .gitignore is also committed and will affect everyone else.

See also