Ogre uses CMake as its build system on all supported platforms. This guide will explain to you how to use CMake to build Ogre from source. You need a CMake version >= 3.3.
CMake is a cross-platform build system - or perhaps more accurately a build configurator. It is a program which, from a set of CMake scripts, creates a native build system for your platform that allows you to build Ogre. The build process is configurable via CMake. Ogre provides several options which you can use to customise your build.
You should now create a build directory for Ogre somewhere outside Ogre's sources. This is the directory where CMake will create the build system for your chosen platform and compiler, and this is also where the Ogre libraries will be compiled. This way, the Ogre source dir stays clean, and you can have multiple build directories all working from the same Ogre source.
By default ogre will build the essential dependencies automatically when you run cmake the first time. If you would rather use system wide libraries set OGRE_BUILD_DEPENDENCIES=OFF
.
Ogre will install the dependencies into the subfolder Dependencies
in the build dir by default. You can configure it by setting OGRE_DEPENDENCIES_DIR
in cmake. For instance to point to a common dependencies folder for all of your projects. Inside
this directory you must have the subdirectories bin, lib and include
where you place .dll, .lib and header files of the dependencies, respectively
On linux you additionally need the following system headers to build the GL RenderSystems (command for Ubuntu):
sudo apt-get install libgles2-mesa-dev libxt-dev libxaw7-dev
furthermore we recommend installing the following optional packages
sudo apt-get install nvidia-cg-toolkit libsdl2-dev doxygen
these will enable input handling in the SampleBrowser and building the documentation.
If you cannot obtain prebuilt binaries of a dependency for your platform, please refer to the list below and get a source package from the website, then build it according to its documentation.
- freetype: http://www.freetype.org
- zlib: http://www.zlib.net
- zziplib: https://github.com/gdraheim/zziplib
- pugixml: https://github.com/zeux/pugixml
- SDL: https://www.libsdl.org/
- DirectX SDK: http://msdn.microsoft.com/en-us/directx/
- FreeImage: http://freeimage.sourceforge.net
- Doxygen: http://doxygen.org
- Cg: http://developer.nvidia.com/object/cg_toolkit.html
- Remotery: https://github.com/Celtoys/Remotery
- Boost: http://www.boost.org (+)
- POCO: http://pocoproject.org (+)
- TBB: http://www.threadingbuildingblocks.org (+)
(+) can be used for threading instead of std::thread
Now start the program cmake-gui by either typing the name in a console or selecting it from the start menu. In the field Where is the source code enter the path to the Ogre source directory (the directory which contains this file). In the field Where to build the binaries enter the path to the build directory you created. Hit Configure. A dialogue will appear asking you to select a generator.
Check the CMake documentation for details on which one is appropriate for your platform and compiler.
@note on OSX, you must to use the Xcode generator to get a proper SampleBrowser .app bundle.
Click Finish. CMake will now gather some information about your build environment and try to locate the dependencies. It will then show a list of build options. You can adjust the settings to your liking;
- unchecking any of the
OGRE_BUILD_XXX
options will disable that particular component/ plugin from being built OGRE_CONFIG_XXX
on the other hand allows you to configure Core features e.g. threading or zip file support.OGRE_CONFIG_NODE_INHERIT_TRANSFORM
enables shearing and non-uniform scaling for Ogre::SceneNode. This requires slightly more storage and computation time.OGRE_PROFILING
add profiling instrumentation the ogre library.OGRE_PROFILING_REMOTERY_PATH
if set, Remotery is used for profiling instead of the Ogre internal profiler.OGRE_ASSERT_MODE
allows you to to disable all runtime assertion exceptions or turn them into calls tostd::abort
.OGRE_RESOURCEMANGER_STRICT
allows you to turn on resource lookup related quirks for pre ogre 1.10 compatibility.
Once you are satisfied, hit Configure again and then click on Generate. CMake will then create the build system for you.
Go to your chosen build directory. CMake has generated a build system for you which you will now use to build Ogre. If you are using Visual Studio, you should find the file OGRE.sln. Open it and compile the target BUILD_ALL. Similarly you will find an Xcode project to build Ogre on MacOS.
If you rather want to trigger the build form a console, then cd to your build directory and call the appropriate make program as
cmake --build . --config release
to start the build process.
If you have doxygen installed and CMake picked it up, then there will be an additional build target called OgreDoc which you can optionally build. This will freshly generate the API documentation for Ogre's classes from the header files. In Visual Studio, just select and build the target OgreDoc, on Linux type:
make OgreDoc
Once the build is complete, you can optionally have the build system copy the built libraries and headers to a clean location. We recommend you do this step as it will make it easier to use Ogre in your projects. In Visual Studio, just select and build the target INSTALL. When using the command line with MSVC, type:
cmake --build . --config release --target INSTALL
For Makefile based generators, type:
make install # (or sudo make install, if root privileges are required)
On Linux Ogre will be installed to /usr/local
by default. On Windows this will create the folder sdk
inside your build directory and copy all the
required libraries there. You can change the install location by changing the variable CMAKE_INSTALL_PREFIX
in CMake.
To build Ogre for Android, you need to specify the android cross toolchain to cmake as
cmake -DCMAKE_TOOLCHAIN_FILE=path/to/android-ndk/build/cmake/android.toolchain.cmake -DANDROID_NDK=path/to/android-ndk .
this will build the core Ogre libraries. Additionally it will create gradle projects OgreJNI
for using Java bindings and SampleBrowserNDK
for the C++ only Sample Browser.
You can now import these projects in Android Studio or manually trigger the APK creation by changing into the project folders and running
gradle assembleRelease
Install the Emscripten SDK (see full documentation on www.emscripten.org), and make sure that the environment variables are correctly set (eg. run source <emsdk_path>/emsdk_env.sh before attempting to build)
Run cmake in cross compile mode using emscripten as following:
mkdir build-wasm
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
emmake make
NB: to simplify the process, 'emcmake' and 'emmake' wrappers are used. These tools are provided by Emscripten to correctly setup the cross compilation environment
This will not build the full SampleBrowser, but just a minimal Sample. The resulting EmscriptenSample.html
will be placed in ${CMAKE_BINARY_DIR}/bin/
.
To prevent any cross-origin issues, start a local webserver as python3 -m http.server 8000
and visit http://localhost:8000.
To build Ogre for iOS, you need to specify the ios cross toolchain to cmake as
cmake -DCMAKE_TOOLCHAIN_FILE=CMake/toolchain/ios.toolchain.xcode.cmake -G Xcode .
Unfortunately, you will now have to do a few manual steps to make the generated build system work properly.
A Xcode project has now been generated in the build directory, so to start the Ogre build, open OGRE.xcodeproj and build as usual. To run samples on your device you will need to have a valid iOS Developer certificate installed. For each sample, double click on target in the Groups & Files list. Ensure that a valid identity is selected in the Code Signing Identity drop menu. Also, because we can't tell CMake what Xcode project format you want, you will have to change it yourself. Open the Project Menu, choose Edit Project Settings. Click on the General tab in the settings window. Change Project Format to Xcode 3.1-compatible. And another thing. You will need to manually set the Bundle Identifier property of the Info.plist file to match the App ID of the chosen code signing identity. This can be done from the Target Properties panel. It must match the bundle identifier of a valid developer certificate if you are building for devices.
You need Windows 8.0 or later, Windows 10 is recommended.
You need Visual Studio 2012 or later, Visual Studio 2015 is recommended as it is bundled with Universal 10.0.240.0, WinStore 8.0/8.1 and WinPhone 8.0/8.1 SDKs.
Download and install CMake 3.4 or later.
Patched dependencies must be used, compiled with appropriate WINAPI_FAMILY. Cg is not supported. You can use https://bitbucket.org/eugene_gff/ogre-dependencies-winrt - has VS2012 and VS2013 projects for Win32, WinRT (can be reused for WinPhone) Compile dependencies for all configurations that you plan to use before running CMake. Dependencies for Win32 and for WinRT must be located in separate folders, Win32 version can be built from OgreDependencies.VS201x.sln, WinRT from OgreDependencies.VS201x.WinRT.sln
Run CMake, specify source and binaries folders, than "Configure", select "Visual Studio 14 2015" generator and "Specify options for cross-compiling" option, specify Operating System = "WindowsStore" or "WindowsPhone", Version = "8.0", "8.1" or for UAP Operating System = "WindowsStore", Version = "10.0.10240.0", "10.0.10586.0" then "Finish", specify WinRT dependencies folder for OGRE_DEPENDENCIES_DIR, "Configure", should be no more errors, then press "Generate".
Select SampleBrowser as the start up project and run.
-
The code and generated CMake solution should be on local NTFS drive, and can't be on a network drive, including VMWare shared folders - or you will get a errors when you will try to compile/link/run resulting exe.
-
Ogre uses d3dcompiler_xx.dll to compile shaders, and WinStore and WinPhone 8.1 projects can use it without restriction as it is part of OS. But WinStore and WinPhone 8.0 applications should load already compiled shaders from cache, as d3dcompiler_xx.dll is available to them only during development. Therefore to avoid necessity to deploy d3dcompiler_xx.dll during development (additional configurations with d3dcompiler_xx.dll) and generation of such cache - use version 8.1 of these platforms.
-
Running WinPhone emulator in OS running under VMware: We were able to run the emulation and debug without an issue by using two steps: (a) Under the settings of the VM > CPU, make sure you have the option to pass-through the Intel VT-x/EPT feature, (b) Edit the config file .vmx and add the parameter: hypervisor.cpuid.v0 = "FALSE" All versions of Visual Studio 2012 have a window refresh issue when running in VMware and the window is maximized, the solution is just to change the size of the Visual Studio window to be less the the screen width and height.