|
| 1 | +# Daemon BSD Source Code |
| 2 | +# Copyright (c) 2022-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 | +function(daemon_detect_nacl_arch) |
| 28 | + set(arch_name "${YOKAI_TARGET_ARCH_NAME}") |
| 29 | + set(nacl_arch "${arch_name}") |
| 30 | + |
| 31 | + if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY) |
| 32 | + set(armhf_usage "arm64;armel") |
| 33 | + if ("${arch_name}" IN_LIST armhf_usage) |
| 34 | + # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. |
| 35 | + # The nexe is system agnostic so there should be no difference with armel. |
| 36 | + set(nacl_arch "armhf") |
| 37 | + |
| 38 | + set(box64_usage ppc64el riscv64) |
| 39 | + if ("${arch_name}" IN_LIST box64_usage) |
| 40 | + option(YOKAI_NACL_BOX64_EMULATION "Use Box64 to emulate x86_64 NaCl loader on unsupported platforms" ON) |
| 41 | + if (YOKAI_NACL_BOX64_EMULATION) |
| 42 | + # Use Box64 to run x86_64 NaCl loader and amd64 nexe. |
| 43 | + # Box64 must be installed and available in PATH at runtime. |
| 44 | + set(nacl_arch "amd64") |
| 45 | + add_definitions(-DDAEMON_NACL_BOX64_EMULATION) |
| 46 | + endif() |
| 47 | + endif() |
| 48 | + endif() |
| 49 | + |
| 50 | + elseif (DAEMON_TARGET_SYSTEM_MACOS) |
| 51 | + if ("${arch_name}" STREQUAL "arm64") |
| 52 | + # You can get emulated NaCl going like this: |
| 53 | + # cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/ |
| 54 | + set(nacl_arch "amd64") |
| 55 | + endif() |
| 56 | + endif() |
| 57 | + |
| 58 | + string(TOUPPER "${nacl_arch_name}" nacl_arch_name_upper) |
| 59 | + |
| 60 | + # The DAEMON_NACL_ARCH_NAME variable contributes to the nexe file name. |
| 61 | + set(DAEMON_NACL_ARCH_NAME "${nacl_arch}" PARENT_SCOPE) |
| 62 | + set(DAEMON_NACL_ARCH_NAME_UPPER "${nacl_arch_upper}" PARENT_SCOPE) |
| 63 | + |
| 64 | + # NaCl runtime is only available on architectures that have a NaCl loader. |
| 65 | + set(nacl_runtime_arch amd64 i686 armhf) |
| 66 | + if ("${nacl_arch}" IN_LIST nacl_runtime_arch) |
| 67 | + add_definitions(-DDAEMON_NACL_RUNTIME_ENABLED) |
| 68 | + endif() |
| 69 | +endfunction() |
| 70 | + |
| 71 | +daemon_detect_nacl_arch() |
| 72 | + |
| 73 | +# Makes possible to do that in CMake code: |
| 74 | +# > if (DAEMON_NACL_ARCH_ARMHF) |
| 75 | +set("DAEMON_NACL_ARCH_${DAEMON_NACL_ARCH_NAME_UPPER}" ON) |
| 76 | + |
| 77 | +# Add printable strings to the executable. |
| 78 | +yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"") |
0 commit comments