From c9fc3b48203935c6d3f250141959b7f85d200792 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 18:23:21 +0100 Subject: [PATCH 1/8] fixup cmake for macos mostly based on the patch from https://github.com/Bijman/srb2bld with some changes from https://github.com/Indev450/SRB2Kart-Saturn/pull/216 but doesent completely replace the build system with what blan has compiles fine on nix, but needs testing on mac --- CMakeLists.txt | 6 +++- src/CMakeLists.txt | 43 +++++++++++++++-------- src/command.h | 6 ++-- src/d_netcmd.c | 3 ++ src/dedicated/i_system.c | 4 --- src/doomdef.h | 41 +++++++++++++++++----- src/m_emotes.h | 8 ++--- src/p_local.h | 8 ++--- src/p_tick.h | 8 +++++ src/r_fps.h | 8 ++--- src/r_main.h | 8 ++--- src/r_segs.cpp | 2 ++ src/sdl/CMakeLists.txt | 4 +-- src/sdl/i_system.cpp | 7 ++-- src/sdl/i_threads.c | 4 +++ src/sdl/macosx/mac_alert.c | 64 ---------------------------------- src/sdl/macosx/mac_alert.h | 27 -------------- src/sdl/macosx/mac_resources.h | 8 ++++- src/strcasestr.c | 4 +++ 19 files changed, 115 insertions(+), 148 deletions(-) delete mode 100644 src/sdl/macosx/mac_alert.c delete mode 100644 src/sdl/macosx/mac_alert.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d280190..c5e12d93d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 3.5) # Version change is fine. project(SRB2 VERSION 1.6 - LANGUAGES C) + LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) # optional but recommended: disables GNU extensions, forces pure ISO C++ if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 361386622..251195414 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,8 @@ # Core sources set(SRB2_CORE_SOURCES + core/memory.cpp + core/thread_pool.cpp am_map.c b_bot.c command.c @@ -18,17 +20,21 @@ set(SRB2_CORE_SOURCES f_wipe.c filesrch.c g_game.c + g_demo.c g_input.c hu_stuff.c i_tcp.c info.c + k_hud.c lzf.c m_aatree.c m_anigif.c m_argv.c m_bbox.c m_cheat.c + m_curl.c m_cond.c + m_emotes.cpp m_fixed.c m_menu.c m_textinput.c @@ -40,19 +46,25 @@ set(SRB2_CORE_SOURCES mserv.c http-mserv.c qs22j.c + r_skins.c s_sound.c screen.c sounds.c st_stuff.c - #string.c + #strcasestr.c tables.c v_video.c w_wad.c y_inter.c - z_zone.c + z_zone.cpp ) set(SRB2_CORE_HEADERS + core/memory.h + core/thread_pool.h + m_curl.h + m_emotes.h + k_hud.h am_map.h b_bot.h byteptr.h @@ -78,6 +90,7 @@ set(SRB2_CORE_HEADERS fastcmp.h filesrch.h g_game.h + g_demo.h g_input.h g_state.h hu_stuff.h @@ -109,6 +122,7 @@ set(SRB2_CORE_HEADERS md5.h mserv.h qs22j.h + r_skins.h s_sound.h screen.h sounds.h @@ -123,18 +137,18 @@ set(SRB2_CORE_HEADERS ) set(SRB2_CORE_RENDER_SOURCES - r_bsp.c + r_bsp.cpp r_data.c - r_draw.c - r_fps.c - r_main.c - r_patch.c - r_patchrotation.c - r_plane.c - r_segs.c + r_draw.cpp + r_fps.cpp + r_main.cpp + r_patch.cpp + r_patchrotation.cpp + r_plane.cpp + r_segs.cpp r_sky.c r_splats.c - r_things.c + r_things.cpp r_portal.c r_bsp.h @@ -162,7 +176,7 @@ set(SRB2_CORE_GAME_SOURCES p_inter.c p_lights.c p_map.c - p_maputl.c + p_maputl.cpp p_mobj.c p_polyobj.c p_saveg.c @@ -475,10 +489,10 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c @@ -493,7 +507,6 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gl.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h diff --git a/src/command.h b/src/command.h index 7074158e1..d3bf09127 100644 --- a/src/command.h +++ b/src/command.h @@ -13,13 +13,13 @@ #ifndef __COMMAND_H__ #define __COMMAND_H__ +#include +#include "doomdef.h" + #ifdef __cplusplus extern "C" { #endif -#include -#include "doomdef.h" - //=================================== // Command buffer & command execution //=================================== diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 781120be2..641a026fd 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -54,6 +54,9 @@ #include "fastcmp.h" #include "m_perfstats.h" +#include "r_data.h" +#include "r_skins.h" + #ifdef NETGAME_DEVMODE #define CV_RESTRICT CV_NETVAR #else diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 4d52ffa70..437439010 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -180,10 +180,6 @@ static char returnWadPath[256]; #include "../m_argv.h" -#ifdef MAC_ALERT -#include "macosx/mac_alert.h" -#endif - #include "../d_main.h" #if !defined(NOMUMBLE) && defined(HAVE_MUMBLE) diff --git a/src/doomdef.h b/src/doomdef.h index 492fa1185..23768d0f4 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -40,22 +40,45 @@ #define ASMCALL #endif -#ifdef __cplusplus -extern "C" { -#endif - #include "doomtype.h" +#ifdef __cplusplus /* Only when compiled as C++ */ + #include /* std::min, std::max, std::sort, … */ +#endif + +#ifdef __cplusplus +// Force libc++ to expose std::min/std::max even when is included first (Apple clang quirk) +#ifndef _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES +#define _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES +#endif +#ifndef _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + +// Optional: only try if it actually exists (newer Xcode) +#if __has_include() +#include +#endif + +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#else +#include #include #include #include +#include #include -#define _USE_MATH_DEFINES // fixes M_PI errors in r_plane.c for Visual Studio -#ifdef __cplusplus -#include -#else -#include +#include #endif #include diff --git a/src/m_emotes.h b/src/m_emotes.h index 594e219f8..d87dd438f 100644 --- a/src/m_emotes.h +++ b/src/m_emotes.h @@ -12,14 +12,14 @@ #ifndef __M_EMOTES__ #define __M_EMOTES__ -#ifdef __cplusplus -extern "C" { -#endif - #include "doomdef.h" #include "m_fixed.h" #include "command.h" +#ifdef __cplusplus +extern "C" { +#endif + extern consvar_t cv_emotes; #define MAXEMOTENAME 32 diff --git a/src/p_local.h b/src/p_local.h index 3c16b5c62..82e3fb673 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -14,10 +14,6 @@ #ifndef __P_LOCAL__ #define __P_LOCAL__ -#ifdef __cplusplus -extern "C" { -#endif - #include "command.h" #include "d_player.h" #include "d_think.h" @@ -28,6 +24,10 @@ extern "C" { #include "p_maputl.h" #include "doomstat.h" // MAXSPLITSCREENPLAYERS +#ifdef __cplusplus +extern "C" { +#endif + #define FLOATSPEED (FRACUNIT*4) //#define VIEWHEIGHTS "41" diff --git a/src/p_tick.h b/src/p_tick.h index a903be0fd..e0fcd899c 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -20,6 +20,10 @@ #pragma interface #endif +#ifdef __cplusplus +extern "C" { +#endif + extern tic_t leveltime; // Called by G_Ticker. Carries out all thinking of enemies and players. @@ -38,6 +42,10 @@ mobj_t *P_SetTarget2(mobj_t **mo, mobj_t *target #endif ); +#ifdef __cplusplus +} +#endif + #ifdef PARANOIA #define P_SetTarget(...) P_SetTarget2(__VA_ARGS__, __FILE__, __LINE__) #else diff --git a/src/r_fps.h b/src/r_fps.h index 89efc6cfb..bf3f48362 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -15,16 +15,16 @@ #ifndef __R_FPS_H__ #define __R_FPS_H__ -#ifdef __cplusplus -extern "C" { -#endif - #include "m_fixed.h" #include "p_local.h" #include "r_state.h" #include "r_things.h" #include "m_perfstats.h" +#ifdef __cplusplus +extern "C" { +#endif + extern consvar_t cv_fpscap, cv_fpscapbg; extern ps_metric_t ps_interp_frac; diff --git a/src/r_main.h b/src/r_main.h index d33d67606..e8b7393e3 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -14,14 +14,14 @@ #ifndef __R_MAIN__ #define __R_MAIN__ -#ifdef __cplusplus -extern "C" { -#endif - #include "d_player.h" #include "r_data.h" #include "m_perfstats.h" +#ifdef __cplusplus +extern "C" { +#endif + // // POV related. // diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 3fe8042ae..6751befc9 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -15,6 +15,8 @@ #include "r_local.h" #include "r_sky.h" +#include + #include "r_portal.h" #include "r_splats.h" #include "r_fps.h" // newview diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index e4b0d4f37..fe29c5d2f 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -32,7 +32,7 @@ set(SRB2_SDL2_SOURCES hwsym_sdl.c i_main.c i_net.c - i_system.c + i_system.cpp i_ttf.c i_video.c i_threads.c @@ -123,8 +123,6 @@ if(${SDL2_FOUND}) set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns) set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") set(SRB2_SDL2_MAC_SOURCES - macosx/mac_alert.c - macosx/mac_alert.h macosx/mac_resources.c macosx/mac_resources.h macosx/Srb2mac.icns diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index eeeb2373c..48dfa9fd2 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -30,6 +30,7 @@ #endif #include +#include #ifdef _WIN32 #define RPC_NO_WINDOWS_H @@ -201,10 +202,6 @@ static char returnWadPath[256]; #include "../s_sound.h" -#ifdef MAC_ALERT -#include "macosx/mac_alert.h" -#endif - #include "../d_main.h" #if !defined(NOMUMBLE) && defined(HAVE_MUMBLE) @@ -2466,7 +2463,7 @@ static const char *locateWad(void) return NULL; } -const char *I_LocateWad(void) +extern "C" const char *I_LocateWad(void) { const char *waddir = NULL; diff --git a/src/sdl/i_threads.c b/src/sdl/i_threads.c index 078f4e0f4..26d3bbefe 100644 --- a/src/sdl/i_threads.c +++ b/src/sdl/i_threads.c @@ -9,6 +9,8 @@ /// \file i_threads.c /// \brief Multithreading abstraction +#ifdef HAVE_THREADS + #include "../doomdef.h" #include "../i_threads.h" @@ -354,3 +356,5 @@ I_wake_all_cond ( if (SDL_CondBroadcast(cond) == -1) abort(); } + +#endif // HAVE_THREADS diff --git a/src/sdl/macosx/mac_alert.c b/src/sdl/macosx/mac_alert.c deleted file mode 100644 index 2a139041a..000000000 --- a/src/sdl/macosx/mac_alert.c +++ /dev/null @@ -1,64 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 1993-1996 by id Software, Inc. -// Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief Graphical Alerts for MacOSX -/// -/// Shows alerts, since we can't just print these to the screen when -/// launched graphically on a mac. - -#ifdef __APPLE_CC__ - -#include "mac_alert.h" -#include - -#define CFSTRINGIFY(x) CFStringCreateWithCString(NULL, x, kCFStringEncodingASCII) - -int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3) -{ - CFOptionFlags results; - - CFStringRef cf_title = CFSTRINGIFY(title); - CFStringRef cf_message = CFSTRINGIFY(message); - CFStringRef cf_button1 = NULL; - CFStringRef cf_button2 = NULL; - CFStringRef cf_button3 = NULL; - - if (button1 != NULL) - cf_button1 = CFSTRINGIFY(button1); - if (button2 != NULL) - cf_button2 = CFSTRINGIFY(button2); - if (button3 != NULL) - cf_button3 = CFSTRINGIFY(button3); - - CFOptionFlags alert_flags = kCFUserNotificationStopAlertLevel | kCFUserNotificationNoDefaultButtonFlag; - - CFUserNotificationDisplayAlert(0, alert_flags, NULL, NULL, NULL, cf_title, cf_message, - cf_button1, cf_button2, cf_button3, &results); - - if (cf_button1 != NULL) - CFRelease(cf_button1); - if (cf_button2 != NULL) - CFRelease(cf_button2); - if (cf_button3 != NULL) - CFRelease(cf_button3); - CFRelease(cf_message); - CFRelease(cf_title); - - return (int)results; -} - -#endif diff --git a/src/sdl/macosx/mac_alert.h b/src/sdl/macosx/mac_alert.h deleted file mode 100644 index 82a28d120..000000000 --- a/src/sdl/macosx/mac_alert.h +++ /dev/null @@ -1,27 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 1993-1996 by id Software, Inc. -// Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief Graphical Alerts for MacOSX -/// -/// Shows alerts, since we can't just print these to the screen when -/// launched graphically on a mac. - -#ifdef __APPLE_CC__ - -extern int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3); - -#endif diff --git a/src/sdl/macosx/mac_resources.h b/src/sdl/macosx/mac_resources.h index 727ac9f6b..d63232dac 100644 --- a/src/sdl/macosx/mac_resources.h +++ b/src/sdl/macosx/mac_resources.h @@ -1,5 +1,11 @@ #ifndef __MAC_RESOURCES_H__ #define __MAC_RESOURCES_H__ +#ifdef __cplusplus +extern "C" { +#endif void OSX_GetResourcesPath(char * buffer); -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/strcasestr.c b/src/strcasestr.c index 3eb6af60f..f05449778 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -23,6 +23,10 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include + static inline int trycmp (char **pp, char *cp, const char *q, size_t qn) -- 2.54.0 From f7bbde398237d395f0b1ff6895cf42a29e575521 Mon Sep 17 00:00:00 2001 From: cobalt2727 <60624944+cobalt2727@users.noreply.github.com> Date: Wed, 8 Feb 2023 14:46:09 -0500 Subject: [PATCH 2/8] fix ARM builds being completely broken If merged, this is the quickest approach to resolve https://github.com/STJr/SRB2/issues/513 ...alternatively, we could just remove the option altogether but I don't have the time right now to test whether it's needed or not To the best of my knowledge, this covers all possible amd64 `CMAKE_SYSTEM_PROCESSOR` values based on what I'm seeing at https://stackoverflow.com/questions/70475665/what-are-the-possible-values-of-cmake-system-processor --- src/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 251195414..cc49bc0b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -549,8 +549,11 @@ endif() # Compatibility flag with later versions of GCC # We should really fix our code to not need this -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64|em64t|EM64T)") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) + endif() + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-trigraphs) endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") -- 2.54.0 From cb2c65e9d93a30187166427b631446880a859c9e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 19:08:52 +0100 Subject: [PATCH 3/8] more cmake fixups - skip asset install for linux - pass fwrapv flag - fix asset hash stuff - pass rdynamic flag - add saturn specific stuff, saturnpak, saturnjoin, libbacktrace and fix screen fbo stuff --- CMakeLists.txt | 1 + assets/CMakeLists.txt | 5 +++ cmake/Modules/Findlibbacktrace.cmake | 33 +++++++++++++++++ src/CMakeLists.txt | 55 ++++++++++++++++++++++------ src/config.h.in | 41 ++------------------- src/d_main.c | 25 +++++++++++++ src/sdl/CMakeLists.txt | 5 +++ 7 files changed, 116 insertions(+), 49 deletions(-) create mode 100644 cmake/Modules/Findlibbacktrace.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c5e12d93d..7c55117ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,7 @@ endif() # OS macros if (UNIX) add_definitions(-DUNIXCOMMON) + add_link_options(-rdynamic) # Use -rdynamic so a backtrace log shows function names endif() if(CMAKE_COMPILER_IS_GNUCC) diff --git a/assets/CMakeLists.txt b/assets/CMakeLists.txt index 12be1c470..a34cf2dfc 100644 --- a/assets/CMakeLists.txt +++ b/assets/CMakeLists.txt @@ -1,5 +1,10 @@ ## Assets Target Configuration ## +if(${CMAKE_SYSTEM} MATCHES Linux) + # Asset installation isn't part of the Linux target + return() +endif() + # For prepending the current source path, later FUNCTION(PREPEND var prefix) SET(listVar "") diff --git a/cmake/Modules/Findlibbacktrace.cmake b/cmake/Modules/Findlibbacktrace.cmake new file mode 100644 index 000000000..81ebeb9dc --- /dev/null +++ b/cmake/Modules/Findlibbacktrace.cmake @@ -0,0 +1,33 @@ +include(LibFindMacros) + +libfind_pkg_check_modules(LIBBACKTRACE_PKGCONF LIBBACKTRACE) + +find_path(LIBBACKTRACE_INCLUDE_DIR + NAMES backtrace.h + PATHS + ${LIBBACKTRACE_PKGCONF_INCLUDE_DIRS} + "/usr/include" + "/usr/local/include" +) + +find_library(LIBBACKTRACE_LIBRARY + NAMES backtrace + PATHS + ${LIBBACKTRACE_PKGCONF_LIBRARY_DIRS} + "/usr/lib" + "/usr/local/lib" +) + +set(LIBBACKTRACE_PROCESS_INCLUDES LIBBACKTRACE_INCLUDE_DIR) +set(LIBBACKTRACE_PROCESS_LIBS LIBBACKTRACE_LIBRARY) +libfind_process(LIBBACKTRACE) + +if(LIBBACKTRACE_FOUND AND NOT TARGET libbacktrace) + add_library(libbacktrace UNKNOWN IMPORTED) + set_target_properties( + libbacktrace + PROPERTIES + IMPORTED_LOCATION "${LIBBACKTRACE_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBBACKTRACE_INCLUDE_DIR}" + ) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc49bc0b4..0d144ec4c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -240,11 +240,19 @@ set(SRB2_CONFIG_HWRENDER ON CACHE BOOL "Enable hardware rendering through OpenGL.") set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL "Use statically linked OpenGL. NOT RECOMMENDED.") -set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL - "Enable OpenGL FBO Downsampling support.") +set(SRB2_CONFIG_SCREENFBO ON CACHE BOOL + "Enable hardware renderer (OpenGL) FBO downsampling support") set(SRB2_CONFIG_DEDICATED OFF CACHE BOOL "Build a dedicated server.") +set(SRB2_CONFIG_SATURNPAK ON CACHE BOOL + "Enable Saturn specific special packet. Required for using the newer resynch system") +set(SRB2_CONFIG_SATURNJOIN ON CACHE BOOL + "Enable Saturn specific allowjoin toggle.") + +set(SRB2_CONFIG_LIBBACKTRACE ON CACHE BOOL + "Enable using libbacktrace for crashlogs") + if(${SRB2_CONFIG_DEDICATED}) set(SRB2_CONFIG_HAVE_GME NO) set(SRB2_CONFIG_HAVE_OPENMPT NO) @@ -483,6 +491,27 @@ if(${SRB2_CONFIG_HAVE_CURL}) endif() endif() +if(${SRB2_CONFIG_LIBBACKTRACE}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(LIBBACKTRACE_FOUND ON) + set(LIBBACKTRACE_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libbacktrace/include) + set(LIBBACKTRACE_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libbacktrace/lib/x86_64 -lbacktrace") + else() # 32-bit + message(WARNING "libbacktrace is unsupported on 32-bit builds.") + endif() + else() + find_package(libbacktrace) + endif() + if(${LIBBACKTRACE_FOUND}) + set(SRB2_HAVE_LIBBACKTRACE ON) + add_definitions(-DHAVE_LIBBACKTRACE) + add_compile_options(-g) + else() + message(WARNING "You have specified that libbacktrace is available but it was not found.") + endif() +endif() + if(${SRB2_CONFIG_HWRENDER}) add_definitions(-DHWRENDER) set(SRB2_HWRENDER_SOURCES @@ -536,29 +565,33 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) else() message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") endif() -endif() -if(${SRB2_CONFIG_HWRENDER}) - if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) + if(${SRB2_CONFIG_SCREENFBO}) add_definitions(-DUSE_FBO_OGL) endif() endif() +if(${SRB2_CONFIG_SATURNPAK}) + add_definitions(-DDOSATURNPAK) +endif() + +if(${SRB2_CONFIG_SATURNJOIN}) + add_definitions(-DDOSATURNJOIN) +endif() + # Targets # Compatibility flag with later versions of GCC # We should really fix our code to not need this if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64|em64t|EM64T)") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) + add_compile_options(-mno-ms-bitfields) endif() - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-trigraphs) + add_compile_options(-Wno-trigraphs) endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) -endif() +# TODO: fix prng and P_CreateBlockmap overflow at some point +add_compile_options(-fwrapv) add_definitions(-DCMAKECONFIG) diff --git a/src/config.h.in b/src/config.h.in index 5225c8b0b..4028ef2f0 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -11,21 +11,6 @@ #ifdef CMAKECONFIG -// Base SRB2 hashes -#define ASSET_HASH_SRB2_SRB "${SRB2_ASSET_srb2.srb_HASH}" -#ifdef USE_PATCH_DTA -#define ASSET_HASH_PATCH_DTA "${SRB2_ASSET_patch.dta_HASH}" -#endif - -// SRB2Kart-specific hashes -#define ASSET_HASH_GFX_KART "${SRB2_ASSET_gfx.kart_HASH}" -#define ASSET_HASH_TEXTURES_KART "${SRB2_ASSET_textures.kart_HASH}" -#define ASSET_HASH_CHARS_KART "${SRB2_ASSET_chars.kart_HASH}" -#define ASSET_HASH_MAPS_KART "${SRB2_ASSET_maps.kart_HASH}" -#ifdef USE_PATCH_KART -#define ASSET_HASH_PATCH_KART "00000000000000000000000000000000" -#endif - #define SRB2_COMP_REVISION "${SRB2_COMP_REVISION}" #define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}" @@ -33,30 +18,10 @@ #else -/* Manually defined asset hashes for non-CMake builds - * Last updated 2015 / 05 / 03 - SRB2 v2.1.15 - srb2.srb - * Last updated 2018 / 12 / 23 - SRB2 v2.1.22 - patch.dta - * Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets - * Last updated 2020 / 08 / 30 - Kart v1.3 - patch.kart - * Last updated 2022 / 08 / 16 - Kart v1.4 - Main assets - * Last updated 2022 / 08 / 19 - Kart v1.5 - gfx.kart - * Last updated 2022 / 11 / 01 - Kart v1.6 - gfx.kart, maps.kart - */ +#define SRB2_COMP_REVISION "" +#define SRB2_COMP_BRANCH "" -// Base SRB2 hashes -#define ASSET_HASH_SRB2_SRB "c1b9577687f8a795104aef4600720ea7" -#ifdef USE_PATCH_DTA -#define ASSET_HASH_PATCH_DTA "b04fd9624bfd94dc96dcf4f400f7deb4" -#endif - -// SRB2Kart-specific hashes -#define ASSET_HASH_GFX_KART "06f86ee16136eb8a7043b15001797034" -#define ASSET_HASH_TEXTURES_KART "abb53d56aba47c3a8cb0f764da1c8b80" -#define ASSET_HASH_CHARS_KART "e2c428347dde52858a3dacd29fc5b964" -#define ASSET_HASH_MAPS_KART "d051e55141ba736582228c456953cd98" -#ifdef USE_PATCH_KART -#define ASSET_HASH_PATCH_KART "00000000000000000000000000000000" -#endif +#define CMAKE_ASSETS_DIR "" #endif #endif diff --git a/src/d_main.c b/src/d_main.c index 81fd3d830..c5499fb57 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -80,6 +80,31 @@ #include "lua_script.h" +/* Manually defined asset hashes for non-CMake builds + * Last updated 2015 / 05 / 03 - SRB2 v2.1.15 - srb2.srb + * Last updated 2018 / 12 / 23 - SRB2 v2.1.22 - patch.dta + * Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets + * Last updated 2020 / 08 / 30 - Kart v1.3 - patch.kart + * Last updated 2022 / 08 / 16 - Kart v1.4 - Main assets + * Last updated 2022 / 08 / 19 - Kart v1.5 - gfx.kart + * Last updated 2022 / 11 / 01 - Kart v1.6 - gfx.kart, maps.kart + */ + +// Base SRB2 hashes +#define ASSET_HASH_SRB2_SRB "c1b9577687f8a795104aef4600720ea7" +#ifdef USE_PATCH_DTA +#define ASSET_HASH_PATCH_DTA "b04fd9624bfd94dc96dcf4f400f7deb4" +#endif + +// SRB2Kart-specific hashes +#define ASSET_HASH_GFX_KART "06f86ee16136eb8a7043b15001797034" +#define ASSET_HASH_TEXTURES_KART "abb53d56aba47c3a8cb0f764da1c8b80" +#define ASSET_HASH_CHARS_KART "e2c428347dde52858a3dacd29fc5b964" +#define ASSET_HASH_MAPS_KART "d051e55141ba736582228c456953cd98" +#ifdef USE_PATCH_KART +#define ASSET_HASH_PATCH_KART "00000000000000000000000000000000" +#endif + #ifdef CMAKECONFIG #include "config.h" #else diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index fe29c5d2f..546b92fcd 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -165,6 +165,11 @@ if(${SDL2_FOUND}) ${DISCORDRPC_LIBRARIES} ) + if(${SRB2_HAVE_LIBBACKTRACE}) + target_link_libraries(SRB2SDL2 PRIVATE ${LIBBACKTRACE_LIBRARIES}) + endif() + + if(${CMAKE_SYSTEM} MATCHES Linux) target_link_libraries(SRB2SDL2 PRIVATE m -- 2.54.0 From 4eeb0b4b20da403878df839d7e613f3415fa7c10 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 19:16:05 +0100 Subject: [PATCH 4/8] update readme to reflect this --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d538288bb..698f55a9c 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,14 @@ We also have a Flatpak available on [Flathub](https://flathub.org/en/apps/org.sr See [SRB2 Wiki/Source code compiling](http://wiki.srb2.org/wiki/Source_code_compiling). The compiling process for SRB2Kart is largely identical to SRB2. -Currently only the Makefile build system with GCC or Clang compiler is supported. -CMake is NOT supported at the moment, but will be availible again soon. - +For Windows only the Makefile build system with GCC or Clang compiler is supported. Visual C++ (MSVC) is unsupported. 64-bit Windows builds are supported and recommended over 32-bit builds, they will build automatically when using the MSYS2 MinGW 64-bit executable (requires the mingw-w64-x86_64-gcc package), no extra flags needed! The specific DLLs can be found under /libs/dll-binaries/(i686 for 32bit/x86_64 for 64-bit)/ or in the Release packages +MacOS and Linux can be build with CMake, but it is recommended to use the Makefile for Linux over CMake + Alternatively the [srb2bld](https://github.com/Bijman/srb2bld) script by Bijman can be used aswell! ## Disclaimer -- 2.54.0 From af952870c3f03ab272dc7e23516f401602f60606 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 19:22:40 +0100 Subject: [PATCH 5/8] fix fbo oopsie --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d144ec4c..07179882d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -565,10 +565,10 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) else() message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") endif() +endif() - if(${SRB2_CONFIG_SCREENFBO}) - add_definitions(-DUSE_FBO_OGL) - endif() +if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_SCREENFBO}) + add_definitions(-DUSE_FBO_OGL) endif() if(${SRB2_CONFIG_SATURNPAK}) -- 2.54.0 From 186421fe85cae9a945fa9d3dd899e0cf6ce8b0a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 19:23:36 +0100 Subject: [PATCH 6/8] cmake: link with peethread --- src/sdl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 546b92fcd..1c7d52344 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -174,6 +174,7 @@ if(${SDL2_FOUND}) target_link_libraries(SRB2SDL2 PRIVATE m rt + pthread ) endif() -- 2.54.0 From 8e91c16e97636409399e0e6c4782d857634fa1bf Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 19:34:38 +0100 Subject: [PATCH 7/8] cmake: enable gnu extensions we rely on some of them like the cleanup macro dont want those breaking or smth --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c55117ad..1acd092bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,9 @@ project(SRB2 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) # optional but recommended: disables GNU extensions, forces pure ISO C++ +#set(CMAKE_CXX_EXTENSIONS OFF) # optional but recommended: disables GNU extensions, forces pure ISO C++ +set(CMAKE_CXX_EXTENSIONS ON) +set(CMAKE_C_EXTENSIONS ON) if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") -- 2.54.0 From 276cf0a8cbfa143a31a874160db2cec993685c6f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 20:04:19 +0100 Subject: [PATCH 8/8] fix string.c include whoops, not sure why that was even done like that string.c will include strcasestr.c and SRB2_HAVE_STRLCPY will ensure eitherways we dont use the included strlcpy stuff --- src/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07179882d..f09b95633 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,7 +51,7 @@ set(SRB2_CORE_SOURCES screen.c sounds.c st_stuff.c - #strcasestr.c + string.c tables.c v_video.c w_wad.c @@ -207,10 +207,6 @@ set(SRB2_CORE_GAME_SOURCES k_stats.h ) -if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) -endif() - prepend_sources(SRB2_CORE_SOURCES) prepend_sources(SRB2_CORE_HEADERS) prepend_sources(SRB2_CORE_RENDER_SOURCES) -- 2.54.0