Skip to content

Commit 23066c8

Browse files
committed
cmake: deeply rewrite the NaCl toolchains
1 parent ff7ea91 commit 23066c8

13 files changed

Lines changed: 527 additions & 350 deletions

CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ endif()
289289
# meaning we have to detect useless engine compiler to set
290290
# useless engine flags when only building vms.
291291
include(DaemonFlags)
292+
include(DaemonNaclFlags)
292293

293294
# FIXME: Once engine flags would be only set when building the engine
294295
# this would be likely unused by vms as they are built by DaemonGame.
@@ -460,7 +461,6 @@ endif()
460461
# LIBS_BASE, LIBS_ENGINE_BASE LIBS_ENGINE, LIBS_BASECLIENT, LIBS_CLIENT
461462

462463
# Native client
463-
include(DaemonNacl)
464464
if (YOKAI_TARGET_SYSTEM_NACL)
465465
add_library(srclibs-nacl-module EXCLUDE_FROM_ALL ${NACLLIST_MODULE})
466466
set(LIBS_BASE ${LIBS_BASE} srclibs-nacl-module)
@@ -481,16 +481,6 @@ elseif (YOKAI_TARGET_SYSTEM_NACL)
481481
find_library(NACL_EXCEPTION nacl_exception)
482482
find_library(NACL_MINIDUMP minidump_generator)
483483

484-
# HACK: To be removed when Saigo is repackaged properly.
485-
if (NOT NACL_MINIDUMP
486-
# NACL_TARGET is specific to Saigo, PNaCl target is le32 and doesn't set NACL_TARGET.
487-
AND "${NACL_TARGET}" STREQUAL "i686"
488-
# x86_64-nacl/lib32 is specific to Google build, other builds may provide i686-nacl/lib instead.
489-
AND EXISTS "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32")
490-
set(NACL_EXCEPTION "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32/libnacl_exception.a")
491-
set(NACL_MINIDUMP "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32/libminidump_generator.a")
492-
endif()
493-
494484
set(LIBS_BASE ${LIBS_BASE} ${NACL_MINIDUMP} ${NACL_EXCEPTION})
495485
else()
496486
find_library(LIBM m)

cmake/DaemonGame.cmake

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
5050
endif()
5151

5252
# Source lists for src/shared
@@ -68,7 +68,11 @@ set(SHAREDLIST_sgame
6868
# Function to setup all the Sgame/Cgame libraries
6969
include(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()

cmake/DaemonNacl.cmake

Lines changed: 0 additions & 81 deletions
This file was deleted.

cmake/DaemonNaclFlags.cmake

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Daemon BSD Source Code
2+
# Copyright (c) 2013-2026, Daemon Developers
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the Daemon developers nor the
13+
# names of its contributors may be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
20+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
# Native Client build configuration.
28+
29+
if (YOKAI_TARGET_SYSTEM_NACL)
30+
# Build nexe binary.
31+
32+
if (YOKAI_CXX_COMPILER_SAIGO)
33+
if (YOKAI_TARGET_ARCH_AMD64)
34+
add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64)
35+
elseif (YOKAI_TARGET_ARCH_I686)
36+
add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=32)
37+
elseif (YOKAI_TARGET_ARCH_ARMHF)
38+
add_definitions(-DNACL_BUILD_ARCH=arm)
39+
else()
40+
message(FATAL_ERROR "Unsupported architecture ${NACL_TARGET}")
41+
endif()
42+
else()
43+
# Those defines looks to be meaningless to produce arch-independent pexe
44+
# with PNaCl but they must be set to anything supported by native builds.
45+
# This requirement looks to be a PNaCl bug.
46+
add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64)
47+
endif()
48+
else()
49+
# Build native dll or native exe.
50+
51+
if (YOKAI_TARGET_SYSTEM_MACOS)
52+
add_definitions(-DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=1)
53+
elseif (YOKAI_TARGET_SYSTEM_LINUX)
54+
add_definitions(-DNACL_WINDOWS=0 -DNACL_LINUX=1 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0)
55+
elseif (YOKAI_TARGET_SYSTEM_FREEBSD)
56+
add_definitions(-DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=1 -DNACL_OSX=0)
57+
elseif (YOKAI_TARGET_SYSTEM_WINDOWS)
58+
add_definitions(-DNACL_WINDOWS=1 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0)
59+
endif()
60+
61+
if (YOKAI_TARGET_ARCH_AMD64)
62+
add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64)
63+
elseif (YOKAI_TARGET_ARCH_I686)
64+
add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=32)
65+
elseif (YOKAI_TARGET_ARCH_ARMHF)
66+
add_definitions(-DNACL_BUILD_ARCH=arm)
67+
else()
68+
# NaCl does not support this architecture natively, but these defines must
69+
# be set because nacl_config.h is included unconditionally. Use dummy x86
70+
# values as PNaCl does for architecture-independent builds.
71+
add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64)
72+
endif()
73+
endif()
74+
75+
include_directories(${LIB_DIR}/nacl)

0 commit comments

Comments
 (0)