@@ -44,9 +44,9 @@ include(Yokai/All)
4444
4545# Do not report unused native compiler if native vms are not built.
4646# If only NACL vms are built, this will be reported in chainloaded build.
47- if (BUILD_GAME_NATIVE_DLL OR BUILD_GAME_NATIVE_EXE OR NACL)
48- include (DaemonNacl )
47+ if (BUILD_GAME_NATIVE_DLL OR BUILD_GAME_NATIVE_EXE OR GAME_BUILD_SUBINVOCATION)
4948 include (DaemonFlags )
49+ include (DaemonNaclFlags )
5050endif ()
5151
5252# Source lists for src/shared
@@ -68,7 +68,11 @@ set(SHAREDLIST_sgame
6868# Function to setup all the Sgame/Cgame libraries
6969include (CMakeParseArguments )
7070
71- if (NOT FORK EQUAL 2)
71+ list (APPEND NACL_ALL_TARGETS "amd64" "i686" "armhf" )
72+
73+ if (NOT GAME_BUILD_SUBINVOCATION)
74+ option (USE_NACL_SAIGO "Use the Saigo toolchain to build NaCl executables" OFF )
75+
7276 if (USE_NACL_SAIGO)
7377 set (HAS_NACL_SDK ON )
7478 elseif (CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME
@@ -83,7 +87,6 @@ if (NOT FORK EQUAL 2)
8387 # can be loaded by daemon with vm.[sc]game.type 0 or 1
8488 option (BUILD_GAME_NACL "Build the NaCl \" pexe\" and \" nexe\" gamelogic modules for enabled architecture targets, required to host mods." OFF )
8589
86- set (NACL_ALL_TARGETS "amd64;i686;armhf" )
8790 set (BUILD_GAME_NACL_TARGETS "all" CACHE STRING "Enabled NaCl \" nexe\" architecture targets, values: ${NACL_ALL_TARGETS} ;all;native;none" )
8891 mark_as_advanced (BUILD_GAME_NACL_TARGETS )
8992
@@ -147,7 +150,7 @@ function(buildGameModule module_slug)
147150 if (module_slug STREQUAL "nacl" )
148151 set_target_properties (${module_target} PROPERTIES
149152 OUTPUT_NAME "${GAMEMODULE_NAME} "
150- SUFFIX "${PLATFORM_EXE_SUFFIX } " )
153+ SUFFIX "${NACL_EXECUTABLE_SUFFIX } " )
151154
152155 target_link_libraries (${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE} )
153156 else ()
@@ -163,13 +166,13 @@ function(gameSubProject)
163166 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR } /${NACL_VMS_PROJECT}
164167 CMAKE_GENERATOR ${VM_GENERATOR}
165168 CMAKE_ARGS
166- -DFORK=2
167- -DDAEMON_DIR=${Daemon_SOURCE_DIR }
168- -DDEPS_DIR=${DEPS_DIR}
169+ "-DDAEMON_DIR=${Daemon_SOURCE_DIR } "
170+ "-DDEPS_DIR=${DEPS_DIR} "
169171 -DBUILD_CLIENT=OFF
170172 -DBUILD_TTY_CLIENT=OFF
171173 -DBUILD_SERVER=OFF
172- -DBUILD_DUMMY_GAMELOGIC=${BUILD_DUMMY_GAMELOGIC}
174+ "-DBUILD_DUMMY_GAMELOGIC=${BUILD_DUMMY_GAMELOGIC} "
175+ -DGAME_BUILD_SUBINVOCATION=ON
173176 ${ARGV}
174177 ${INHERITED_OPTION_ARGS}
175178 INSTALL_COMMAND ""
@@ -199,8 +202,9 @@ function(GAMEMODULE)
199202 buildGameModule ("native-exe" )
200203 endif ()
201204
202- if (NOT FORK) # create the nacl-vms target only the first time that GAMEMODULE is called
203- set (FORK 1 PARENT_SCOPE )
205+ if (NOT NACL_VMS_TARGET_CREATED AND NOT GAME_BUILD_SUBINVOCATION)
206+ # Create the nacl-vms target only the first time that GAMEMODULE is called.
207+ set (NACL_VMS_TARGET_CREATED ON PARENT_SCOPE )
204208
205209 if (CMAKE_GENERATOR MATCHES "Visual Studio" )
206210 set (VM_GENERATOR "NMake Makefiles" )
@@ -215,33 +219,27 @@ function(GAMEMODULE)
215219 "-D${inherited_option} =${${inherited_option} }" )
216220 endforeach (inherited_option )
217221
218- if (BUILD_GAME_NACL)
222+ if (BUILD_GAME_NACL AND NOT YOKAI_TARGET_SYSTEM_NACL )
219223 if (USE_NACL_SAIGO)
220224 add_custom_target (nacl-vms ALL )
221225 unset (NACL_VMS_PROJECTS)
222226
223- foreach (NACL_TARGET IN LISTS NACL_TARGETS)
224- if (NACL_TARGET STREQUAL "i686" )
225- set (SAIGO_ARCH "i686" )
226- elseif (NACL_TARGET STREQUAL "amd64" )
227- set (SAIGO_ARCH "x86_64" )
228- elseif (NACL_TARGET STREQUAL "armhf" )
229- set (SAIGO_ARCH "arm" )
230- else ()
227+ foreach (nacl_target IN LISTS NACL_TARGETS)
228+ if (NOT nacl_target IN_LIST NACL_ALL_TARGETS)
231229 message (FATAL_ERROR "Unknown NaCl architecture ${NACL_TARGET} " )
232230 endif ()
233231
234- set (NACL_VMS_PROJECT nacl-vms-${NACL_TARGET } )
232+ set (NACL_VMS_PROJECT nacl-vms-${nacl_target } )
235233 list (APPEND NACL_VMS_PROJECTS ${NACL_VMS_PROJECT} )
236234 add_dependencies (nacl-vms ${NACL_VMS_PROJECT} )
237235
236+ # TODO: Remove USE_NACL_SAIGO once the game uses YOKAI_TARGET_SYSTEM_NACL.
238237 gameSubProject (
239- -DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-saigo.cmake
238+ "-DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR } /cmake/cross-toolchain-saigo-${nacl_target} .cmake"
239+ "-DPREFIX_SAIGO=${DEPS_DIR} /saigo_newlib"
240240 -DBUILD_GAME_NACL=ON
241241 -DBUILD_GAME_NATIVE_DLL=OFF
242242 -DBUILD_GAME_NATIVE_EXE=OFF
243- -DSAIGO_ARCH=${SAIGO_ARCH}
244- -DNACL_TARGET=${NACL_TARGET}
245243 -DUSE_NACL_SAIGO=ON
246244 )
247245 endforeach ()
@@ -253,19 +251,20 @@ function(GAMEMODULE)
253251 string (REPLACE ";" "," NACL_TARGETS_STRING "${NACL_TARGETS} " )
254252
255253 gameSubProject (
256- -DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-pnacl.cmake
254+ "-DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR } /cmake/cross-toolchain-pnacl.cmake"
255+ "-DPREFIX_PNACL=${DEPS_DIR} /pnacl"
257256 -DBUILD_GAME_NACL=ON
258257 -DBUILD_GAME_NATIVE_DLL=OFF
259258 -DBUILD_GAME_NATIVE_EXE=OFF
260- -DNACL_TARGETS_STRING=${NACL_TARGETS_STRING}
259+ " -DNACL_TARGETS_STRING=${NACL_TARGETS_STRING} "
261260 )
262261 endif ()
263262 endif ()
264263
265264 set (NACL_VMS_PROJECTS ${NACL_VMS_PROJECTS} PARENT_SCOPE )
266- elseif (FORK EQUAL 2) # we are in the CMake sub-invocation for NaCl
265+ elseif (GAME_BUILD_SUBINVOCATION)
267266 if (BUILD_GAME_NACL)
268- if (USE_NACL_SAIGO )
267+ if (YOKAI_CXX_COMPILER_SAIGO )
269268 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
270269 else ()
271270 # Put the .nexe and .pexe files in the same directory as the engine.
@@ -274,16 +273,28 @@ function(GAMEMODULE)
274273
275274 buildGameModule ("nacl" )
276275
277- if (USE_NACL_SAIGO)
276+ if (YOKAI_CXX_COMPILER_SAIGO)
277+ include (DaemonSaigoFinalize )
278+
278279 # Finalize NaCl executables for supported architectures.
279- saigo_finalize (${CMAKE_RUNTIME_OUTPUT_DIRECTORY } /.. ${GAMEMODULE_NAME} ${NACL_TARGET} )
280+ saigo_finalize (
281+ "${CMAKE_RUNTIME_OUTPUT_DIRECTORY } "
282+ "${GAMEMODULE_NAME} "
283+ "${YOKAI_TARGET_ARCH_NAME} "
284+ )
280285 else ()
286+ include (DaemonPNaClFinalize )
287+
281288 # Revert a workaround for a bug where CMake ExternalProject lists-as-args are cut on first “;”
282289 string (REPLACE "," ";" NACL_TARGETS "${NACL_TARGETS_STRING} " )
283290
284291 # Generate NaCl executables for supported architectures.
285- foreach (NACL_TARGET ${NACL_TARGETS} )
286- pnacl_finalize (${CMAKE_RUNTIME_OUTPUT_DIRECTORY } ${GAMEMODULE_NAME} ${NACL_TARGET} )
292+ foreach (nacl_target ${NACL_TARGETS} )
293+ pnacl_finalize (
294+ "${CMAKE_RUNTIME_OUTPUT_DIRECTORY } "
295+ "${GAMEMODULE_NAME} "
296+ "${nacl_target} "
297+ )
287298 endforeach ()
288299 endif ()
289300 endif ()
0 commit comments