Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ build
#ignore external deps
external_deps/*
!external_deps/build.sh
!external_deps/sdk-build.sh
!external_deps/cygtar.py
!external_deps/*.patch

Expand Down
162 changes: 81 additions & 81 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ if (Daemon_OUT)
endif()

include(Yokai/All)
include(DaemonNaclHost)

if (NOT YOKAI_TARGET_SYSTEM_NACL)
include(DaemonNaclArchitecture)

daemon_detect_nacl_arch("${YOKAI_TARGET_ARCH_NAME}")

# Add printable strings to the executable.
yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"")
endif()

################################################################################
# Configuration options
Expand Down Expand Up @@ -189,8 +197,9 @@ else()
set(FULL_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
endif()

# Dependencies version, this must match the number in external_deps/build.sh
set(DEPS_VERSION 11)
# Dependencies versions
set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh
set(SAIGOSDK_VERSION 20260925) # This must match the number in external_deps/sdk-build.sh

option(USE_EXTERNAL_DEPS "Download or reuse dependencies from EXTERNAL_DEPS_DIR (mandatory for building and running NaCl .nexe binaries)." ON)

Expand Down Expand Up @@ -265,6 +274,9 @@ endif()

option(USE_EXTERNAL_DEPS_LIBS "Build and link against libraries from the EXTERNAL_DEPS_DIR" ${DEFAULT_USE_EXTERNAL_DEPS_LIBS})

set(PNACL_SDK_PREFIX "${DEPS_DIR}/pnacl" CACHE PATH "PNaCl SDK path")
mark_as_advanced(PNACL_SDK_PREFIX)

if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL)
if (DEPS_DIR)
message(STATUS "Using external deps dir: ${DEPS_DIR}")
Expand All @@ -291,6 +303,7 @@ endif()
# meaning we have to detect useless engine compiler to set
# useless engine flags when only building vms.
include(DaemonFlags)
include(DaemonNaclFlags)

# FIXME: Once engine flags would be only set when building the engine
# this would be likely unused by vms as they are built by DaemonGame.
Expand Down Expand Up @@ -397,33 +410,33 @@ if (DEPS_DIR)
if (NOT EXISTS ${DEPS_DIR})
file(MAKE_DIRECTORY ${EXTERNAL_DEPS_DIR})
get_filename_component(BASENAME ${DEPS_DIR} NAME)
set(DEPS_FILENAME "${BASENAME}${DEPS_EXT}")

# Download test DEPS archive if DEPS archive isn't available yet.
# This makes possible to get the CI working before releasing the DEPS archive.
foreach(REMOTE_BASEURL https://dl.unvanquished.net/deps;https://dl.unvanquished.net/test/deps)
set(REMOTE "${REMOTE_BASEURL}/${DEPS_FILENAME}")
message(STATUS "Downloading dependencies from '${REMOTE}'")

file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}"
SHOW_PROGRESS
STATUS DOWNLOAD_RESULT
LOG DOWNLOAD_LOG
)

list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS)
list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING)

if (DOWNLOAD_STATUS EQUAL 0)
break()
else ()
message(WARNING "Error downloading '${REMOTE}':
Status code: ${DOWNLOAD_STATUS}
Error string: ${DOWNLOAD_STRING}
Download log: ${DOWNLOAD_LOG}"
)
endif()
endforeach()
set(DEPS_FILENAME "${BASENAME}${DEPS_EXT}")

# Download test DEPS archive if DEPS archive isn't available yet.
# This makes possible to get the CI working before releasing the DEPS archive.
foreach(REMOTE_BASEURL https://dl.unvanquished.net/deps;https://dl.unvanquished.net/test/deps)
set(REMOTE "${REMOTE_BASEURL}/${DEPS_FILENAME}")
message(STATUS "Downloading dependencies from '${REMOTE}'")

file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}"
SHOW_PROGRESS
STATUS DOWNLOAD_RESULT
LOG DOWNLOAD_LOG
)

list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS)
list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING)

if (DOWNLOAD_STATUS EQUAL 0)
break()
else ()
message(WARNING "Error downloading '${REMOTE}':
Status code: ${DOWNLOAD_STATUS}
Error string: ${DOWNLOAD_STRING}
Download log: ${DOWNLOAD_LOG}"
)
endif()
endforeach()

if (NOT DOWNLOAD_STATUS EQUAL 0)
message(FATAL_ERROR "Failed to download '${DEPS_FILENAME}'")
Expand All @@ -442,6 +455,11 @@ if (DEPS_DIR)
endif()
endif()

if (BUILD_GAME_NACL AND USE_NACL_SAIGO AND NOT SAIGOSDK_PREFIX)
include(DaemonDependenciesDownload)
download_saigosdk()
endif()

if (USE_EXTERNAL_DEPS_LIBS)
# Add to paths
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH})
Expand All @@ -462,7 +480,6 @@ endif()
# LIBS_BASE, LIBS_ENGINE_BASE LIBS_ENGINE, LIBS_BASECLIENT, LIBS_CLIENT

# Native client
include(DaemonNacl)
if (YOKAI_TARGET_SYSTEM_NACL)
add_library(srclibs-nacl-module EXCLUDE_FROM_ALL ${NACLLIST_MODULE})
set(LIBS_BASE ${LIBS_BASE} srclibs-nacl-module)
Expand All @@ -483,16 +500,6 @@ elseif (YOKAI_TARGET_SYSTEM_NACL)
find_library(NACL_EXCEPTION nacl_exception)
find_library(NACL_MINIDUMP minidump_generator)

# HACK: To be removed when Saigo is repackaged properly.
if (NOT NACL_MINIDUMP
# NACL_TARGET is specific to Saigo, PNaCl target is le32 and doesn't set NACL_TARGET.
AND "${NACL_TARGET}" STREQUAL "i686"
# x86_64-nacl/lib32 is specific to Google build, other builds may provide i686-nacl/lib instead.
AND EXISTS "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32")
set(NACL_EXCEPTION "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32/libnacl_exception.a")
set(NACL_MINIDUMP "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32/libminidump_generator.a")
endif()

set(LIBS_BASE ${LIBS_BASE} ${NACL_MINIDUMP} ${NACL_EXCEPTION})
else()
find_library(LIBM m)
Expand Down Expand Up @@ -969,56 +976,49 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER
add_custom_target(runtime_deps)
set_target_properties(runtime_deps PROPERTIES FOLDER "CMakePlumbing")

# The NaCl loader and IRT are required to load .nexe files
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX}
${FULL_OUTPUT_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX}
)

add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe
${FULL_OUTPUT_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe
)

# Linux uses a bootstrap program to reserve address space
if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY)
if (YOKAI_TARGET_ARCH_ARM64)
add_executable(nacl_helper_bootstrap-armhf tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp)
add_dependencies(runtime_deps nacl_helper_bootstrap-armhf)

foreach(arch_name IN LISTS DAEMON_NACL_ARCH_NAME_LIST)
# The NaCl loader and IRT are required to load .nexe files
if (YOKAI_TARGET_SYSTEM_WINDOWS AND YOKAI_TARGET_ARCH_I686 AND "${arch_name}" STREQUAL "amd64")
# Backport compatibility until the external_deps script properly suffixes names in the archives.
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
${FULL_OUTPUT_DIR}/lib-armhf
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX}
${FULL_OUTPUT_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX}
)

else()
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${DEPS_DIR}/lib-armhf
${FULL_OUTPUT_DIR}/lib-armhf
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX}
${FULL_OUTPUT_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX}
)
endif()

add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/nacl_helper_bootstrap
${FULL_OUTPUT_DIR}/nacl_helper_bootstrap
${DEPS_DIR}/irt_core-${arch_name}.nexe
${FULL_OUTPUT_DIR}/irt_core-${arch_name}.nexe
)
endif()
endforeach()

# Win32 requires nacl_loader_amd64.exe in order to run on Win64
if (YOKAI_TARGET_SYSTEM_WINDOWS AND YOKAI_TARGET_ARCH_I686)
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/nacl_loader-amd64${CMAKE_EXECUTABLE_SUFFIX}
${FULL_OUTPUT_DIR}/nacl_loader-amd64${CMAKE_EXECUTABLE_SUFFIX}
)
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/irt_core-amd64.nexe
${FULL_OUTPUT_DIR}/irt_core-amd64.nexe
)
if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY)
if (DAEMON_NACL_MULTIARCH)
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${DEPS_DIR}/libs-${DAEMON_NACL_ARCH_NAME}
${FULL_OUTPUT_DIR}/libs-linux-${DAEMON_NACL_ARCH_NAME}
)
endif()

# Linux uses a bootstrap program to reserve address space for 32-bit runtimes.
foreach(arch_name IN LISTS DAEMON_NACL_ARCH_NAME_LIST)
if ("${arch_name}" IN_LIST "i686;armhf")
add_custom_command(TARGET runtime_deps PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${DEPS_DIR}/nacl_helper_bootstrap
${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${arch_name}
)
endif()
endforeach()
endif()

# Mac requires some libraries from external_deps
Expand Down
74 changes: 74 additions & 0 deletions cmake/DaemonDependenciesDownload.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Daemon BSD Source Code
# Copyright (c) 2013-2026, Daemon Developers
Comment thread
slipher marked this conversation as resolved.
# 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 Daemon developers 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 DAEMON DEVELOPERS 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.

# TODO: Move other deps downloading code in here.

set(SAIGOSDK_BASENAME "saigosdk-${DEPS_SYSTEM}-${DEPS_ARCH}_${SAIGOSDK_VERSION}")

# Warning: changing SAIGOSDK_PREFIX/SAIGOSDK_VERSION after subprojects have been configured WILL
# change the compiler, but it is a bad idea since flag tests and such (not to mention the actual
# compiled artifacts) will be out of date.
set(SAIGOSDK_PREFIX "${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME}" CACHE PATH "PNaCl SDK path")
mark_as_advanced(SAIGOSDK_PREFIX)

# As an alternative to downloading, external_deps/sdk-build.sh can be used, to build the host-mode
# dependencies and install them in the expected path.
function(download_saigosdk)
if (NOT EXISTS "${SAIGOSDK_PREFIX}")
set(DEPS_FILENAME "${SAIGOSDK_BASENAME}.tar.xz")
set(REMOTE "https://github.com/DaemonEngine/saigo-nacl-sdk/releases/download/v${SAIGOSDK_VERSION}/${DEPS_FILENAME}")
message(STATUS "Downloading NaCl SDK from '${REMOTE}'")

file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}"
SHOW_PROGRESS
STATUS DOWNLOAD_RESULT
LOG DOWNLOAD_LOG
)

list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS)
list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING)

if (NOT DOWNLOAD_STATUS EQUAL 0)
message(FATAL_ERROR "Failed to download '${REMOTE}': This may be a network error, or your system may be an unsupported host platform.
Status code: ${DOWNLOAD_STATUS}
Error string: ${DOWNLOAD_STRING}
Download log: ${DOWNLOAD_LOG}"
)
endif()

message(STATUS "SDK download completed successfully")

# Extract the downloaded archive
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xJf ${OBJ_DIR}/${DEPS_FILENAME}
WORKING_DIRECTORY ${EXTERNAL_DEPS_DIR}
RESULT_VARIABLE EXTRACT_RESULT
)
if (NOT EXTRACT_RESULT EQUAL 0)
message(FATAL_ERROR "Could not extract ${DEPS_FILENAME}")
endif()
endif()
endfunction()
16 changes: 10 additions & 6 deletions cmake/DaemonFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,14 @@ if (USE_FLOAT_EXCEPTIONS)
add_definitions(-DDAEMON_USE_FLOAT_EXCEPTIONS)
endif()

if (NOT NACL AND BUILD_CLIENT)
if (NOT YOKAI_TARGET_SYSTEM_NACL AND BUILD_CLIENT)
option(USE_OPENMP "Use OpenMP to parallelize some tasks" OFF)
endif()

if (NOT YOKAI_TARGET_SYSTEM_NACL AND BUILD_CLIENT AND USE_OPENMP)
set(ENABLE_OPENMP ON)
endif()

if (YOKAI_CXX_COMPILER_MSVC_COMPATIBILITY)
if (YOKAI_CXX_COMPILER_MSVC)
# /MP doesn't do anything and prints a warning in the Clang clone.
Expand All @@ -275,7 +279,7 @@ if (YOKAI_CXX_COMPILER_MSVC_COMPATIBILITY)
set_cxx_flag("/std:c++23preview")
endif()

if (NOT NACL AND BUILD_CLIENT AND USE_OPENMP)
if (ENABLE_OPENMP)
# Flag checks doen't work with MSVC so we assume it's there.
set(OPENMP_COMPILE_FLAG "/openmp")
endif()
Expand Down Expand Up @@ -385,7 +389,7 @@ else()
endif()
endif()

if (NOT NACL AND BUILD_CLIENT AND USE_OPENMP)
if (ENABLE_OPENMP)
check_CXX_compiler_flag("-fopenmp" FLAG_FOPENMP)

if (FLAG_FOPENMP)
Expand All @@ -396,7 +400,7 @@ else()
endif()
endif()

if (YOKAI_TARGET_SYSTEM_NACL AND USE_NACL_SAIGO AND DAEMON_NACL_ARCH_ARMHF)
if (YOKAI_TARGET_SYSTEM_NACL AND YOKAI_CXX_COMPILER_SAIGO AND YOKAI_TARGET_ARCH_ARMHF)
# Saigo produces broken arm builds when optimizing them.
# See: https://github.com/Unvanquished/Unvanquished/issues/3297
# When setting this clang-specific option, we don't have to care
Expand Down Expand Up @@ -445,7 +449,7 @@ else()
try_flag(WARNINGS "-Werror")
endif()

if (YOKAI_TARGET_SYSTEM_NACL AND NOT USE_NACL_SAIGO)
if (YOKAI_TARGET_SYSTEM_NACL AND YOKAI_CXX_COMPILER_PNACL)
# PNaCl only supports libc++ as standard library.
set_c_cxx_flag("-stdlib=libc++")
set_c_cxx_flag("--pnacl-allow-exceptions")
Expand Down Expand Up @@ -508,7 +512,7 @@ else()
# Don't set _FORTIFY_SOURCE in debug builds.
endif()

if (NOT NACL)
if (NOT YOKAI_TARGET_SYSTEM_NACL)
# Saigo reports weird errors when building some cgame and sgame arm nexe with PIC:
# > error: Cannot represent a difference across sections
# > error: expected relocatable expression
Expand Down
Loading
Loading