Patch 2789404: fix NVPerfHUD support in trunk
[ogre3d.git] / CMakeLists.txt
blobce6f302baeca2dfa05d7bdb3c3410663dae0dac4
1 ######################################################################
2 # OGRE BUILD SYSTEM
3 # Welcome to the CMake build system for OGRE.
4 # This is the main file where we prepare the general build environment
5 # and provide build configuration options.
6 ######################################################################
8 cmake_minimum_required(VERSION 2.6)
9 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
10 cmake_policy(SET CMP0003 NEW)
12 project(OGRE)
14 # Include necessary submodules
15 set(CMAKE_MODULE_PATH 
16   "${OGRE_SOURCE_DIR}/CMake"
17   "${OGRE_SOURCE_DIR}/CMake/Utils" 
18   "${OGRE_SOURCE_DIR}/CMake/Packages"
20 include(CMakeDependentOption)
21 include(MacroLogFeature)
22 include(OgreConfigTargets)
23 include(PreprocessorUtils)
24 set(OGRE_TEMPLATES_DIR "${OGRE_SOURCE_DIR}/CMake/Templates")
25 set(OGRE_WORK_DIR ${OGRE_BINARY_DIR})
28 #####################################################################
29 # Set up the basic build environment
30 #####################################################################
32 if (CMAKE_BUILD_TYPE STREQUAL "")
33   # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
34   # differentiation between debug and release builds.
35   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)
36 endif ()
38 # determine Ogre version numbers
39 include(OgreGetVersion)
40 ogre_get_version(${OGRE_SOURCE_DIR}/OgreMain/include/OgrePrerequisites.h)
41 message(STATUS "Configuring OGRE ${OGRE_VERSION}")
43 if (NOT APPLE)
44   # Create debug libraries with _d postfix
45   set(CMAKE_DEBUG_POSTFIX "_d")
46 endif ()
48 # Set compiler specific build flags
49 if (CMAKE_COMPILER_IS_GNUCXX)
50   add_definitions(-msse)
51 endif ()
52 if (MSVC)
53   add_definitions(/fp:fast)
54 endif ()
56 if (CMAKE_COMPILER_IS_GNUCXX)
57   # Test for GCC visibility
58   include(CheckCXXCompilerFlag)
59   check_cxx_compiler_flag(-fvisibility=hidden OGRE_GCC_VISIBILITY)
60   if (OGRE_GCC_VISIBILITY)
61     # determine gcc version
62     execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion 
63       OUTPUT_VARIABLE OGRE_GCC_VERSION)
64     message(STATUS "Detected g++ ${OGRE_GCC_VERSION}")
65     message(STATUS "Enabling GCC visibility flags")
66     set(OGRE_GCC_VISIBILITY_FLAGS "-DOGRE_GCC_VISIBILITY -fvisibility=hidden")
67   
68     # check if we can safely add -fvisibility-inlines-hidden
69     string(TOLOWER "${CMAKE_BUILD_TYPE}" OGRE_BUILD_TYPE)
70     if (OGRE_BUILD_TYPE STREQUAL "debug" AND OGRE_GCC_VERSION VERSION_LESS "4.2")
71       message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
72     else ()
73       set(OGRE_GCC_VISIBILITY_FLAGS "${OGRE_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
74     endif ()
75   endif (OGRE_GCC_VISIBILITY)
76 endif (CMAKE_COMPILER_IS_GNUCXX)
78 # determine system endianess
79 include(TestBigEndian)
80 test_big_endian(OGRE_TEST_BIG_ENDIAN)
82 # Add OgreMain include path
83 include_directories("${OGRE_SOURCE_DIR}/OgreMain/include")
84 include_directories("${OGRE_BINARY_DIR}/include")
86 # Find dependencies
87 include(Dependencies)
88 # definitions for samples
89 set(OGRE_LIBRARIES OgreMain) 
90 set(OGRE_CEGUIRenderer_LIBRARIES CEGUIOgreRenderer)
91 set(OGRE_Paging_LIBRARIES OgrePaging)
92 set(OGRE_Terrain_LIBRARIES OgreTerrain)
93 set(OGRE_Plugin_PCZSceneManager_LIBRARIES Plugin_PCZSceneManager)
94 set(OGRE_Plugin_OctreeZone_LIBRARIES Plugin_OctreeZone)
96 # Specify build paths
97 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OGRE_BINARY_DIR}/lib")
98 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OGRE_BINARY_DIR}/lib")
99 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OGRE_BINARY_DIR}/bin")
100 if (WIN32 OR APPLE)
101   if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
102     # We don't want to install in default system location, install is really for the SDK, so call it that
103     SET(CMAKE_INSTALL_PREFIX
104           "${OGRE_BINARY_DIR}/sdk" CACHE PATH "OGRE install prefix" FORCE
105     )
106   endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
107 endif(WIN32 OR APPLE)
110 ######################################################################
111 # Provide user options to customise the build process
112 ######################################################################
114 # Customise what to build
115 option(OGRE_STATIC "Static build" FALSE)
116 cmake_dependent_option(OGRE_BUILD_RENDERSYSTEM_D3D9 "Build Direct3D9 RenderSystem" TRUE "WIN32;DirectX_FOUND" FALSE)
117 cmake_dependent_option(OGRE_BUILD_RENDERSYSTEM_D3D10 "Build Direct3D10 RenderSystem" TRUE "WIN32;DirectX_D3D10_FOUND" FALSE)
118 cmake_dependent_option(OGRE_BUILD_RENDERSYSTEM_GL "Build OpenGL RenderSystem" TRUE "OPENGL_FOUND" FALSE)
119 option(OGRE_BUILD_PLUGIN_BSP "Build BSP SceneManager plugin" TRUE)
120 option(OGRE_BUILD_PLUGIN_OCTREE "Build Octree SceneManager plugin" TRUE)
121 option(OGRE_BUILD_PLUGIN_PCZ "Build PCZ SceneManager plugin" TRUE)
122 option(OGRE_BUILD_PLUGIN_PFX "Build ParticleFX plugin" TRUE)
123 option(OGRE_BUILD_COMPONENT_PAGING "Build Paging component" TRUE)
124 option(OGRE_BUILD_COMPONENT_TERRAIN "Build Terrain component" TRUE)
125 cmake_dependent_option(OGRE_BUILD_COMPONENT_PROPERTY "Build Property component" TRUE "Boost_FOUND" FALSE)
126 cmake_dependent_option(OGRE_BUILD_PLUGIN_CG "Build Cg plugin" TRUE "Cg_FOUND" FALSE)
127 cmake_dependent_option(OGRE_BUILD_CEGUIRENDERER "Build CEGUI renderer" TRUE "CEGUI_FOUND" FALSE)
128 option(OGRE_BUILD_SAMPLES "Build Ogre demos" TRUE)
129 option(OGRE_BUILD_TOOLS "Build the command-line tools" TRUE)
130 option(OGRE_BUILD_TESTS "Build the unit tests & PlayPen" FALSE)
131 # Configure the build
132 #option(OGRE_CONFIG_PROFILING "Enable Ogre profiling code" FALSE)
133 #set(OGRE_CONFIG_ASSERTMODE 0 CACHE STRING 
134 #"Set Ogre assertion mode. Possible values:
135 #  0 - Regular asserts in debug, none in release
136 #  1 - Regular asserts in debug, exceptions in release
137 #  2 - Exceptions in debug and release"
139 option(OGRE_CONFIG_DOUBLE "Use doubles instead of floats in Ogre" FALSE)
140 set(OGRE_CONFIG_ALLOCATOR 2 CACHE STRING
141 "Specify the memory allocator to use. Possible values:
142   1 - Standard allocator
143   2 - nedmalloc
144   3 - User-provided allocator"
146 option(OGRE_CONFIG_CONTAINERS_USE_CUSTOM_ALLOCATOR "STL containers in Ogre use the custom allocator" TRUE)
147 option(OGRE_CONFIG_STRING_USE_CUSTOM_ALLOCATOR "Ogre String uses the custom allocator" FALSE)
148 option(OGRE_CONFIG_MEMTRACK_DEBUG "Enable Ogre's memory tracker in debug mode" FALSE)
149 option(OGRE_CONFIG_MEMTRACK_RELEASE "Enable Ogre's memory tracker in release mode" FALSE)
150 if (Boost_FOUND)
151   set(OGRE_CONFIG_THREADS 0 CACHE STRING 
152   "Enable Ogre thread support for background loading. Possible values:
153     0 - Threading off.
154     1 - Full background loading.
155     2 - Background resource preparation."
156   )
157 else ()
158   set(OGRE_CONFIG_THREADS 0)
159 endif ()
160 cmake_dependent_option(OGRE_CONFIG_DISABLE_FREEIMAGE "Don't build FreeImage codec. If you use this option, you need to provide your own image handling codecs." FALSE "FreeImage_FOUND" TRUE)
161 option(OGRE_CONFIG_DISABLE_DDS "Don't build DDS codec." FALSE)
162 option(OGRE_CONFIG_NEW_COMPILERS "Use the new script compilers." TRUE)
163 # Customise what to install
164 option(OGRE_INSTALL_PLUGINS_HEADERS "Install header files for Ogre plugins." FALSE)
165 option(OGRE_INSTALL_SAMPLES "Install Ogre demos." FALSE)
166 option(OGRE_INSTALL_TOOLS "Install Ogre tools." TRUE)
167 option(OGRE_INSTALL_DOCS "Install documentation." FALSE)
168 option(OGRE_INSTALL_MEDIA "Install media files." FALSE)
169 option(OGRE_INSTALL_SAMPLES_SOURCE "Install samples source files." FALSE)
170 cmake_dependent_option(OGRE_INSTALL_PDB "Install debug pdb files" FALSE "MSVC" FALSE)
171 option(OGRE_FULL_RPATH "Build executables with the full required RPATH to run from their install location." FALSE)
172 option(OGRE_STANDALONE_BUILD "Generate build files that do not reference CMake (e.g. source distro)" FALSE)
177 ###################################################################
178 # configure global build settings based on selected build options
179 ###################################################################
180 include(ConfigureBuild)
183 ##################################################################
184 # Now setup targets
185 ##################################################################
187 # install resource files
188 include(InstallResources)
190 # Setup OgreMain project
191 add_subdirectory(OgreMain)
193 # Setup RenderSystems
194 add_subdirectory(RenderSystems)
196 # Setup Plugins
197 add_subdirectory(PlugIns)
199 # Setup Components
200 add_subdirectory(Components)
202 # Setup CEGUI renderer
203 if (OGRE_BUILD_CEGUIRENDERER)
204   add_subdirectory(Samples/Common/CEGUIRenderer)
205 endif ()
207 # Setup samples
208 add_subdirectory(Samples) 
210 # Setup command-line tools
211 if (OGRE_BUILD_TOOLS)
212   add_subdirectory(Tools)
213 endif ()
215 # Setup tests
216 if (OGRE_BUILD_TESTS)
217   add_subdirectory(Tests)
218 endif ()
220 # Install documentation
221 add_subdirectory(Docs)
223 # Install media files
224 if (OGRE_INSTALL_MEDIA)
225   add_subdirectory(Samples/Media)
226 endif ()
228 # Install CMake modules
229 add_subdirectory(CMake)
231 # Provide CPack packaging target
232 include(Packaging)