Building Your Projects With CMake         Using CMake With Ogre
Image

This is an introduction to using cmake to build your own Ogre projects. For more detailed information about cmake, refer to the official site.

IMPORTANT: These instructions are meant to be used with old releases of Ogre. For Ogre 1.10+, rather use The Tutorials.

Introduction

This is a cmake script for building the Ogre Wiki Tutorial Framework, but it can easily be adapted for your own projects.

Done

Works for Visual Studio, MinGW, and the GCC toolchain.

Prerequisites

Be sure to visit the Prerequisites page!

Note for Windows:
If you don't have Boost installed, you want to set the environment variable BOOST_ROOT to OGRE_HOME/boost


What It Does

The CMake script will configure your project to output the executable into 'BUILD_DIRECTORY/dist/bin', either by post-build copy or by setting the output path directly.
The INSTALL project/target will copy plugins.cfg and resources.cfg to the bin directory, and on Windows it will additionally copy the Ogre DLLs and the Media directory as well (to 'BUILD_DIRECTORY/Media').
Normally, you don't need to build the install target more than once, or whenever Ogre itself changes.

If you don't want, or need that behavior, either don't build INSTALL, or modify it to suit your needs.


What You Need

Convenient All-In-One Download

 Plugin disabled
Plugin attach cannot be executed.
 Plugin disabled
Plugin attach cannot be executed.
(updated for Ogre 1.9)

Just download and un-archive, and you're all set. wink
The download contains a copy of the tutorial framework, the dist directory and the CMake script.
You can also check this github project, which is compatible with Ogre 1.7, 1.8 and 1.9. It also include continuous integration builds on Travis and Gitlab CI. The project is under MIT license and contributions are welcome.

Ogre Wiki Tutorial Framework

Get the Ogre Wiki Tutorial Framework and put the four files in a directory:

  • ogreapp
    • CMakeLists.txt (see below)
    • BaseApplication.h
    • BaseApplication.cpp
    • TutorialApplication.h
    • TutorialApplication.cpp

Dist archive

Download one of these archives and unpack it into the ogreapp directory:

 Plugin disabled
Plugin attach cannot be executed.
|
 Plugin disabled
Plugin attach cannot be executed.

CMakeLists.txt

Info Red

This CMake script assumes the following:

  • Windows: the environment variable OGRE_HOME is set to point to the root directory of your Ogre SDK.
  • Linux: Ogre is installed in the standard path: /usr/local.
  • You're using the 1.7.2 SDK. In 1.7.2 the OIS.dll was renamed to libOIS.dll. As of 1.7.2 it is also necessary to copy the boost dll's into the bin directory because they're no longer statically linked. You can remove that part of the script (at the bottom) if you're using 1.7.1 (but it shouldn't do any harm if you leave it).

CMakeLists

Replace OgreApp with any name you want.
CMAKE_MODULE_PATH points to where you installed the Ogre3D cmake modules.
OGRE_SAMPLES_INCLUDEPATH points to where you installed the Ogre3D Samples framework include directory.
This usually happens when you run make install on Ogre.

How To Use It

After having created your OgreApp source directory, and populated it with the four files from the Ogre Wiki Tutorial Framework and the CMakeLists.txt file, plus the 'dist' directory, you are now ready to build it using CMake.

  1. Open CMake-Gui, choose your source directory ('ogreapp') and a build directory ('ogreapp_build').
  2. Click 'Configure', choose a generator.
  3. Click 'Configure' again if CMake ran without fatal errors.
  4. Click 'Generate'.
  5. Navigate to your 'ogreapp_build' directory.

If you don't see anything in the status window, switch to 'advanced view'.

What you should do next depends on what generator you're using.

Visual Studio

  1. Open the 'OgreApp' solution and build the 'BUILD_ALL' project.
  2. Build the 'INSTALL' project - you only need to build this once to copy the Ogre DLLs, configuration files and media over.

MinGW

  1. Open a command prompt and issue the command: mingw32-make
  2. Install the Ogre files by doing a mingw32-make install

GCC on Linux

  1. In a console, issue the command: make
  2. You should see the make command looking for the parts of the build that are required (Ogre (obviously:)), OIS, boost, etc..) Then the compilation progress indicators
  3. Now, issue the command: make install Don't worry: it's a 'fake' install, it's only local. What it does is copy the 'dist' directory over to your build directory.
  4. Run the "OgreApp" bin and you should see a blank screen with some OgreSDK info overlays. If you've gotten this far, your build process works!
  5. If you get errors, you might need to copy the plugins.cfg from /usr/share/OGRE to your dist directory (use the one in your source directory, not the one in the build directory):
    cp /usr/share/OGRE/plugins.cfg ~/programming/ogreapp/dist/bin/plugins.cfg


If you're a Linux user, be sure to check out Setting Up An Application - Linux for ways to import the CMake script into NetBeans, QtCreator, KDevelop and other development environments.

Happy coding! :-)