History: Building Your Projects With CMake
Source of version: 57
Copy to clipboard
{BOX(width="100%",class="Layout_box9")}{SPLIT(colsize=10%|70%)}{IMG(src="img/wiki_up/Libraries.png",imalign="left",link="Building Your Projects With CMake",title="Building Your Projects With CMake")}{IMG}
---
{DIV(class="bigBold")}((Building Your Projects With CMake)){DIV}
This section is an introduction on how to use CMake to build your own projects and have them link against Ogre. For more detailed information about CMake, refer to the official CMake website: [http://www.cmake.org]
{SPLIT}{BOX}
!Introduction
This is a simple CMake script for use in your own projects.
The sample script uses the ((Ogre Wiki Tutorial Framework)), but you can adapt it easily.
{DIV(class="Layout_box6")}%done% Works for Visual Studio and MinGW on Windows, and regular GCC tool-chain on Linux.{DIV}
Quick download: {ATTACH(id="146",icon="1",showdesc="0")}{ATTACH}
{maketoc}
!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 {MONO()}BOOST_ROOT{MONO} to {MONO()}OGRE_HOME/boost_1_42{MONO}
---
!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
{ATTACH(id="146",icon="1",showdesc="0")}{ATTACH}
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.
!!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 {MONO()}ogreapp{MONO} directory:
{ATTACH(id="128",icon="1",showdesc="1")}{ATTACH} | {ATTACH(id="135",icon="1",showdesc="1")}{ATTACH}
!!CMakeLists.txt
{TRANSCLUDE(page="infodiv")}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).
{TRANSCLUDE}
((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.
# Open CMake-Gui, choose your source directory ('''ogreapp''') and a build directory ('''ogreapp_build''').
# Click '''Configure''', choose a generator.
# Click '''Configure''' again if CMake ran without fatal errors.
# Click '''Generate'''.
# 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
# Open the '''OgreApp''' solution and build the '''BUILD_ALL''' project.
# Build the '''INSTALL''' project - you only need to build this once to copy the Ogre DLLs, configuration files and media over.
!!MinGW
# Open a command prompt and issue the command: {MONO()}mingw32-make{MONO}
# Install the Ogre files by doing a {MONO()}mingw32-make install{MONO}
!!GCC on Linux
# In a console, issue the command: {MONO()}make{MONO}
# 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
# Now, issue the command: {MONO()}make install{MONO} 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.
# 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!
# If you get errors, you might need to copy the plugins.cfg from /usr/local/share/OGRE to your dist directory (use the one in your source directory, not the one in the build directory):
+{MONO()}cp /usr/local/share/OGRE/plugins.cfg ~/programming/ogreapp/dist/bin/plugins.cfg{MONO}
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! :)