-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
237 lines (186 loc) · 6.3 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
project (bitfighter)
cmake_minimum_required (VERSION 2.8.8)
# CMake 3.0 policy that says you need to do something like this (NEW):
# set_target_properties(master_lib master PROPERTIES COMPILE_DEFINITIONS_DEBUG "TNL_DEBUG")
#
# instead of this (OLD):
# set_target_properties(master_lib master PROPERTIES COMPILE_DEFINITIONS $<$<CONFIG:Debug>:TNL_DEBUG>)
#
# Set to OLD behavior until minimum cmake version >= 2.8.10
if(POLICY CMP0043)
cmake_policy(SET CMP0043 OLD)
endif()
#
# CMake options
#
option(USE_SDL2 "Use SDL2" YES)
option(USE_GLES "Force usage of OpenGL ES for the bitfighter client. Requires SDL2." NO)
option(USE_GLES2 "Force usage of OpenGL ES 2 for the bitfighter client. Requires SDL2." NO)
option(USE_LUAJIT_IN_TREE "Force usage of in-tree LuaJIT." NO)
option(LUAJIT_DISABLE_JIT "Disable JIT compiler in LuaJIT." NO)
option(MASTER_MINIMAL "Build master server without MySQL (only SQLite)." NO)
option(ALURE_DISABLE_MP3 "Disable dynamic loading of libmpg123. Disables mp3 completely." NO)
#
# CMake system management
#
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
# Use appropriate platform alterations
if(WIN32)
include(${CMAKE_SOURCE_DIR}/cmake/Platform/Win32.cmake)
elseif(APPLE)
include(${CMAKE_SOURCE_DIR}/cmake/Platform/Apple.cmake)
elseif(UNIX)
include(${CMAKE_SOURCE_DIR}/cmake/Platform/Linux.cmake)
endif()
# No creating project files in-source. Bad, evil things happen
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource)
if (_insource)
message(SEND_ERROR "No building in-source. You must run CMake from the \"build\" directory.")
message(FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first.")
endif()
# Default to Release for a build type
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
#
# Library searching and dependencies
#
# SDL2 is default and should be found on all platforms except possibly Linux
if(USE_SDL2)
find_package(SDL2)
if(SDL2_FOUND)
set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIR})
set(SDL_LIBRARY ${SDL2_LIBRARY})
else()
message(STATUS "SDL2 not found. Attempting to find SDL 1.2...")
endif()
endif()
if(NOT USE_SDL2 OR NOT SDL2_FOUND)
# SDL_LIBRARY and SDL_INCLUDE_DIR are set by the FindSDL module
find_package(SDL)
endif()
# Searches for OpenGL and enables GLES if GL isnt found in the system
message(STATUS "Determining system GL provider")
if(NOT USE_GLES AND NOT USE_GLES2)
message(STATUS "Atempting to use standard OpenGL")
find_package(OpenGL)
set(USE_STANDARD_GL 1)
set(GL_LIBRARY ${OPENGL_LIBRARY})
set(GL_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
endif()
if(NOT USE_GLES2 AND (USE_GLES OR NOT USE_STANDARD_GL) )
message(STATUS "Atempting to use OpenGL ES")
add_definitions(-DBF_USE_GLES)
add_definitions(-DBF_NO_CONSOLE)
find_package(OpenGLES)
set(GL_LIBRARY ${OPENGLES_LIBRARY})
set(GL_INCLUDE_DIR ${OPENGLES_INCLUDE_DIR})
endif()
if(USE_GLES2)
message(STATUS "Atempting to use OpenGL ES 2")
add_definitions(-DBF_USE_GLES2)
add_definitions(-DBF_NO_CONSOLE)
find_package(OpenGLES2)
set(GL_LIBRARY ${OPENGLES2_LIBRARY})
set(GL_INCLUDE_DIR ${OPENGLES2_INCLUDE_DIR})
endif()
# Other needed libraries that don't have in-tree fallback options
find_package(Threads REQUIRED)
find_package(PhysFS REQUIRED)
find_package(PNG)
find_package(MySQL)
find_package(OGG)
find_package(Speex)
find_package(Vorbis)
find_package(ModPlug)
find_package(OpenAL)
# Now look for libraries that have an in-tree fallback option
# Many of these may have special overrides to properly adapt to the in-tree versions
# Special function to look for a system lib, but fall back to the in-tree version
function(FIND_WITH_FALLBACK packageName capsName dirName)
if(NOT FORCE_IN_TREE_${capsName})
find_package(${packageName})
endif()
if( NOT ${capsName}_FOUND )
set(${capsName}_LIBRARIES ${dirName})
set(${capsName}_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/${dirName}")
endif()
# export the results
set(${capsName}_FOUND "${${capsName}_FOUND}" PARENT_SCOPE)
set(${capsName}_INCLUDE_DIR "${${capsName}_INCLUDE_DIR}" PARENT_SCOPE)
set(${capsName}_LIBRARY "${${capsName}_LIBRARY}" PARENT_SCOPE)
set(${capsName}_LIBRARIES "${${capsName}_LIBRARIES}" PARENT_SCOPE)
endfunction()
# ALURE
find_with_fallback(ALURE ALURE alure)
if(NOT ALURE_FOUND)
if(NOT OPENAL_FOUND OR NOT VORBIS_FOUND OR NOT MODPLUG_FOUND)
message(WARNING "Audio system components are missing. Bitfighter will be compiled without audio")
add_definitions(-DBF_NO_AUDIO)
set(OPENAL_INCLUDE_DIR "")
else()
message(STATUS "Using in-tree ALURE")
add_definitions(-DALURE_STATIC_LIBRARY)
add_subdirectory(alure)
endif()
endif()
# sqlite3
find_with_fallback(Sqlite SQLITE3 sqlite)
if(NOT SQLITE3_FOUND)
message(STATUS "Using in-tree sqlite3")
add_subdirectory(sqlite)
endif()
# libtomcrypt
find_with_fallback(TomCrypt TOMCRYPT tomcrypt)
if(NOT TOMCRYPT_FOUND)
message(STATUS "Using in-tree libtomcrypt")
set(TOMCRYPT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/tomcrypt/src/headers")
add_subdirectory(tomcrypt)
endif()
# Boost
find_with_fallback(Boost Boost boost)
if(NOT Boost_FOUND)
message(STATUS "Using in-tree Boost c++ headers")
set(BOOST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/boost")
endif()
# Clipper
find_with_fallback(Clipper CLIPPER clipper)
if(NOT CLIPPER_FOUND)
message(STATUS "Using in-tree Clipper")
add_subdirectory(clipper)
endif()
# poly2tri
find_with_fallback(Poly2tri POLY2TRI poly2tri)
if(NOT POLY2TRI_FOUND)
message(STATUS "Using in-tree poly2tri")
add_subdirectory(poly2tri)
endif()
# LuaJIT / Lua
find_with_fallback(LuaJit LUAJIT lua)
if(LUAJIT_FOUND AND NOT USE_LUAJIT_IN_TREE)
set(LUA_LIB ${LUAJIT_LIBRARIES})
set(LUA_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR})
else()
message(STATUS "Using in-tree LuaJIT")
# Use internal LuaJIT
set(LUA_LIB luajit)
set(LUA_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/lua/luajit/src")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/lua/${LUA_LIB}")
add_subdirectory("${CMAKE_SOURCE_DIR}/lua/${LUA_LIB}")
endif()
# mysql++ is for compiling master
if(EXISTS "${CMAKE_SOURCE_DIR}/mysql++")
add_subdirectory(mysql++)
endif()
# gtest is for compiling the bitfighter_test suite
if(EXISTS "${CMAKE_SOURCE_DIR}/gtest")
add_subdirectory(gtest)
endif()
# Other internal-only sub-projects
add_subdirectory(tnl)
add_subdirectory(tnlping)
add_subdirectory(master)
add_subdirectory(updater) # Windows-only
# Our main sources!
add_subdirectory(zap)