History: Building Your Projects With CMake
Preview of version: 19
- «
- »
|
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 |
Introduction
Table of contents
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
CMakeLists.txt
Copy to clipboard
#/* #----------------------------------------------------------------------------- #Filename: CMakeLists.txt #----------------------------------------------------------------------------- # #This source file is part of the # ___ __ __ _ _ _ # /___\__ _ _ __ ___ / / /\ \ (_) | _(_) # // // _` | '__/ _ \ \ \/ \/ / | |/ / | #/ \_// (_| | | | __/ \ /\ /| | <| | #\___/ \__, |_| \___| \/ \/ |_|_|\_\_| # |___/ # Tutorial Framework # http://www.ogre3d.org/tikiwiki/ #----------------------------------------------------------------------------- #*/ cmake_minimum_required(VERSION 2.6) project(OgreApp) if(WIN32) set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}") set(OGRE_SAMPLES_INCLUDEPATH $ENV{OGRE_HOME}/Samples/include ) endif(WIN32) if(UNIX) set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}") set(OGRE_SAMPLES_INCLUDEPATH /usr/local/share/OGRE/samples/Common/include/ ) endif(UNIX) if (CMAKE_BUILD_TYPE STREQUAL "") # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up # differentiation between debug and release builds. set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) endif () set(CMAKE_DEBUG_POSTFIX "_d") set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist") find_package(OGRE REQUIRED) if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha") message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.") endif() find_package(OIS REQUIRED) if(NOT OIS_FOUND) message(SEND_ERROR "Failed to find OIS.") endif() # Find Boost # Prefer static linking in all cases if (NOT OGRE_BUILD_PLATFORM_IPHONE) if (WIN32 OR APPLE) set(Boost_USE_STATIC_LIBS TRUE) else () # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit set(Boost_USE_STATIC_LIBS ${OGRE_STATIC}) endif () set(Boost_ADDITIONAL_VERSIONS "1.37.0" "1.37" "1.38.0" "1.38" "1.39.0" "1.39" "1.40.0" "1.40") # Components that need linking (NB does not include header-only components like bind) set(OGRE_BOOST_COMPONENTS thread date_time regex) find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) if (NOT Boost_FOUND) # Try again with the other type of libs set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS}) find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) endif() find_package(Boost QUIET) endif(NOT OGRE_BUILD_PLATFORM_IPHONE) set(HDRS ./BaseApplication.h ./TutorialApplication.h ) set(SRCS ./BaseApplication.cpp ./TutorialApplication.cpp ) include_directories( ${OIS_INCLUDE_DIRS} ${Boost_INCLUDE_DIR} ${OGRE_INCLUDE_DIRS} ${OGRE_SAMPLES_INCLUDEPATH} ) add_executable(OgreApp WIN32 ${HDRS} ${SRCS}) set_target_properties(OgreApp PROPERTIES DEBUG_POSTFIX _d) target_link_libraries(OgreApp ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${BOOST_LIBRARIES}) # post-build copy for win32 if(WIN32) add_custom_command( TARGET OgreApp PRE_BUILD COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin ) add_custom_command( TARGET OgreApp POST_BUILD COMMAND copy \"$(TargetPath)\" .\\dist\\bin ) endif(WIN32) # if win32, copy the Ogre DLLs and the media over if(WIN32) install(TARGETS OgreApp RUNTIME DESTINATION bin CONFIGURATIONS Release Debug) install(DIRECTORY $ENV{OGRE_HOME}/media DESTINATION ../ ) install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll ${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll ${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_OctreeSceneManager.dll ${OGRE_PLUGIN_DIR_REL}/cg.dll ${OGRE_PLUGIN_DIR_REL}/OIS.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_CgProgramManager.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_ParticleFX.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_BSPSceneManager.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_CgProgramManager.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_PCZSceneManager.dll ${OGRE_PLUGIN_DIR_REL}/Plugin_OctreeZone.dll ${OGRE_PLUGIN_DIR_REL}/resources.cfg ${OGRE_PLUGIN_DIR_REL}/plugins.cfg DESTINATION bin CONFIGURATIONS Release ) install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll ${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll ${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_OctreeSceneManager_d.dll ${OGRE_PLUGIN_DIR_DBG}/cg.dll ${OGRE_PLUGIN_DIR_DBG}/OIS_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_CgProgramManager_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_ParticleFX_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_BSPSceneManager_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_CgProgramManager_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_PCZSceneManager_d.dll ${OGRE_PLUGIN_DIR_DBG}/Plugin_OctreeZone_d.dll ${OGRE_PLUGIN_DIR_DBG}/resources_d.cfg ${OGRE_PLUGIN_DIR_DBG}/plugins_d.cfg DESTINATION bin CONFIGURATIONS Debug ) endif(WIN32)
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.
resources.cfg & plugins.cfg
Linux
Copy 'plugins.cfg' and 'resources.cfg' from the Ogre media directory - usually '/usr/local/share/OGRE' - to your build directory:
Copy to clipboard
cp /usr/local/share/OGRE/plugins.cfg /path/to/OgreApp/build_directory/plugins.cfg cp /usr/local/share/OGRE/resources.cfg /path/to/OgreApp/build_directory/resources.cfg
Windows
TBD