mirror of
https://github.com/diasurgical/DevilutionX.git
synced 2026-10-12 02:13:06 +00:00
Restore AmigaOS build and runtime support (#8660)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# Wrapper around CMake's bundled FindSDL module.
|
||||
#
|
||||
# The bundled module runs its own `find_package(Threads)` and appends
|
||||
# `CMAKE_THREAD_LIBS_INIT` to the SDL libraries. AmigaOS has no POSIX threads
|
||||
# library — SDL 1.2 uses native AmigaOS tasks — and `m68k-amigaos-g++` rejects
|
||||
# both `-pthread` and `-lpthreads`, so strip the thread flag back out.
|
||||
#
|
||||
# This has to live in a wrapper rather than at the call site because
|
||||
# dependencies built from source (notably SDL_audiolib) call `find_package(SDL)`
|
||||
# themselves and propagate the flag through their own link interface.
|
||||
|
||||
include("${CMAKE_ROOT}/Modules/FindSDL.cmake")
|
||||
|
||||
if(AMIGA)
|
||||
foreach(_devilutionx_sdl_var SDL_LIBRARY SDL_LIBRARIES SDL_LIBRARY_TEMP)
|
||||
if(${_devilutionx_sdl_var})
|
||||
list(FILTER ${_devilutionx_sdl_var} EXCLUDE REGEX "pthread")
|
||||
endif()
|
||||
endforeach()
|
||||
unset(_devilutionx_sdl_var)
|
||||
|
||||
# The module also bakes the thread flag into the imported target's link
|
||||
# interface, which is what dependencies actually consume.
|
||||
if(TARGET SDL::SDL)
|
||||
get_target_property(_devilutionx_sdl_iface SDL::SDL INTERFACE_LINK_LIBRARIES)
|
||||
if(_devilutionx_sdl_iface)
|
||||
list(FILTER _devilutionx_sdl_iface EXCLUDE REGEX "pthread")
|
||||
set_target_properties(SDL::SDL PROPERTIES INTERFACE_LINK_LIBRARIES "${_devilutionx_sdl_iface}")
|
||||
endif()
|
||||
unset(_devilutionx_sdl_iface)
|
||||
endif()
|
||||
endif()
|
||||
@@ -1,3 +1,5 @@
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/threads-stub")
|
||||
|
||||
set(BUILD_TESTING OFF)
|
||||
set(ASAN OFF)
|
||||
set(UBSAN OFF)
|
||||
@@ -8,9 +10,11 @@ set(SDL1_VIDEO_MODE_BPP 8)
|
||||
set(DEVILUTIONX_SYSTEM_BZIP2 OFF)
|
||||
set(DEVILUTIONX_SYSTEM_ZLIB OFF)
|
||||
|
||||
# Lower the optimization level to O2 because there are issues with O3.
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
|
||||
# Lower the optimization level to O1 because m68k-amigaos GCC miscompiles at
|
||||
# -O2 and above. See also the AMIGA branch in Source/CMakeLists.txt, which keeps
|
||||
# the rendering code from being bumped back up to -O2.
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O1")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O1")
|
||||
|
||||
# `fseeko` fails to link on Amiga.
|
||||
add_definitions(-Dfseeko=fseek)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# Stub out the Threads package.
|
||||
# Some platforms do not have a system threads library but SDL threads are supported.
|
||||
add_library(Threads::Threads INTERFACE IMPORTED GLOBAL)
|
||||
set(Threads_FOUND TRUE)
|
||||
if(NOT TARGET Threads::Threads)
|
||||
add_library(Threads::Threads INTERFACE IMPORTED GLOBAL)
|
||||
endif()
|
||||
|
||||
+5
-1
@@ -274,7 +274,11 @@ endif()
|
||||
#
|
||||
# PS4 toolchain crashes in `create-fself` when linking with these flags, so we exclude it:
|
||||
# https://github.com/PacBrew/ps4-openorbis/issues/8
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT PS4)
|
||||
# On m68k-amigaos, `--gc-sections` discards static constexpr data that is still
|
||||
# referenced (magic_enum's per-enum name tables are the visible casualty: the
|
||||
# string_views survive with correct lengths but point at collected storage, so
|
||||
# every enum name reads as garbage). Excluded here for the same reason as PS4.
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT PS4 AND NOT AMIGA)
|
||||
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:-ffunction-sections;-fdata-sections>")
|
||||
if(APPLE)
|
||||
add_link_options("$<$<NOT:$<CONFIG:Debug>>:LINKER:-dead_strip>")
|
||||
|
||||
@@ -174,7 +174,12 @@ set(_optimize_in_debug_srcs
|
||||
utils/cel_to_clx.cpp
|
||||
utils/cl2_to_clx.cpp
|
||||
utils/pcx_to_clx.cpp)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
# These COMPILE_OPTIONS are appended after the global flags, so on Amiga they
|
||||
# would otherwise override the -O1 set in CMake/platforms/amiga.cmake. m68k-amigaos
|
||||
# GCC miscompiles this rendering code at -O2.
|
||||
if(AMIGA)
|
||||
set_source_files_properties(${_optimize_in_debug_srcs} PROPERTIES COMPILE_OPTIONS "-O1;--param=max-vartrack-size=900000000")
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set_source_files_properties(${_optimize_in_debug_srcs} PROPERTIES COMPILE_OPTIONS "-O2;--param=max-vartrack-size=900000000")
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set_source_files_properties(${_optimize_in_debug_srcs} PROPERTIES COMPILE_OPTIONS "-O2")
|
||||
@@ -890,6 +895,8 @@ endif()
|
||||
if(AMIGA AND NOT WARPOS)
|
||||
# Works around a missing `__cmpdf2` in the hard-float libgcc multilib.
|
||||
list(APPEND libdevilutionx_SRCS platform/amiga/cmpdf2.c)
|
||||
# Works around a missing `__xpg_strerror_r` under GCC 15's libstdc++.
|
||||
list(APPEND libdevilutionx_SRCS platform/amiga/strerror_r.c)
|
||||
endif()
|
||||
|
||||
if(NOT DISABLE_DEMOMODE)
|
||||
|
||||
@@ -272,7 +272,10 @@ private:
|
||||
{
|
||||
seed(timeSeed());
|
||||
|
||||
#if !(defined(WINVER) && WINVER <= 0x0500 && (!defined(_WIN32_WINNT) || _WIN32_WINNT == 0))
|
||||
// AmigaOS has no entropy source backing std::random_device; constructing it
|
||||
// aborts, and this runs during static initialization, so the process dies
|
||||
// before main().
|
||||
#if !(defined(WINVER) && WINVER <= 0x0500 && (!defined(_WIN32_WINNT) || _WIN32_WINNT == 0)) && !defined(__amigaos__)
|
||||
static std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> dist;
|
||||
for (uint32_t &cell : s)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* GCC 15's libstdc++ (system_error.o) calls the XSI-compliant `strerror_r`,
|
||||
* but libnix only ships the GNU-flavoured one, so linking fails with an
|
||||
* undefined `__xpg_strerror_r`.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
int __xpg_strerror_r(int errnum, char *buf, size_t buflen);
|
||||
|
||||
int __xpg_strerror_r(int errnum, char *buf, size_t buflen)
|
||||
{
|
||||
if (buf == NULL || buflen == 0)
|
||||
return ERANGE;
|
||||
|
||||
const char *msg = strerror(errnum);
|
||||
if (msg == NULL)
|
||||
return EINVAL;
|
||||
|
||||
const size_t len = strlen(msg);
|
||||
if (len >= buflen) {
|
||||
memcpy(buf, msg, buflen - 1);
|
||||
buf[buflen - 1] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
memcpy(buf, msg, len + 1);
|
||||
return 0;
|
||||
}
|
||||
@@ -6,7 +6,11 @@
|
||||
|| (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000)
|
||||
#define DVL_NO_FILESYSTEM
|
||||
#endif
|
||||
#elif defined(NXDK) || (defined(_MSVC_LANG) && _MSVC_LANG < 201703L) \
|
||||
// AmigaOS paths are not POSIX paths: volumes and assigns such as `PROGDIR:` or
|
||||
// `Work:games` use a colon that std::filesystem treats as an ordinary character,
|
||||
// so it fails to create or resolve them. The non-filesystem fallbacks below
|
||||
// handle these paths correctly.
|
||||
#elif defined(NXDK) || defined(__amigaos__) || (defined(_MSVC_LANG) && _MSVC_LANG < 201703L) \
|
||||
|| (defined(WINVER) && WINVER <= 0x0500 && (!defined(_WIN32_WINNT) || _WIN32_WINNT == 0))
|
||||
#define DVL_NO_FILESYSTEM
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user