1#-------------------------------------------------------------------
2# This file is part of the CMake build system for OGRE
3#     (Object-oriented Graphics Rendering Engine)
4# For the latest info, see http://www.ogre3d.org/
5#
6# The contents of this file are placed in the public domain. Feel
7# free to make use of it in any way you like.
8#-------------------------------------------------------------------
9
10######################################################################
11# OGRE SAMPLES BUILD SYSTEM
12######################################################################
13
14cmake_minimum_required(VERSION 2.6.2)
15set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
16cmake_policy(SET CMP0003 NEW)
17
18# CMake 2.8.2 has a bug that creates unusable Xcode projects when using ARCHS_STANDARD_32_BIT
19# to specify both armv6 and armv7.
20if(OGRE_BUILD_PLATFORM_APPLE_IOS AND (CMAKE_VERSION VERSION_EQUAL 2.8.2) AND (CMAKE_GENERATOR STREQUAL "Xcode"))
21	message(FATAL_ERROR "CMake 2.8.2 cannot create compatible Xcode projects for iOS, please download the latest version or an older release from http://www.cmake.org/files/")
22endif()
23
24# Just debug / release since that's all that's included in SDK. Only release for iOS/OS X
25if(APPLE)
26  set (CMAKE_CONFIGURATION_TYPES "Release" CACHE STRING "" FORCE)
27else()
28  set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
29endif()
30
31# Use relative paths
32# Note that up to CMake 2.8.0 on MSVC the .pdbs are still referenced absolutely
33# This has been fixed with a patch so I expect that in future we will be able to use this
34# to pre-generate the sample projects for the SDK.
35if(WIN32)
36  # This seems to break Xcode projects so definitely don't enable on Apple builds
37  set(CMAKE_USE_RELATIVE_PATHS true)
38  set(CMAKE_SUPPRESS_REGENERATION true)
39endif()
40
41project(OGRE)
42
43# Find actual Ogre root
44if (WIN32 OR APPLE)
45  get_filename_component(OGRE_ROOT_DIR "${OGRE_SOURCE_DIR}" ABSOLUTE)
46  set(OGRE_TEMPLATES_DIR "${OGRE_ROOT_DIR}/cmake")
47  set(OGRE_WORK_DIR "${OGRE_ROOT_DIR}")
48  set(CMAKE_MODULE_PATH "${OGRE_ROOT_DIR}/cmake")
49elseif (UNIX)
50  get_filename_component(OGRE_ROOT_DIR "${OGRE_SOURCE_DIR}/../.." ABSOLUTE)
51  set(OGRE_TEMPLATES_DIR "${OGRE_ROOT_DIR}/lib/OGRE/cmake")
52  set(OGRE_WORK_DIR "${OGRE_ROOT_DIR}")
53  set(CMAKE_MODULE_PATH "${OGRE_ROOT_DIR}/lib/OGRE/cmake")
54endif ()
55
56if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
57  #  By default, install to the Ogre SDK root
58  SET(CMAKE_INSTALL_PREFIX
59   "${OGRE_ROOT_DIR}" CACHE PATH "OGRE install prefix" FORCE
60  )
61endif ()
62
63# Include necessary submodules
64set(OGRE_SDK_BUILD TRUE)
65set(OGRE_LIB_TYPE @OGRE_LIB_TYPE@)
66set(OGRE_STATIC @OGRE_STATIC@)
67include(OgreConfigTargets)
68set(CMAKE_PREFIX_PATH "${OGRE_ROOT_DIR}")
69set(OGRE_INSTALL_SAMPLES FALSE)
70if (NOT APPLE)
71  # Create debug libraries with _d postfix
72  set(CMAKE_DEBUG_POSTFIX "_d")
73endif ()
74# Boost is included
75set (BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/boost")
76
77#####################################################################
78# Set up the basic build environment
79#####################################################################
80
81# Set compiler specific build flags
82if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
83  list(APPEND CMAKE_CXX_FLAGS -msse)
84endif ()
85if (APPLE AND OGRE_BUILD_PLATFORM_APPLE_IOS)
86  # Set build variables
87  set(XCODE_ATTRIBUTE_SDKROOT iphoneos)
88  if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
89    execute_process(COMMAND xcodebuild -version -sdk "${XCODE_ATTRIBUTE_SDKROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
90    string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
91  else()
92    set(CMAKE_OSX_SYSROOT iphoneos)
93  endif()
94
95  set(CMAKE_OSX_DEPLOYMENT_TARGET "")
96  set(CMAKE_EXE_LINKER_FLAGS "-framework Foundation -framework CoreGraphics -framework QuartzCore -framework UIKit")
97  set(XCODE_ATTRIBUTE_GCC_UNROLL_LOOPS "YES")
98  set(XCODE_ATTRIBUTE_LLVM_VECTORIZE_LOOPS "YES")
99  set(XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
100  set(OGRE_BUILD_RENDERSYSTEM_GLES TRUE CACHE BOOL "Forcing OpenGL ES RenderSystem for iOS" FORCE)
101  set(OGRE_BUILD_RENDERSYSTEM_GLES2 TRUE CACHE BOOL "Forcing OpenGL ES 2 RenderSystem for iOS" FORCE)
102  set(OGRE_STATIC TRUE CACHE BOOL "Forcing static build for iOS" FORCE)
103  set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.yourcompany.\${PRODUCT_NAME:rfc1034identifier}")
104  set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_INCLUDING_64_BIT)")
105
106  remove_definitions(-msse)
107endif ()
108if (MSVC)
109  add_definitions(/fp:fast)
110endif ()
111
112# Find dependencies
113find_package(OGRE REQUIRED)
114find_package(OIS REQUIRED)
115
116# Need to get the Cg path for OS X post build scripts.
117if (APPLE AND NOT OGRE_RenderSystem_GLES2_FOUND AND NOT OGRE_RenderSystem_GLES_FOUND)
118  find_package(Cg REQUIRED)
119endif()
120
121if (NOT OGRE_BUILD_PLATFORM_APPLE_IOS)
122	if (WIN32 OR APPLE)
123		set(Boost_USE_STATIC_LIBS TRUE)
124	else ()
125		# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
126		set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
127	endif ()
128	if (MINGW)
129		# this is probably a bug in CMake: the boost find module tries to look for
130		# boost libraries with name libboost_*, but CMake already prefixes library
131		# search names with "lib". This is the workaround.
132		set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
133	endif ()
134    set(Boost_ADDITIONAL_VERSIONS "1.54" "1.54.0" "1.53" "1.53.0" "1.52" "1.52.0" "1.51" "1.51.0" "1.50" "1.50.0" "1.49" "1.49.0" "1.48" "1.48.0" "1.47" "1.47.0" "1.46" "1.46.0" "1.45" "1.45.0" "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40")
135    # Components that need linking (NB does not include header-only components like bind)
136    set(OGRE_BOOST_COMPONENTS thread date_time)
137    find_package(Boost QUIET)
138    if (NOT Boost_FOUND)
139        if(Boost_USE_STATIC_LIBS)
140            set(Boost_USE_STATIC_LIBS OFF)
141        else()
142            set(Boost_USE_STATIC_LIBS ON)
143        endif()
144        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
145    endif()
146
147    if(Boost_FOUND AND Boost_VERSION GREATER 104900)
148        set(OGRE_BOOST_COMPONENTS thread date_time system chrono)
149        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
150    endif()
151
152	# Set up referencing of Boost
153	include_directories(${Boost_INCLUDE_DIR})
154	add_definitions(-DBOOST_ALL_NO_LIB)
155	set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
156else()
157	set(BOOST_LIBRARYDIR "${CMAKE_CURRENT_SOURCE_DIR}/boost/lib")
158	set(BOOST_INCLUDEDIR "${CMAKE_CURRENT_SOURCE_DIR}/boost/include")
159	set(Boost_USE_STATIC_LIBS TRUE)
160	set(Boost_NO_SYSTEM_PATHS TRUE)
161    set(Boost_USE_MULTITHREADED OFF)
162
163    set(Boost_ADDITIONAL_VERSIONS "1.54" "1.54.0" "1.53" "1.53.0" "1.52" "1.52.0" "1.51" "1.51.0" "1.50" "1.50.0" "1.49" "1.49.0" "1.48" "1.48.0" "1.47" "1.47.0" "1.46" "1.46.0" "1.45" "1.45.0" "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40")
164    # Components that need linking (NB does not include header-only components like bind)
165    set(OGRE_BOOST_COMPONENTS thread date_time)
166    find_package(Boost QUIET)
167    if (NOT Boost_FOUND)
168        if(Boost_USE_STATIC_LIBS)
169            set(Boost_USE_STATIC_LIBS OFF)
170        else()
171            set(Boost_USE_STATIC_LIBS ON)
172        endif()
173        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
174    endif()
175
176    if(Boost_FOUND AND Boost_VERSION GREATER 104900)
177        set(OGRE_BOOST_COMPONENTS thread date_time system chrono)
178        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
179    endif()
180
181	# Set up referencing of Boost
182	include_directories(${Boost_INCLUDE_DIR})
183	add_definitions(-DBOOST_ALL_NO_LIB)
184	set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
185endif(NOT OGRE_BUILD_PLATFORM_APPLE_IOS)
186
187include_directories(
188  ${OGRE_INCLUDE_DIRS}
189  ${OGRE_Plugin_PCZSceneManager_INCLUDE_DIRS}
190  ${OGRE_Plugin_OctreeZone_INCLUDE_DIRS}
191  ${OIS_INCLUDE_DIRS}
192  ${CMAKE_CURRENT_SOURCE_DIR}/Common/include
193)
194if (APPLE)
195  if (OGRE_BUILD_PLATFORM_APPLE_IOS)
196    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/OGRE/iOS")
197  else ()
198    # Set 10.6 as the base SDK by default
199    set(XCODE_ATTRIBUTE_SDKROOT macosx)
200    if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
201      execute_process(COMMAND xcodebuild -version -sdk "${XCODE_ATTRIBUTE_SDKROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
202      string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
203    else()
204      set(CMAKE_OSX_SYSROOT macosx)
205    endif()
206
207    set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6)
208    set(CMAKE_OSX_ARCHITECTURES ${ARCHS_STANDARD_32_64_BIT})
209    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/OGRE/OSX"
210      "${CMAKE_CURRENT_SOURCE_DIR}/include/OGRE/RenderSystems/GL"
211      "${CMAKE_CURRENT_SOURCE_DIR}/include/OGRE/RenderSystems/GL/OSX")
212  endif ()
213endif (APPLE)
214
215if (OGRE_RTShaderSystem_FOUND)
216	add_definitions(-DINCLUDE_RTSHADER_SYSTEM)
217	ogre_add_component_include_dir(RTShaderSystem)
218		# Link to RT Shader System if enabled.
219  		set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${OGRE_RTShaderSystem_LIBRARIES})
220endif()
221
222if (OGRE_Terrain_FOUND)
223    ogre_add_component_include_dir(Terrain)
224    set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${OGRE_Terrain_LIBRARIES})
225endif ()
226
227if (OGRE_Paging_FOUND)
228    ogre_add_component_include_dir(Paging)
229    set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${OGRE_Paging_LIBRARIES})
230endif ()
231
232if (OGRE_Volume_FOUND)
233    ogre_add_component_include_dir(Volume)
234    set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${OGRE_Volume_LIBRARIES})
235endif ()
236
237if (OGRE_Overlay_FOUND)
238    ogre_add_component_include_dir(Overlay)
239    set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${OGRE_Overlay_LIBRARIES})
240endif ()
241
242if (UNIX AND NOT APPLE)
243  # on Linux, shipped samples will still be compiled with CMake, so we need
244  # the .cfg files in the build directory.
245  configure_file(${OGRE_SOURCE_DIR}/plugins.cfg ${OGRE_BINARY_DIR}/bin/plugins.cfg COPYONLY)
246  configure_file(${OGRE_SOURCE_DIR}/resources.cfg ${OGRE_BINARY_DIR}/bin/resources.cfg COPYONLY)
247  configure_file(${OGRE_SOURCE_DIR}/samples.cfg ${OGRE_BINARY_DIR}/bin/samples.cfg COPYONLY)
248  configure_file(${OGRE_SOURCE_DIR}/quakemap.cfg ${OGRE_BINARY_DIR}/bin/quakemap.cfg COPYONLY)
249endif ()
250
251if (MINGW)
252  # MinGW also relies on CMake, but we can just output to source dir.
253  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
254    add_definitions(-DDEBUG)
255    set(OGRE_BUILD_TYPE "debug")
256  else ()
257    set(OGRE_BUILD_TYPE "release")
258  endif ()
259  set(OGRE_ARCHIVE_OUTPUT ${OGRE_SOURCE_DIR}/lib/${OGRE_BUILD_TYPE})
260  set(OGRE_LIBRARY_OUTPUT ${OGRE_SOURCE_DIR}/lib/${OGRE_BUILD_TYPE})
261  set(OGRE_RUNTIME_OUTPUT ${OGRE_SOURCE_DIR}/bin/${OGRE_BUILD_TYPE})
262endif ()
263
264
265if (OGRE_STATIC)
266  # need to link against all plugins
267  if (OGRE_Plugin_BSPSceneManager_FOUND)
268    include_directories(${OGRE_Plugin_BSPSceneManager_INCLUDE_DIRS})
269    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_Plugin_BSPSceneManager_LIBRARIES})
270  endif ()
271  if (OGRE_Plugin_CgProgramManager_FOUND)
272    include_directories(${OGRE_Plugin_CgProgramManager_INCLUDE_DIRS})
273    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_Plugin_CgProgramManager_LIBRARIES})
274  endif ()
275  if (OGRE_Plugin_OctreeSceneManager_FOUND)
276    include_directories(${OGRE_Plugin_OctreeSceneManager_INCLUDE_DIRS})
277    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_Plugin_OctreeSceneManager_LIBRARIES})
278  endif ()
279  if (OGRE_Plugin_ParticleFX_FOUND)
280    include_directories(${OGRE_Plugin_ParticleFX_INCLUDE_DIRS})
281    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_Plugin_ParticleFX_LIBRARIES})
282  endif ()
283  if (OGRE_RenderSystem_Direct3D9_FOUND)
284    include_directories(${OGRE_RenderSystem_Direct3D9_INCLUDE_DIRS})
285    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_RenderSystem_Direct3D9_LIBRARIES})
286  endif ()
287  if (OGRE_RenderSystem_Direct3D11_FOUND)
288    include_directories(${OGRE_RenderSystem_Direct3D11_INCLUDE_DIRS})
289    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_RenderSystem_Direct3D11_LIBRARIES})
290  endif ()
291  if (OGRE_RenderSystem_GL_FOUND)
292    include_directories(${OGRE_RenderSystem_GL_INCLUDE_DIRS})
293    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_RenderSystem_GL_LIBRARIES})
294  endif ()
295  if (OGRE_RenderSystem_GLES_FOUND)
296    include_directories(${OGRE_RenderSystem_GLES_INCLUDE_DIRS})
297    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_RenderSystem_GLES_LIBRARIES})
298  endif ()
299  if (OGRE_RenderSystem_GLES2_FOUND)
300    include_directories(${OGRE_RenderSystem_GLES2_INCLUDE_DIRS})
301    set(OGRE_PLUGIN_LIBRARIES ${OGRE_PLUGIN_LIBRARIES} ${OGRE_RenderSystem_GLES2_LIBRARIES})
302  endif ()
303endif ()
304
305add_subdirectory(Samples)
306