Skip to main content

History: CMake Quick Start Guide

Preview of version: 59

Image

For the impatient: Learn how to build Ogre with CMake in two minutes. If you encounter any problems or need some more advanced procedures, do read the rest of the sections below!

Introduction

This guide is designed to get you building OGRE from source with the default settings in the shortest possible time, showing you the barest minimum of CMake to do that, and minus any real discussion. Remember that there is a lot more to the hows and whys of this process, so it's a good idea to go back to the Getting Started With CMake page and read the whole thing when you have time.

We assume here that you've already downloaded / extracted the OGRE source code into a folder on your local machine. From here, go to the section for your platform.

Done Make sure that you've sorted out the Prerequisites before attempting to build Ogre with CMake!

  1. Download the Dependencies repository. To i.e. C:\OgreSDK\Dependencies
  2. Download and install CMake. You want the 'Win32 installer' release in the binary distribution section. Use version +2.8; version 3.x is not widely tested yet.
  3. Launch CMake via Start > Program Files > CMake 2.8 > CMake
  4. Point "Where is the source code" to C:\OgreSDK\Dependencies; and "Where to build the binaries" pointing to "C:\OgreSDK\Dependencies\build"
  5. Click 'Configure' and select the generator (i.e. if you're using Visual Studio 2013, select Visual Studio 12) Deps.png
  6. Answer 'Ok' when asked if you want to create the build directory
  7. Sometimes on bleeding edge repos there might be CMake syntax warnings. Ignore them.
  8. Now click 'Generate'.
  9. Open C:\OgreSDK\Dependencies\build\OGREDEPS.sln under Visual Studio. If you have multiple versions of VS, make sure you open it with the one you targeted for in CMake.
  10. Build the whole solution; which should build FreeImage, freetype, OIS, zlib and zziplib. Make sure to build both Debug and Release
  11. Once it's finished, right click on INSTALL project, and click build. THIS IS VERY IMPORTANT. It will create the folder structure that Ogre needs. You need to do this both for Debug and Release.DepsInstall.png
  12. This should've created an SDK folder structure under C:\OgreSDK\Dependencies\build\ogredeps
  13. Now download Ogre from the repository into C:\OgreSDK.
  14. We now repeat the same process: Open CMake, set C:\OgreSDK and C:\OgreSDK\build as "Where is the source code" and "Where to build the binaries" respectively.
  15. Hit Configure and choose the same Visual Studio generator you did for the dependencies. It will now complain it can't find the Dependencies.
  16. Set OGRE_DEPENDENCIES_DIR to point to C:\OgreSDK\Dependencies\build\ogredeps as in the picture. Use the search filter to find the option quickly. Now hit configure again.OgreDepsFix.png
  17. Pro tip: If "C:\OgreSDK\Dependencies" contains the files that are generated in C:\OgreSDK\Dependencies\build\ogredeps; you can skip the previous step.
  18. Click Generate.
  19. Open the solution C:\OgreSDK\build\OGRE.sln and compile.
  20. Right click on INSTALL project if you wish to generate the SDK structure we provide in our official releases.
  21. You're done.
  22. If you are like me (I don't like using INSTALL feature for my own projects), you can add C:\OgreSDK\build\include to your project's include location and C:\OgreSDK\build\lib\Debug (and Release) to your additional library paths. The DLLs will be located in bin\debug (or release)


That's it for CMake! You now have a set of project files that are very much like you're used to in previous versions of OGRE, in the output folder you chose. There is now a special target called 'ALL_BUILD' which is a quick way to build all targets for a specific configuration. Note that all build output is now stored in a subfolder of this build folder, and not in the original OGRE source folder - so you can create multiple builds from one source directory now.

-(Linux)--------

Done Make sure that you've sorted out the Prerequisites before attempting to build Ogre with CMake!

  1. Download Ogre Source (Instructions below assume current version of 1.8.0, update as needed)
  2. Decompress:
    Copy to clipboard
    tar xjf ogre_src_v1-8-0.tar.bz2
  3. Move to source directory:
    Copy to clipboard
    cd ogre_src_v1-8-0
  4. Create build directory:
    Copy to clipboard
    mkdir build
  5. Move into build directory:
    Copy to clipboard
    cd build
  6. Trigger cmake, passing path to Ogre source directory:
    Copy to clipboard
    cmake ..
    See the Extensive CMake page for a list of compilation options which can be passed to CMake at this stage, and Getting Started With CMake for even more background material. N.B. Please note that OGRE_CONFIG_THREADS = 1 is not supported on Linux.
  7. If the CMake results look good, build Ogre:
    Copy to clipboard
    make -j2
    The -j2 specifies how many parallel compilation jobs to run. Substitute the number of processor cores on your system, e.g. -j2 for a dual-core, -j4 for a quad core...
  8. Once compilation is successful, you can install into the system (by default, /usr/local):
    Copy to clipboard
    sudo make install



-(Mac OS X)--------

Done Make sure that you've sorted out the Prerequisites before attempting to build Ogre with CMake!


Building Ogre via CMake GUI (see alt. command line below)


Xcode 4.3 changed the layout of developer tools on disk which can cause some serious problems for CMake. The issue has been fixed but is not yet publicly released. CMake 2.8.8 will include Xcode 4.3 support. At the time of writing, a release candidate is available that includes this support.

You will also need to install the Command Line Tools from within Xcode's Downloads Preferences and set the Xcode path from the command line like this.

Assuming that Xcode is installed in /Applications,

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

  1. Download CMake. You want the 'Mac OS X Universal' release in the binary distribution section
  2. The .dmg will probably auto-mount when it downloads, if not, double-click it to open
  3. Double-click the .pkg installer, install on your main drive and opt to install the command-line tools too (in case you want to use them later, we will use the GUI here)
  4. Launch CMake via Applications
  5. In the "Where is the source code" box, type or browse to the root directory of your OGRE source (the one that contains the OgreMain folder)
  6. In the "Where to build the binaries" box, type or browse to any folder you like - this will be where the build output will go (libraries, headers, dlls & sample exes). The folder does not have to exist yet. Note that you can run this process more than once with different output folders if you want (but we won't complicate matters now)
  7. Hit the 'Configure' button near the bottom of the screen
  8. Pick 'Xcode' as the generator and opt to use native compilers
  9. Answer 'Ok' when asked if you want to create the build directory
  10. Wait for the configure process to finish
  11. The screen will now have a bunch of configuration options on it, which will be red (this is to indicate this is the first time you've seen them). You can see the potential for customising your build here, but for now just click the 'Configure' button again
  12. The values will turn grey, and the 'Generate' button at the bottom will now be enabled. Click 'Generate'
  13. Build files will now be generated in the location you picked
  14. Now, open OGRE.xcodeproj in the build directory you picked, open it in Xcode. SampleBrowser will build everything!


Note: ALL_BUILD does not work properly with Xcode 4.

Building Ogre via Command Line (see alt. GUI method above)

  1. Download Ogre Source (Instructions below assume current version of 1.8.0, update as needed)
  2. Decompress:
    Copy to clipboard
    tar xjf ogre_src_v1-8-0.tar.bz2
  3. Move to source directory:
    Copy to clipboard
    cd ogre_src_v1-8-0
  4. Create build directory:
    Copy to clipboard
    mkdir build
  5. Move into build directory:
    Copy to clipboard
    cd build
  6. Trigger cmake, specify Xcode generation and pass path to Ogre source directory:
    Copy to clipboard
    cmake -GXcode ..
    See the Extensive CMake page for a list of compilation options which can be passed to CMake at this stage, and Getting Started With CMake for even more background material.
  7. Build via Xcode
    Copy to clipboard
    xcodebuild -configuration RelWithDebInfo
    (or open OGRE.xcodeproj and build within Xcode)

Installing Ogre

You will find Ogre.framework in 'lib' within your build directory. You can embed this in your application bundle, or drag it to /Library/Frameworks for system-wide installation.

You will also find plugins (Plugin_*.dylib and RenderSystem_GL.dylib) in the same location, you can copy these to the framework's Resource directory or your own application's bundle. Be sure to configure you applications' plugins.cfg to match (e.g. /Library/Frameworks/Ogre.framework/Resources/)

-(iPhone)--------
Detailed instructions on building OGRE for iPhone can be found on this page Building From Source (for iPhone)

-(Android)--------
Download the dependencies and extract inside the OGRE src dir. The deps are compiled for armeabi and armeabi-v7a.

Copy to clipboard
http://sourceforge.net/projects/ogre/files/ogre-dependencies-android/1.9/AndroidDependencies_27_08_2013.zip/download


Building for Android on Windows host:

1. Download and install the android sdk
Copy to clipboard
http://developer.android.com/sdk/index.html

2. After the install open the "Android SDK Manager" and download & install your target API.
Here we target the lowest possible API - which is API10 Android 2.3.3.
Due the usage of the native activity and the asset manager if we would skip these we could go a bit lower but that would not make much sense because OGRE still needs a decent hardware to run.

3. Now add the install directory to your enviroment variables -> ANDROID_SDK = C:\Users\wolfmanfx\AppData\Local\Android\android-sdk

  • Append %ANDROID_SDK%\tools and %ANDROID_SDK%\platform-tools to your PATH variable

4. Download the android ndk

  • Extract the content to C:/android/ndk and create a env var %ANDROID_NDK%
  • Add %ANDROID_NDK% to your path
Copy to clipboard
http://dl.google.com/android/ndk/android-ndk-r8c-windows.zip Android NDK revision 8b is not supported due a bug in the toolchain

5. We need ant (http://ant.apache.org/bindownload.cgi) to build projects from the command line

Copy to clipboard
Apache Ant(TM) version 1.9.1 compiled on May 15 2013

6. The build command for the deps, using Visual Studio command prompt (this is necessary only if you are building the dependencies from source)

Copy to clipboard
cmake -G"NMake Makefiles" -DCMAKE_TOOLCHAIN_FILE=..\cmake\android.toolchain.cmake -DANDROID_ABI=armeabi .. nmake

7. The build command for ogre (for armeabi - if you want to build for armeabi v7a just remove -DANDROID_ABI=armeabi) create a build dir inside the OGRE src tree and cd to this dir and execute this command:

Copy to clipboard
cmake -G"NMake Makefiles" -DCMAKE_TOOLCHAIN_FILE=..\CMake\toolchain\android.toolchain.cmake -DOGRE_DEPENDENCIES_DIR=..\AndroidDependencies -DANDROID_ABI=armeabi -DANDROID_NATIVE_API_LEVEL=9 ..


You may have to call "nmake" after executing the cmake script.
Currently there are a couple targets in the system which you can see by typing "nmake help".
If you want to build the old OgreSampleBrowser, which you can download from the Google Play Store, you have to type "nmake SampleBrowserDummy".

Copy to clipboard
nmake SampleBrowserDummy

Currently, the default value is the JNI Sample, which might not be complete just yet.


Note: standard NMake can only build one file at a time. For functionality similar to "make -j" (parallel builds), use JOM in place of the "nmake" command above. JOM can be found here: http://qt-project.org/wiki/jom

Once you have successfully built Ogre with nmake or JOM, you still need to make the SampleBrowser app itself. This is a native activity and the project resides in a "SampleBrowserNDK" subdirectory of the build directory you provided earlier. Change to this directory, run "ndk-build all" (optionally with a "-j " option — without the quotes of course — for parallel build), and then "ant debug install" to build a debug APK and install it to your device.


Building for Android on Mac OSX host:

Copy to clipboard
cmake -DCMAKE_TOOLCHAIN_FILE="`pwd`/../CMake/toolchain/android.toolchain.cmake" -DOGRE_DEPENDENCIES_DIR="`pwd`/../AndroidDependencies" -DANDROID_ABI=armeabi -DANDROID_NATIVE_API_LEVEL=9 ..


History

Information Version
Sun 27 of May, 2018 22:35 GMT-0000 paroj 67
Sun 03 of Sep, 2017 16:38 GMT-0000 paroj 66
Sun 06 of Sep, 2015 22:10 GMT-0000 dark_sylinc 65
Thu 30 of Jul, 2015 23:51 GMT-0000 holocronweaver add Android JNI build todo 64
Sat 25 of Jul, 2015 04:03 GMT-0000 holocronweaver clarify highest Android API tested 63
Sat 25 of Jul, 2015 03:44 GMT-0000 holocronweaver substantial update to Android build instructions 62
Tue 16 of Sep, 2014 07:33 GMT-0000 DanielSefton 61
Thu 07 of Aug, 2014 19:19 GMT-0000 dark_sylinc Added video tutorial 60
Thu 07 of Aug, 2014 19:16 GMT-0000 dark_sylinc Updated build instructions for Windows. They were ancient and impossible to follow by mortals 59
Mon 19 of May, 2014 19:59 GMT-0000 sajty 58
Tue 27 of Aug, 2013 21:39 GMT-0000 wolfmanfx 57
Mon 17 of Jun, 2013 19:35 GMT-0000 edoardo Updated Ant version 1.9.0 => 1.9.1 56
Fri 17 of May, 2013 20:34 GMT-0000 edoardo And of course I forgot to update the output of the new ant command, now it's done 55
Fri 17 of May, 2013 20:29 GMT-0000 edoardo "apache-ant-1.8.4-bin.zip" doesn't exist anymore, plus the link had a double slash typo 54
Fri 29 of Mar, 2013 15:39 GMT-0000 Emerich 53
Fri 29 of Mar, 2013 15:38 GMT-0000 Emerich 52
Fri 22 of Feb, 2013 06:36 GMT-0000 c6burns updated dependency link to newer binaries (that include optimizer) 51
Fri 22 of Feb, 2013 04:06 GMT-0000 c6burns note that step 6 is optional 50
Thu 21 of Feb, 2013 21:53 GMT-0000 xavier 49
Thu 21 of Feb, 2013 21:53 GMT-0000 xavier 48
Thu 21 of Feb, 2013 21:51 GMT-0000 xavier 47
Thu 21 of Feb, 2013 21:43 GMT-0000 xavier 46
Thu 21 of Feb, 2013 20:34 GMT-0000 xavier 45
Wed 28 of Nov, 2012 11:30 GMT-0000 wolfmanfx 44
Sun 09 of Sep, 2012 22:16 GMT-0000 wolfmanfx 43