forked from realXtend/tundra
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
408 lines (363 loc) · 18.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# Set project name
project(tundra)
# CMake version requirement
cmake_minimum_required(VERSION 2.6.0)
# Policy CMP0005 - Preprocessor definition values are now escaped automatically.
if (COMMAND cmake_policy)
cmake_policy(SET CMP0005 NEW)
endif()
# See src/Core/TundraCore/CMakeLists.txt for application name and version definitions.
message("") # newline before any other output from the script
# TUNDRA_NO_BOOST defines whether we want to replace usage of Boost with the C++ TR1/11 standard equivalents.
# Setting TUNDRA_NO_BOOST to TRUE, i.e. disabling usage of Boost in the Tundra codebase, requires compiler
# with up-to-date C++ TR1 and preferably the C99 standard cstdint header. Also if the used compiler has C++11
# make_shared function available, it is used.
# If TUNDRA_NO_BOOST is set to TRUE, kNet must also be built without Boost dependency. In order to make the
# Tundra build fully free of Boost, you must also build Ogre and AssImp, which depend on Boost by default,
# with Boost disabled. See the dependencies scripts for instructions how to control this.
# On Linux TUNDRA_NO_BOOST can not yet be used
option(TUNDRA_NO_BOOST "Specifies whether Tundra is built without Boost." ON)
option(TUNDRA_BOOST_REGEX "Enable regex from the Boost libraries. Can be used with TUNDRA_NO_BOOST=ON. Tip: Use if used STL does not implemement regex." OFF)
option(TUNDRA_BOOST_SYSTEM "Enable system from the Boost libraries. Can be used with TUNDRA_NO_BOOST=ON. Tip: Use if building WebSocketServerModule." OFF)
option(TUNDRA_CPP11_ENABLED "Enables usage of certain C++11 features on Tundra." FALSE)
if (APPLE)
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "10.6")
endif()
if (APPLE AND TUNDRA_CPP11_ENABLED) # todo: Test if this works on Linux too
# Compiler-specific C++11 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8))
message(FATAL_ERROR "${PROJECT_NAME} C++11 features require GCC 4.8 or greater.")
else ()
message(STATUS "C++11 features enabled for GCC")
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION)
if (NOT (CLANG_VERSION VERSION_GREATER 4.1 OR CLANG_VERSION VERSION_EQUAL 4.1))
message(FATAL_ERROR "${PROJECT_NAME} C++11 features require clang 4.1 or greater.")
else ()
message(STATUS "C++11 features enabled for Clang")
endif ()
else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11!")
endif ()
if ("${CMAKE_GENERATOR}" MATCHES "Xcode")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
endif()
elseif (UNIX AND TUNDRA_CPP11_ENABLED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (MSVC AND TUNDRA_CPP11_ENABLED)
# MSVC has partial C++11 support beginning in VC10
if (MSVC90)
message(FATAL_ERROR "VC9 does not support C++11 features!")
endif()
endif()
option(TUNDRA_NO_AUDIO "Specifies whether Tundra is built without OpenAL audio playback capabilities." OFF)
if (ANDROID)
add_definitions(-DANDROID)
# TODO For now, disable audio on Android
set(TUNDRA_NO_AUDIO OFF)
endif()
macro(PrintUsedEnvVariables)
# Print out the resolved variables. Note that this does not print the env variables
# in most cases as they should be resolved to our CMake variables and get cached.
# This way this printed list wont lie if ran without env variables and we are still
# successfully finding all the deps from our cacher (or in bad cases assumed) dirs.
message("===================== Used Environment Variables =====================\n") # 70 visible chars
message(STATUS "TUNDRA_DEP_PATH = " ${ENV_TUNDRA_DEP_PATH})
message(STATUS "QTDIR = " ${ENV_QT_DIR})
if (NOT TUNDRA_NO_BOOST)
message (STATUS "BOOST_ROOT = " ${BOOST_ROOT})
endif()
message(STATUS "OGRE_HOME = " ${OGRE_DIR}) # OGRE_DIR is our internal OGRE_HOME
message(STATUS "SKYX_HOME = " ${SKYX_HOME})
message(STATUS "HYDRAX_HOME = " ${HYDRAX_HOME})
message(STATUS "KNET_DIR = " ${KNET_DIR})
message(STATUS "BULLET_DIR = " ${BULLET_DIR})
message("")
endmacro()
macro(PrintUsedBuildConfig)
message("===================== Used Build Configuration =======================\n")
message(STATUS "TUNDRA_NO_BOOST = " ${TUNDRA_NO_BOOST})
message(STATUS "TUNDRA_NO_AUDIO = " ${TUNDRA_NO_AUDIO})
message(STATUS "TUNDRA_CPP11_ENABLED = " ${TUNDRA_CPP11_ENABLED})
message(STATUS "TUNDRACORE_SHARED = " ${TUNDRACORE_SHARED})
message(STATUS "BUILD_SDK_ONLY = " ${BUILD_SDK_ONLY})
message(STATUS "INSTALL_BINARIES_ONLY = " ${INSTALL_BINARIES_ONLY})
message(STATUS "INSTALL_EXAMPLE_SCENES = " ${INSTALL_EXAMPLE_SCENES})
message(STATUS "ENABLE_TRANSLATIONS = " ${ENABLE_TRANSLATIONS})
message(STATUS "ENABLE_BUILD_OPTIMIZATIONS = " ${ENABLE_BUILD_OPTIMIZATIONS})
message(STATUS "ENABLE_HYDRAX = " ${ENABLE_HYDRAX})
message(STATUS "ENABLE_SKYX = " ${ENABLE_SKYX})
message(STATUS "ENABLE_OPEN_ASSET_IMPORT = " ${ENABLE_OPEN_ASSET_IMPORT})
message(STATUS "ENABLE_PROFILING = " ${ENABLE_PROFILING})
message(STATUS "ENABLE_JS_PROFILING = " ${ENABLE_JS_PROFILING})
message(STATUS "ENABLE_MEMORY_LEAK_CHECKS = " ${ENABLE_MEMORY_LEAK_CHECKS})
message("")
message(STATUS "Install prefix = " ${CMAKE_INSTALL_PREFIX})
message("")
endmacro()
macro(GetLastElementFromPath dirPath outputParam)
string (FIND ${dirPath} "/" lastPathSepIndex REVERSE)
# This path does not have any subdirs in it
if (${lastPathSepIndex} STREQUAL "-1")
set (${outputParam} ${dirPath})
# Path has subdirs, pick the last
else ()
math(EXPR lastPathSepIndex "${lastPathSepIndex} + 1")
string(SUBSTRING ${dirPath} ${lastPathSepIndex} -1 ${outputParam})
endif ()
endmacro ()
macro(RemoveLastElementFromPath dirPath outputParam)
string (FIND ${dirPath} "/" lastPathSepIndex REVERSE)
# This path does not have any subdirs in it
if (${lastPathSepIndex} STREQUAL "-1")
set (${outputParam} ${dirPath})
# Path has subdirs, pick the path in front of it
else ()
string(SUBSTRING ${dirPath} 0 ${lastPathSepIndex} ${outputParam})
endif ()
endmacro ()
# The AddEntityComponent macro adds the static EC lib from the given sourceFolder directory to the build.
# The componentName == A subfolder in src/EntityComponents/ or a relative path to the EC directory where the CMakeLists.txt is located.
# Use this macro when adding ECs to the build, since this macro tracks the set of ECs that are added, so that the individual
# modules get #defines in C++ code for each EC that is present. This allows conditionally excluding ECs from the build.
# Note that for eg. AddEntityComponent(3rdparty/myecs/EC_Thingie) the define will be EC_Thingie_ENABLED and you would expect.
# Examples: AddEntityComponent(EC_Sound)
# AddEntityComponent(3rdparty/myecs/EC_Thingie)
macro(AddEntityComponent componentName)
set (PROJECT_TYPE "EntityComponents")
# Chekc if the component is in our default entity components location
# note: from cmake docs: IS_DIRECTORY Behavior is well-defined only for full paths.
if (IS_DIRECTORY ${PROJECT_BINARY_DIR}/src/EntityComponents/${componentName})
add_subdirectory (src/EntityComponents/${componentName})
set (${componentName}_ENABLED 1)
set (USED_ENTITYCOMPONENTS ${USED_ENTITYCOMPONENTS} ${componentName})
elseif (IS_DIRECTORY ${PROJECT_BINARY_DIR}/${componentName})
add_subdirectory (${componentName})
GetLastElementFromPath(${componentName} compNameFromRelPath)
set(${compNameFromRelPath}_ENABLED 1)
set(USED_ENTITYCOMPONENTS ${USED_ENTITYCOMPONENTS} ${compNameFromRelPath})
else ()
message(FATAL_ERROR "Could not resolve AddEntityComponent() call with path " ${componentName} ". Are you sure the component is there?")
endif ()
set (PROJECT_TYPE "")
endmacro()
# AddProject takes in one or two parameters:
# - One param : argv0 == the relative directory (to the root CMakeLists.txt) where you project is and that contains the CMakeLists.txt for this project.
# - Two params : argv0 == 'Core'|'Application'. argv1 folder name of the project in the src/argv0/
# More useful for building the Tundra project when including platform provided projects.
# Note: One param projects or two param "Application" type plugins will always be omitted if BUILD_SDK_ONLY is true!
# Note: Due to the CMake's add_subdirectory restrictions, the directory cannot be outside the Tundra source tree, hopefully we can go around this one day.
# Examples: AddProject(Core Input)
# AddProject(Application JavascriptModule)
# AddProject(mysubdir/MyPlugin)
function(AddProject)
set (PROJECT_TYPE ${ARGV0})
if (NOT ARGV1)
if (BUILD_SDK_ONLY)
message (STATUS "** Omitting Application level project " ${ARGV0} " because BUILD_SDK_ONLY is set to TRUE")
else ()
add_subdirectory(${ARGV0})
endif ()
else ()
if (NOT ${ARGV0} STREQUAL "Core" AND NOT ${ARGV0} STREQUAL "Application")
message (FATAL_ERROR "You are trying to use AddProject macro with invalid project type parameter: " ${ARGV0} " with project name " ${ARGV1})
endif()
if (BUILD_SDK_ONLY AND ${ARGV0} STREQUAL "Application")
message (STATUS "** Omitting Application level project " ${ARGV1} " because BUILD_SDK_ONLY is set to TRUE")
else ()
add_subdirectory(src/${ARGV0}/${ARGV1})
endif ()
endif ()
set (PROJECT_TYPE "")
endfunction()
# Set CMake library search policy
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0005 NEW)
endif()
if (APPLE)
EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE OSX_MINOR_VERSION_RAW)
STRING(REGEX REPLACE "10\\.([0-9]).*" "\\1" MACOSX_VERSION "${OSX_MINOR_VERSION_RAW}")
if(${MACOSX_VERSION} LESS 6)
message(FATAL_ERROR "Unsupported version of OS X: ${OSX_MINOR_VERSION_RAW}")
return()
elseif (${MACOSX_VERSION} LESS 7)
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
endif()
endif()
# Detect that a supported Visual Version is used and set up helper variables VC_VER and VS_PLATFORM
if (MSVC)
if (CMAKE_CL_64)
set(VS_PLATFORM "x64")
else()
SET(VS_PLATFORM "Win32")
endif()
if (MSVC90)
set(VC_VER "vc9")
elseif(MSVC10)
set(VC_VER "vc10")
else()
message(STATUS "-- Warning: Unsupported Visual Studio version detected. Currently Visual Studio 2008 and 2010 are supported.")
endif()
endif()
# Set compiler warning levels.
# On MSVC, use warning level 4 but disable the following warnings:
# C4127 conditional expression is constant
# C4512 'class' : assignment operator could not be generated
# TODO Ideally we wouldn't like to disable these, but if we don't, we get warning spam from Qt files.
if ("${CMAKE_CXX_FLAGS}" STREQUAL "")
if (MSVC)
add_definitions (/W4 /wd4127 /wd4512)
else ()
add_definitions (-Wall -Wextra -Wno-unknown-pragmas -Wno-unused -Wno-reorder -Wno-switch -Wno-write-strings)
endif()
endif ()
# Set CMake custom module path & include them
# The following CMake modules are required for the project to build.
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} cmake)
include (Sagase)
include (ModuleSetup)
include (ConfigurePackages)
include (TundraInstall)
include (FindBoostTundra)
include (FindOgre)
include (FindDirectX)
# Disable unnecessary build types
if (NOT LINUX)
set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Configurations" FORCE)
else()
set(CMAKE_CONFIGURATION_TYPES "" CACHE STRING "Configurations" FORCE)
endif()
if (MSVC)
# In Visual Studio, use Unicode character set
add_definitions(-DUNICODE -D_UNICODE)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
# Currently, kNet uses this flag for Unix OSes. (required also for client-side headers).
# TODO This can be removed when kNet's master is merged to stable (has not been done yet as of 2014-11-05),
# https://github.com/juj/kNet/commit/0f35b17c71952bc362c241212caf31209b1051a7
add_definitions(-DUNIX)
endif()
# On all platforms, we enable PCH files by default.
add_definitions (-DPCH_ENABLED)
SET(PCH_ENABLED 1)
# Windows-only: Possibility to opt out of linking against DirectX-specific libs.
# Enabled more efficient texture blitting to Ogre using DirectX. This makes RenderSystem_Direct3D9 mandatory.
set (ENABLE_DIRECTX 1)
# Set global hardcoded install prefix. User cannot change this at the moment, until we figure how we want to use this!
# Call the cleanup step that cleans the install prefix before every installations. This is important as module setups might change between builds.
set (CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/build)
set (TUNDRA_BIN ${PROJECT_BINARY_DIR}/bin)
setup_clean_install_step()
# Set normalized path for common environment variables
# If you want to use custom built dependencies along side with TUNDRA_DEP_PATH
# you can define the following env variables:
# OGRE_HOME, SKYX_HOME, HYDRAX_HOME, KNET_DIR_QT47, BULLET_DIR, ASSIMP_DIR
file (TO_CMAKE_PATH "$ENV{TUNDRA_DEP_PATH}" ENV_TUNDRA_DEP_PATH)
file (TO_CMAKE_PATH "$ENV{QTDIR}" ENV_QT_DIR)
file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" ENV_BOOST_ROOT)
file (TO_CMAKE_PATH "$ENV{OGRE_HOME}" ENV_OGRE_HOME)
file (TO_CMAKE_PATH "$ENV{SKYX_HOME}" ENV_SKYX_HOME)
file (TO_CMAKE_PATH "$ENV{HYDRAX_HOME}" ENV_HYDRAX_HOME)
file (TO_CMAKE_PATH "$ENV{KNET_DIR}" ENV_KNET_DIR)
file (TO_CMAKE_PATH "$ENV{BULLET_DIR}" ENV_BULLET_DIR)
file (TO_CMAKE_PATH "$ENV{ASSIMP_DIR}" ENV_ASSIMP_DIR)
# Utilize CMake's cache for the environment variables. This is needed if e.g.. TUNDRA_DEP_PATH
# was set on the first run of CMake, but once e.g.. Visual Studio auto runs CMake (after changes to any CMakeLists.txt)
# it is no longer set. This will result us in losing all the acquired dependency information that was not found with
# CMake macros find_packade, find_library etc. that automatically cache. This is more flexible for many use cases to remember
# if we once got a valid TUNDRA_DEP_PATH. If env variable TUNDRA_DEP_PATH is present, the cache is never read but instead updated.
if (NOT ENV_TUNDRA_DEP_PATH)
set (ENV_TUNDRA_DEP_PATH ${CACHED_ENV_TUNDRA_DEP_PATH})
else ()
set (CACHED_ENV_TUNDRA_DEP_PATH ${ENV_TUNDRA_DEP_PATH} CACHE PATH "Tundra build dependency path" FORCE)
endif ()
if (NOT ENV_QT_DIR)
set (ENV_QT_DIR ${CACHED_ENV_QT_DIR})
else ()
set (CACHED_ENV_QT_DIR ${ENV_QT_DIR} CACHE PATH "Tundra build Qt path" FORCE)
endif ()
if (NOT ENV_OGRE_HOME)
set (ENV_OGRE_HOME ${CACHED_ENV_OGRE_HOME})
else ()
set (CACHED_ENV_OGRE_HOME ${ENV_OGRE_HOME} CACHE PATH "Tundra build Ogre path" FORCE)
endif ()
# If we still haven't resolved TUNDRA_DEP_PATH report a fatal error.
# ENV_QT_DIR and ENV_OGRE_HOME are not fatal if missing.
if (NOT ENV_TUNDRA_DEP_PATH)
message(FATAL_ERROR "TUNDRA_DEP_PATH could not be resolved from a environment variable or from cmake cache!")
endif ()
message("====================== Configuring Dependencies ======================\n")
# Find needed external libraries, abort on error
configure_boost()
configure_qt4()
configure_qjson()
configure_ogre()
if (NOT TUNDRA_NO_AUDIO)
configure_openal()
endif()
use_package_ogg()
use_package_vorbis()
# This will find kNet and set the global include and library directories
use_package_knet()
message ("\n** Adding global include and link directories")
use_package(OGRE)
use_package(QT4)
if (NOT TUNDRA_NO_AUDIO)
use_package(OPENAL)
endif()
# OSX / Xcode needs Assimp as a global link directory, as it cannot find libassimp otherwise for eg. modules linking to OgreRenderingModule
if (APPLE)
use_package_assimp()
endif()
message("")
# If the custom optional modules configuration file does not yet
# exist, create it from the template file.
if (NOT EXISTS CMakeBuildConfig.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeBuildConfigTemplate.txt
${CMAKE_CURRENT_SOURCE_DIR}/CMakeBuildConfig.txt)
endif ()
# The following defines are required to compile.
add_definitions(
# These enable implicit conversions of common math types
# between different libraries and our internal math library.
#-DMATH_AUTOMATIC_SSE # TODO: Initial tests with SSE2 did not break the build
#-DMATH_SSE2 # but runtime exceptions occurred in float3x4.
-DMATH_QT_INTEROP
-DMATH_TUNDRA_INTEROP
-DMATH_ENABLE_STL_SUPPORT
# Both MathGeoLib and kNet has same macros for logging, so disable them from the beforementioned.
# TODO This can be removed when kNet's master is merged to stable (has not been done yet as of 2014-11-05),
# https://github.com/juj/kNet/commit/82c52da4f4508c71c4319851f76d23374e255eed
-DLOGGING_SUPPORT_DISABLED
)
if (ANDROID)
add_definitions(-DQT_STL)
endif()
# Read the set of optional modules from another file
# that is kept outside the source control.
# To configure the set of optional modules to add to the build,
# edit CMakeBuildConfig.txt and rerun cmake.
include(CMakeBuildConfig.txt)
# Collect translation files.
if (ENABLE_TRANSLATIONS)
file(GLOB TRANSLATIONS_FILES bin/data/translations/*.ts)
# Collect ui-files which are stored into data/
file(GLOB ui_src bin/data/ui/*.ui)
set(FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE} ${ui_src})
if (UPDATE_LANGUAGE_TRANSLATIONS) # TODO UPDATE_LANGUAGE_TRANSLATIONS is not specified currently anywhere.
message(STATUS "Update .ts files with new translation data.")
update_translation_files(TRANSLATIONS_FILES)
endif()
update_qm_files(TRANSLATIONS_FILES)
message (STATUS "Language translations generated")
endif()
PrintUsedEnvVariables ()
PrintUsedBuildConfig ()