# Building

## Dependencies

https://github.com/bkaradzic/bx

## Getting Source

    git clone git://github.com/bkaradzic/bx.git
    git clone git://github.com/bkaradzic/bgfx.git

## Quick Start

These are step for users who use Windows with Visual Studio.

Enter bgfx directory:

    cd bgfx

Generate Visual Studio 2015 project files:

    ..\bx\tools\bin\windows\genie vs2015

Open bgfx solution in Visual Studio 2015:

    start .build\projects\vs2015\bgfx.sln

Note

For more detailed prerequisites and build steps on other platforms see below.

## Prerequisites

### Android

Download AndroidNDK:

> - https://developer.android.com/tools/sdk/ndk/index.html

Set following enironment variables:

    setx ANDROID_NDK_ROOT <path to AndroidNDK directory>
    setx ANDROID_NDK_ARM <path to AndroidNDK directory>\toolchains\arm-linux-androideabi-4.7\prebuilt\windows-x86_64
    setx ANDROID_NDK_MIPS <path to AndroidNDK directory>\toolchains\mipsel-linux-android-4.7\prebuilt\windows-x86_64
    setx ANDROID_NDK_X86 <path to AndroidNDK directory>\toolchains\x86-4.7\prebuilt\windows-x86_64

To deploy on Android you can use bgfx android activity:

> - https://github.com/Nodrev/bgfx-android-activity#bgfx-android-activity—android-glue-for-bgfx

### Linux

    sudo apt-get install libgl1-mesa-dev x11proto-core-dev libx11-dev

### Native Client

Download Native Client SDK:

> - https://developers.google.com/native-client/sdk/download

Set following enironment variables:

    setx NACL_SDK_ROOT <path to Native Client SDK directory>

### Windows

Windows users download GnuWin32 utilities:

> - http://gnuwin32.sourceforge.net/packages/make.htm
> - http://gnuwin32.sourceforge.net/packages/coreutils.htm
> - http://gnuwin32.sourceforge.net/packages/libiconv.htm
> - http://gnuwin32.sourceforge.net/packages/libintl.htm

If you’re building with Visual Studio 2008, you’ll need TR1 support from: Visual C++ 2008 Feature Pack Release

## Build

bgfx uses GENie - Project generator tool to generate project files for various platform. Binaries for Linux, OSX, and Windows are included in bx repository.

### General

    cd bgfx
    make

After calling `make`, .build/projects/* directory will be generated. All intermediate files generated by compiler will be inside .build directory structure. Deleting .build directory at any time is safe.

    make <configuration>

Configuration is `<platform>-<debug/release>[32/64]`. For example:

    linux-release32, nacl-debug64, nacl-arm-debug, pnacl-release,
    android-release, etc.

### Windows

Visual Studio 2008 command line:

    make vs2008-release64

Visual Studio 2008 IDE:

    start .build/projects/vs2008/bgfx.sln

### Xcode

    open .build/projects/xcode4-osx/bgfx.xcworkspace

Due to inability to set working directory for an Xcode project from GENie configuration file, it has to be set manually for each example project:

1. Open “Edit scheme...” dialog for a given project.
2. Select “Run” settings.
3. Check “Use custom working directory” and enter following path: `${PROJECT_DIR}/../../../examples/runtime`.

### Linux

    make linux-release64

### WinRT / Windows Phone 8.1

    ../bx/tools/bin/windows/genie --vs=winphone81 vs2015

Build the resulting solution and deploy to device.

Note

Shaders will need to be compiled with the appropriate target profile for your platform.

## Amalgamated Build

For ease of integration to other build system bgfx library can be built with single .cpp file. It’s only necessary to build src/amalgamated.cpp (for OSX/iOS use src/amalgamated.mm instead) inside different build system.

## OculusVR Integration

To build with OculusVR HMD support enabled you must set `OVR_DIR` enviroment variable:

    set OVR_DIR=<path to OculusSDK>

And generate project files with `--with-ovr` option:

    genie --with-ovr vs2015

## Tools

To build bgfx project files for tools, use `--with-tools` option:

    genie --with-tools vs2015

## Alternative build systems

fips is a highlevel build system wrapper written in Python for C/C++ projects. https://github.com/floooh/fips#fips

mkvfx is a tool that builds open source libraries commonly used in games, film, and vfx. https://github.com/meshula/mkvfx#mkvfx—make-vfx-libraries-and-programs