-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCMakeLists.txt
252 lines (225 loc) · 8.58 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
cmake_minimum_required(VERSION 3.7)
project(caveproductions)
#-------------------------------------------------------------------------------
# options
#-------------------------------------------------------------------------------
option(NETWORKING "Enable networking" ON)
option(UNITTESTS "Builds with unittests" ON)
option(TOOLS "Builds with tools" ON)
option(VERBOSE "Print debug information" OFF)
option(COVERAGE "Compile with test coverage" OFF)
option(USE_CCACHE "Use ccache" ON)
# The build system will search for system libs, if it can't find them (e.g. via pkg-config)
# it will take those that are bundled under src/libs. If you don't want that for some reason,
# you can set this to ON and the libs dir will not be taken into account at all.
option(FORCE_USE_SYSTEM_LIBS "Use system libs" OFF)
option(CAVEEXPRESS "Build caveexpress" ON)
option(CAVEPACKER "Build cavepacker" ON)
option(SANITIZER "Build with sanitizer support if available" OFF)
option(ANDROID_INSTALL_PACKAGES "Install required android packages" ON)
#-------------------------------------------------------------------------------
# end options
#-------------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile Type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(RELEASE False)
else()
set(RELEASE True)
endif()
if (BUILD_SHARED_LIBS)
message(STATUS "Forcing building the internal libraries as static, even though BUILD_SHARED_LIBS=ON was requested.")
set(BUILD_SHARED_LIBS OFF)
endif()
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Root dir")
message(STATUS "Place binaries in ${ROOT_DIR}")
# First for the generic no-config case (e.g. with mingw)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROOT_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
# Second, for multi-config builds (e.g. msvc)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${ROOT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
endforeach()
set(DEFAULT_LUAC_EXECUTABLE luac)
set(CP_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CP_CMAKE_DIR})
set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_EXTENSIONS off)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (${CMAKE_EXTRA_GENERATOR} MATCHES "Eclipse CDT4")
message(STATUS "Generate eclipse projects")
set(CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES OFF)
set(CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT ON)
set(CMAKE_ECLIPSE_VERSION "4.3" CACHE STRING "Eclipse version")
set(CMAKE_CXX_COMPILER_ARG1 "-std=c++11" CACHE STRING "C++ version for Eclipse")
endif()
find_program(GDB_EXECUTABLE gdb)
find_program(LLDB_EXECUTABLE lldb)
if (GDB_EXECUTABLE)
set(DEBUGGER ${GDB_EXECUTABLE} CACHE STRING "Which debugger should be used")
elseif (LLDB_EXECUTABLE)
set(DEBUGGER ${LLDB_EXECUTABLE} CACHE STRING "Which debugger should be used")
else()
set(DEBUGGER "unknown" CACHE STRING "Which debugger should be used")
message(STATUS "No debugger (gdb or lldb) was found")
endif()
set_property(CACHE DEBUGGER PROPERTY STRINGS gdb lldb)
include(${CP_CMAKE_DIR}/macros.cmake)
if (COVERAGE)
if ((CP_GCC OR CP_CLANG) AND NOT RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
elseif (RELEASE)
message(WARNING "Skip coverage, you attempt to compile in release mode")
else()
message(WARNING "Skip coverage, you don't compile with gcc or clang")
endif()
endif()
cp_message("ROOT_DIR: ${ROOT_DIR}")
cp_message("CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
cp_message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
#-------------------------------------------------------------------------------
# variables
#-------------------------------------------------------------------------------
if (WIN32)
set(WINDOWS 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(LINUX 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(DARWIN 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LINUX 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
set(EMSCRIPTEN 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Haiku")
set(HAIKU 1)
else()
message(WARNING "Unknown host system: ${CMAKE_SYSTEM_NAME}. Default to linux")
set(LINUX 1)
endif()
include(${CP_CMAKE_DIR}/pack.cmake)
include(CPack)
# on mac it e.g. finds the gui launcher - this is not what we want - find a proper way to handle this
if (NOT ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
find_host_program(TEXTUREPACKER_BIN NAMES TexturePacker)
if (TEXTUREPACKER_BIN)
execute_process(COMMAND ${TEXTUREPACKER_BIN} --format CaveExpress ERROR_VARIABLE TEXTURE_PACKER_EXPORTER)
if (TEXTURE_PACKER_EXPORTER MATCHES "Unknown format")
message(STATUS "Found TexturePacker: ${TEXTUREPACKER_BIN}")
message(WARNING "but without the needed exporter. Find it in contrib/assets/png-packed/exporter. Check out the HOWTO.md in that directory.")
unset(TEXTUREPACKER_BIN)
else()
message(STATUS "Found TexturePacker: ${TEXTUREPACKER_BIN}")
endif()
else()
message(STATUS "Could not find TexturePacker")
endif()
endif()
if (NOT CMAKE_TOOLCHAIN_FILE)
if (WINDOWS)
include(${CP_CMAKE_DIR}/toolchains/windows-toolchain.cmake)
elseif (DARWIN)
include(${CP_CMAKE_DIR}/toolchains/darwin-toolchain.cmake)
elseif (HAIKU)
include(${CP_CMAKE_DIR}/toolchains/haiku-toolchain.cmake)
else()
include(${CP_CMAKE_DIR}/toolchains/linux-toolchain.cmake)
endif()
else()
if (MSVC)
# 4456: declaration of 'q' hides previous local declaration
# 4244: possible loss of data (e.g. float/double)
# 4201: nonstandard extension used
# 4245: signed/unsigned mismatch
# 4100: unreferenced formal parameter
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4245 /wd4201 /wd4100 /wd4456 /wd4267")
endif()
endif()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if (ANDROID)
include(${CP_CMAKE_DIR}/android.cmake)
elseif (IOS)
include(${CP_CMAKE_DIR}/ios.cmake)
elseif (DARWIN)
include(${CP_CMAKE_DIR}/darwin.cmake)
elseif (WINDOWS)
# include(${CP_CMAKE_DIR}/windows.cmake)
elseif (NACL)
include(${CP_CMAKE_DIR}/nacl.cmake)
elseif (EMSCRIPTEN)
include(${CP_CMAKE_DIR}/emscripten.cmake)
elseif (HAIKU)
# include(${CP_CMAKE_DIR}/haiku.cmake)
endif()
if (PKGDATADIR)
add_definitions(-DPKGDATADIR="${PKGDATADIR}")
message(STATUS "You specified a package data dir - the game will append the game name to this directory.")
message(STATUS "So you get e.g. ${PKGDATADIR}/caveexpress as final directory.")
endif()
if (NOT NETWORKING)
add_definitions(-DNONETWORK=1)
endif()
if (NOT CMAKE_BUILD_TYPE)
if (RELEASE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Compile Type" FORCE)
else()
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile Type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release)
endif()
find_host_program(CCACHE "ccache")
if (CCACHE)
if (USE_CCACHE)
message(STATUS "Using ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
endif()
else()
message(STATUS "ccache not found")
endif()
find_package(sdl2 REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_net REQUIRED)
find_package(sqlite3 REQUIRED)
find_package(lua REQUIRED)
find_package(box2d REQUIRED)
find_package(zlib REQUIRED)
configure_file(${ROOT_DIR}/src/config.h.in ${CMAKE_BINARY_DIR}/cp-config.h)
include_directories(${CMAKE_BINARY_DIR})
add_subdirectory(src/libs)
include_directories(src)
include_directories(src/modules)
include_directories(BEFORE src/modules/physics)
if (UNITTESTS)
include_directories(src/libs/gtest)
include_directories(src/libs/gtest/include)
endif()
# TODO move into lib cmakefiles
if (LUA_FOUND)
add_definitions(-DHAVE_LUA_H)
endif()
if (UNITTESTS)
enable_testing()
endif()
add_subdirectory(src/modules)
if (CAVEPACKER)
add_subdirectory(src/cavepacker)
endif()
if (CAVEEXPRESS)
add_subdirectory(src/caveexpress)
endif()
if (UNITTESTS)
add_subdirectory(src/tests)
endif()