From ee31cc1722519e4355eae935f683693df104f262 Mon Sep 17 00:00:00 2001 From: PAS Date: Tue, 18 Nov 2025 12:47:40 -0500 Subject: [PATCH 1/2] Fix macOS/CMake build Moved C++ includes out of extern "C" blocks Added missing algorithm includes Disabled threads on macOS, since macOS doesn't support C11 threads.h Added extern "C" blocks to src/sdl/macosx/mac_resources.h and src/p_tick.h Added #ifdef HAVE_THREADS guard to src/sdl/i_threads.c Removed mac_alert code while I'm at it, since it's obsolete in SDL2 --- src/CMakeLists.txt | 7 ++-- src/command.h | 6 ++-- src/dedicated/i_system.c | 4 --- src/doomdef.h | 14 ++++---- src/p_local.h | 8 ++--- src/p_tick.h | 9 +++++ src/r_bsp.cpp | 2 ++ src/r_fps.h | 8 ++--- src/r_main.h | 8 ++--- src/r_segs.cpp | 2 ++ src/sdl/CMakeLists.txt | 2 -- src/sdl/i_system.cpp | 4 --- 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 | 11 +++++- 16 files changed, 54 insertions(+), 126 deletions(-) delete mode 100644 src/sdl/macosx/mac_alert.c delete mode 100644 src/sdl/macosx/mac_alert.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 69d9834a6..341bcc62e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,8 +130,11 @@ if(${SRB2_CONFIG_LIBBACKTRACE}) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_LIBBACKTRACE) endif() -set(SRB2_HAVE_THREADS ON) -target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS) +# FIXME macOS does not support C11 threads.h +if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set(SRB2_HAVE_THREADS ON) + target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS) +endif() if(${SRB2_CONFIG_HAVE_ZLIB}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) 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/dedicated/i_system.c b/src/dedicated/i_system.c index fe8889405..d852462f1 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -162,10 +162,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 cf15d3fa8..5d58ce73d 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -47,6 +47,13 @@ #define ASMCALL #endif +#define _USE_MATH_DEFINES // fixes M_PI errors in r_plane.c for Visual Studio +#ifdef __cplusplus +#include +#else +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -58,13 +65,6 @@ extern "C" { #include #include -#define _USE_MATH_DEFINES // fixes M_PI errors in r_plane.c for Visual Studio -#ifdef __cplusplus -#include -#else -#include -#endif - #include #include #include diff --git a/src/p_local.h b/src/p_local.h index 6977cc4b1..2e72fc11b 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..428aff161 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -16,6 +16,10 @@ #include "doomdef.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUG__ #pragma interface #endif @@ -43,4 +47,9 @@ mobj_t *P_SetTarget2(mobj_t **mo, mobj_t *target #else #define P_SetTarget P_SetTarget2 #endif + +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 5a0a21d76..39aa884a6 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -14,6 +14,8 @@ #include "doomdef.h" #include "g_game.h" +#include + #include "r_fps.h" #include "r_local.h" #include "r_state.h" diff --git a/src/r_fps.h b/src/r_fps.h index 7ad5e9f16..8058e1b6b 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 850101e64..6b864e61c 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 61eac0c35..3dac241a7 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 d40d39ad7..ff647f46a 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -23,8 +23,6 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns) set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") target_sources(SRB2SDL2 PRIVATE - 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 0dc751c85..a7bce6d73 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -201,10 +201,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) 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..f281a116d 100644 --- a/src/sdl/macosx/mac_resources.h +++ b/src/sdl/macosx/mac_resources.h @@ -1,5 +1,14 @@ #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 +} // extern "C" +#endif + +#endif -- 2.54.0 From 04e649d7169804f28a12ec5ddc5344ef5be4802b 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/2] 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 341bcc62e..bb43d1419 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -230,7 +230,10 @@ 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" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64|em64t|EM64T)") + target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields) + endif() + target_compile_options(SRB2SDL2 PRIVATE -Wno-trigraphs) endif() # TODO: fix prng and P_CreateBlockmap overflow at some point -- 2.54.0