-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathDaemonGame.cmake
More file actions
278 lines (238 loc) · 9.86 KB
/
DaemonGame.cmake
File metadata and controls
278 lines (238 loc) · 9.86 KB
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
# Daemon BSD Source Code
# Copyright (c) 2013-2016, Daemon Developers
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include_directories(${MOUNT_DIR} ${LIB_DIR} ${LIB_DIR}/zlib)
## About the different ways to host/play games:
## Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.
## NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.
## Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.
## See VirtualMachine.h for code.
# can be loaded by daemon with vm.[sc]game.type 3
option(BUILD_GAME_NATIVE_DLL "Build the shared library files, mostly useful for debugging changes locally." ON)
# can be loaded by daemon with vm.[sc]game.type 2
option(BUILD_GAME_NATIVE_EXE "Build native executable, which might be used for better performances by server owners" OFF)
include(ExternalProject)
include(DaemonSourceGenerator)
include(DaemonPlatform)
# Do not report unused native compiler if native vms are not built.
# If only NACL vms are built, this will be reported in chainloaded build.
if (BUILD_GAME_NATIVE_DLL OR BUILD_GAME_NATIVE_EXE OR NACL)
include(DaemonNacl)
include(DaemonFlags)
endif()
# Source lists for src/shared
set(SHAREDLIST
${MOUNT_DIR}/shared/CommandBufferClient.cpp
${MOUNT_DIR}/shared/CommandBufferClient.h
${MOUNT_DIR}/shared/CommonProxies.cpp
${MOUNT_DIR}/shared/CommonProxies.h
${MOUNT_DIR}/shared/VMMain.cpp
${MOUNT_DIR}/shared/VMMain.h
)
set(SHAREDLIST_cgame
${MOUNT_DIR}/shared/client/cg_api.cpp ${MOUNT_DIR}/shared/client/cg_api.h
)
set(SHAREDLIST_sgame
${MOUNT_DIR}/shared/server/sg_api.cpp ${MOUNT_DIR}/shared/server/sg_api.h
)
# Function to setup all the Sgame/Cgame libraries
include(CMakeParseArguments)
# The NaCl SDK only runs on amd64 or i686.
if (NOT FORK EQUAL 2)
if (CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME
AND (ARCH STREQUAL "amd64" OR ARCH STREQUAL "i686"))
# can be loaded by daemon with vm.[sc]game.type 0 or 1
option(BUILD_GAME_NACL "Build the NaCl \"pexe\" and \"nexe\" gamelogic modules for enabled architecture targets, required to host mods." OFF)
set(NACL_ALL_TARGETS "amd64;i686;armhf")
set(BUILD_GAME_NACL_TARGETS "all" CACHE STRING "Enabled NaCl \"nexe\" architecture targets, values: ${NACL_ALL_TARGETS}, all, native, none.")
mark_as_advanced(BUILD_GAME_NACL_TARGETS)
if (BUILD_GAME_NACL_TARGETS STREQUAL "all")
set(NACL_TARGETS "${NACL_ALL_TARGETS}")
elseif (BUILD_GAME_NACL_TARGETS STREQUAL "native")
set(NACL_TARGETS "${ARCH}")
elseif (BUILD_GAME_NACL_TARGETS STREQUAL "none")
set(NACL_TARGETS "")
else()
set(NACL_TARGETS "${BUILD_GAME_NACL_TARGETS}")
endif()
foreach(NACL_TARGET ${NACL_TARGETS})
set(IS_NACL_VALID_TARGET OFF)
foreach(NACL_VALID_TARGET ${NACL_ALL_TARGETS})
if(NACL_TARGET STREQUAL NACL_VALID_TARGET)
set(IS_NACL_VALID_TARGET ON)
endif()
endforeach()
if (NOT IS_NACL_VALID_TARGET)
message(FATAL_ERROR "Invalid NaCl target ${NACL_TARGET}, must be one of ${NACL_ALL_TARGETS}")
endif()
endforeach()
else()
set(BUILD_GAME_NACL OFF)
set(NACL_TARGETS "")
endif()
endif()
daemon_write_buildinfo("Game")
function(buildGameModule module_slug)
set(module_target "${GAMEMODULE_NAME}-${module_slug}")
set(module_target_args ${PCH_FILE} ${GAMEMODULE_FILES} ${SHAREDLIST_${GAMEMODULE_NAME}} ${SHAREDLIST} ${BUILDINFOLIST} ${COMMONLIST})
if (module_slug STREQUAL "native-dll")
add_library("${module_target}" MODULE ${module_target_args})
set_target_properties(${module_target} PROPERTIES PREFIX "")
set(GAMEMODULE_DEFINITIONS "${GAMEMODULE_DEFINITIONS};BUILD_VM_IN_PROCESS")
else()
if (module_slug STREQUAL "native-exe")
set(GAMEMODULE_DEFINITIONS "${GAMEMODULE_DEFINITIONS};BUILD_VM_NATIVE_EXE")
endif()
add_executable("${module_target}" ${module_target_args})
endif()
set_target_properties(${module_target} PROPERTIES
COMPILE_DEFINITIONS "VM_NAME=${GAMEMODULE_NAME};${GAMEMODULE_DEFINITIONS};BUILD_VM"
COMPILE_OPTIONS "${GAMEMODULE_FLAGS}"
FOLDER ${GAMEMODULE_NAME}
)
if (module_slug STREQUAL "nacl")
set_target_properties(${module_target} PROPERTIES
OUTPUT_NAME "${GAMEMODULE_NAME}"
SUFFIX "${PLATFORM_EXE_SUFFIX}")
target_link_libraries(${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE})
else()
target_link_libraries(${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE} ${CPP23SupportLibrary})
endif()
ADD_PRECOMPILED_HEADER(${module_target})
endfunction()
function(gameSubProject)
ExternalProject_Add(${NACL_VMS_PROJECT}
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NACL_VMS_PROJECT}
CMAKE_GENERATOR ${VM_GENERATOR}
CMAKE_ARGS
-DFORK=2
-DDAEMON_DIR=${Daemon_SOURCE_DIR}
-DDEPS_DIR=${DEPS_DIR}
-DBUILD_CLIENT=OFF
-DBUILD_TTY_CLIENT=OFF
-DBUILD_SERVER=OFF
-DBUILD_DUMMY_GAMELOGIC=${BUILD_DUMMY_GAMELOGIC}
${ARGV}
${INHERITED_OPTION_ARGS}
INSTALL_COMMAND ""
)
# Force the rescan and rebuild of the subproject.
ExternalProject_Add_Step(${NACL_VMS_PROJECT} forcebuild
COMMAND ${CMAKE_COMMAND} -E remove
${CMAKE_CURRENT_BINARY_DIR}/${NACL_VMS_PROJECT}-prefix/src/${NACL_VMS_PROJECT}-stamp/${NACL_VMS_PROJECT}-configure
COMMENT "Forcing build step for '${NACL_VMS_PROJECT}'"
DEPENDEES build
ALWAYS 1
)
endfunction()
function(GAMEMODULE)
# ParseArguments setup
set(oneValueArgs NAME)
set(multiValueArgs DEFINITIONS FLAGS FILES LIBS)
cmake_parse_arguments(GAMEMODULE "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (BUILD_GAME_NATIVE_DLL)
buildGameModule("native-dll")
endif()
if (BUILD_GAME_NATIVE_EXE)
buildGameModule("native-exe")
endif()
if (NOT FORK) # create the nacl-vms target only the first time that GAMEMODULE is called
set(FORK 1 PARENT_SCOPE)
if (CMAKE_GENERATOR MATCHES "Visual Studio")
set(VM_GENERATOR "NMake Makefiles")
else()
set(VM_GENERATOR ${CMAKE_GENERATOR})
endif()
set(INHERITED_OPTION_ARGS)
foreach(inherited_option ${NACL_VM_INHERITED_OPTIONS})
set(INHERITED_OPTION_ARGS ${INHERITED_OPTION_ARGS}
"-D${inherited_option}=${${inherited_option}}")
endforeach(inherited_option)
if (BUILD_GAME_NACL)
if (USE_NACL_SAIGO)
add_custom_target(nacl-vms ALL)
unset(NACL_VMS_PROJECTS)
foreach(NACL_TARGET ${NACL_TARGETS})
if (NACL_TARGET STREQUAL "i686")
set(SAIGO_ARCH "i686")
elseif (NACL_TARGET STREQUAL "amd64")
set(SAIGO_ARCH "x86_64")
elseif (NACL_TARGET STREQUAL "armhf")
set(SAIGO_ARCH "arm")
else()
message(FATAL_ERROR "Unknown NaCl architecture ${NACL_TARGET}")
endif()
set(NACL_VMS_PROJECT nacl-vms-${NACL_TARGET})
list(APPEND NACL_VMS_PROJECTS ${NACL_VMS_PROJECT})
add_dependencies(nacl-vms ${NACL_VMS_PROJECT})
gameSubProject(
-DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-saigo.cmake
-DBUILD_GAME_NACL=ON
-DBUILD_GAME_NATIVE_DLL=OFF
-DBUILD_GAME_NATIVE_EXE=OFF
-DUSE_NACL_SAIGO=ON
-DSAIGO_ARCH=${SAIGO_ARCH}
-DNACL_TARGET=${NACL_TARGET}
)
endforeach()
else()
set(NACL_VMS_PROJECT nacl-vms)
set(NACL_VMS_PROJECTS ${NACL_VMS_PROJECT})
# Workaround a bug where CMake ExternalProject lists-as-args are cut on first “;”
string(REPLACE ";" "," NACL_TARGETS_STRING "${NACL_TARGETS}")
gameSubProject(
-DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-pnacl.cmake
-DBUILD_GAME_NACL=ON
-DBUILD_GAME_NATIVE_DLL=OFF
-DBUILD_GAME_NATIVE_EXE=OFF
-DNACL_TARGETS_STRING=${NACL_TARGETS_STRING}
)
endif()
endif()
set(NACL_VMS_PROJECTS ${NACL_VMS_PROJECTS} PARENT_SCOPE)
elseif (FORK EQUAL 2) # we are in the CMake sub-invocation for NaCl
if (BUILD_GAME_NACL)
if (USE_NACL_SAIGO)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else()
# Put the .nexe and .pexe files in the same directory as the engine.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/..)
endif()
buildGameModule("nacl")
if (USE_NACL_SAIGO)
# Finalize NaCl executables for supported architectures.
saigo_finalize(${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/.. ${GAMEMODULE_NAME} ${NACL_TARGET})
else()
# Revert a workaround for a bug where CMake ExternalProject lists-as-args are cut on first “;”
string(REPLACE "," ";" NACL_TARGETS "${NACL_TARGETS_STRING}")
# Generate NaCl executables for supported architectures.
foreach(NACL_TARGET ${NACL_TARGETS})
pnacl_finalize(${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${GAMEMODULE_NAME} ${NACL_TARGET})
endforeach()
endif()
endif()
endif()
endfunction()