Clang fixes

This commit is contained in:
NepDisk 2025-05-01 15:16:53 -04:00
parent ecfc29ac8a
commit dd176a9efd
12 changed files with 103 additions and 35 deletions

View file

@ -1,8 +1,17 @@
add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32)
if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}")
# On MinGW with internal libraries, link the standard library statically
target_link_options(SRB2SDL2 PRIVATE "-static" "-Wl,--disable-dynamicbase")
if(("${CMAKE_COMPILER_IS_GNUCC}" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase")
if("${SRB2_CONFIG_STATIC_STDLIB}")
# On MinGW with internal libraries, link the standard library statically
target_link_options(SRB2SDL2 PRIVATE -Wl,--add-stdcall-alias -static-libgcc -static-libstdc++ -static -lpthread)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(SRB2SDL2 PRIVATE Threads::Threads)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_link_options(SRB2SDL2 PRIVATE "-Wl,--large-address-aware")
endif()
endif()
target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17)
@ -197,7 +206,7 @@ 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")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields)
endif()
@ -296,6 +305,7 @@ target_compile_options(SRB2SDL2 PRIVATE
-Wno-trigraphs
-Wno-error=non-literal-null-conversion
-Wno-error=constant-conversion
-Wno-unused-but-set-variable
-Wno-error=unused-but-set-variable
>
@ -309,6 +319,9 @@ target_compile_options(SRB2SDL2 PRIVATE
# C++, GNU, Clang and Apple Clang
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<OR:$<C_COMPILER_ID:GNU>,$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>>:
-Wall
-Wno-unused-function
-Wno-unused-but-set-variable
-Wno-unused-private-field
>
# C++, MSVC
@ -358,19 +371,19 @@ if(SRB2_CONFIG_PROFILEMODE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
target_link_options(SRB2SDL2 PRIVATE -pg)
endif()
# strip debug symbols into separate file when using gcc.
# strip debug symbols into separate file when using gcc or clang.
# to be consistent with Makefile, don't generate for OS X.
if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin))
if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin))
if((${CMAKE_BUILD_TYPE} MATCHES Debug) OR (${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo))
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
set(OBJCOPY_ONLY_KEEP_DEBUG "--only-keep-debug")
endif()
message(STATUS "Will make separate debug symbols in *.debug")
add_custom_command(TARGET SRB2SDL2 POST_BUILD
COMMAND ${OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $<TARGET_FILE:SRB2SDL2> $<TARGET_FILE:SRB2SDL2>.debug
COMMAND ${CMAKE_OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $<TARGET_FILE:SRB2SDL2> $<TARGET_FILE:SRB2SDL2>.debug
# mold linker: .gnu_debuglink is present by default, so --add-gnu-debuglink would fail
COMMAND ${OBJCOPY} --strip-debug --remove-section=.gnu_debuglink $<TARGET_FILE:SRB2SDL2>
COMMAND ${OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:SRB2SDL2>.debug $<TARGET_FILE:SRB2SDL2>
COMMAND ${CMAKE_OBJCOPY} --strip-debug --remove-section=.gnu_debuglink $<TARGET_FILE:SRB2SDL2>
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:SRB2SDL2>.debug $<TARGET_FILE:SRB2SDL2>
)
endif()
endif()
@ -378,14 +391,22 @@ endif()
# copy DLLs to bin/ directory if building internal shared on windows
if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}" AND "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}")
set(ADDITIONAL_DLLS "")
if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU)
if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# also copy implicitly linked system libraries
get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH)
list(APPEND ADDITIONAL_DLLS
"libgcc_s_dw2-1.dll"
"libstdc++-6.dll"
"libwinpthread-1.dll"
)
if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU)
list(APPEND ADDITIONAL_DLLS
"libgcc_s_dw2-1.dll"
"libstdc++-6.dll"
"libwinpthread-1.dll"
)
else()
list(APPEND ADDITIONAL_DLLS
"libunwind.dll"
"libc++.dll"
"libwinpthread-1.dll"
)
endif()
list(TRANSFORM ADDITIONAL_DLLS PREPEND "${MINGW_BIN_PATH}/")
endif()
add_custom_command(TARGET SRB2SDL2 POST_BUILD

View file

@ -1621,7 +1621,7 @@ bool CallFunc_CountPushables(ACSVM::Thread *thread, const ACSVM::Word *argV, ACS
--------------------------------------------------*/
/*bool CallFunc_HaveUnlockable(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC)
{
UINT8 id = 0;
UINT32 id = 0;
bool unlocked = false;
(void)argC;

View file

@ -238,11 +238,12 @@ bool operator!=(const srb2::StaticVec<T, L1>& lhs, const srb2::StaticVec<T, L2>&
template <typename T, size_t Limit>
struct std::hash<srb2::StaticVec<T, Limit>>
{
uint64_t operator()(const srb2::StaticVec<T, Limit>& input) const
size_t operator()(const srb2::StaticVec<T, Limit>& input) const
{
constexpr const uint64_t prime {0x00000100000001B3};
std::size_t ret {0xcbf29ce484222325};
constexpr size_t prime = sizeof(size_t) == 8 ? 0x00000100000001B3 : 0x01000193;
constexpr size_t basis = sizeof(size_t) == 8 ? 0xcbf29ce484222325 : 0x811c9dc5;
size_t ret = basis;
for (auto itr = input.begin(); itr != input.end(); itr++)
{
ret = (ret * prime) ^ std::hash<T>(*itr);

View file

@ -400,6 +400,9 @@ extern struct debugFlagNames_s const debug_flag_names[];
// Misc stuff for later...
// =======================
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180)
// Modifier key variables, accessible anywhere

View file

@ -262,7 +262,7 @@ enum {false = 0, true = 1};
#endif
#endif
#if defined (__MINGW32__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) // MinGW, >= GCC 3.4
#if defined (__MINGW32__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && !defined(__clang__) // MinGW, >= GCC 3.4, not Clang
#define ATTRPACK __attribute__((packed, gcc_struct))
#else
#define ATTRPACK __attribute__((packed))
@ -400,8 +400,12 @@ typedef UINT64 precise_t;
// that struct and it's fine...
// Cast function pointer to (void*)
#define FUNCPTRCAST(p) ((union{void(*f)(void);void*v;})\
{(void(*)(void))p}).v
typedef union {
void (*f)(void);
void *v;
} func_ptr_cast_union;
#define FUNCPTRCAST(p) (((func_ptr_cast_union){(void(*)(void))(p)}).v)
#include "typedef.h"

View file

@ -997,14 +997,14 @@ static inline boolean M_PNGLib(void)
if (!pnglib)
return false;
#ifdef HAVE_SDL
aPNG_set_acTL = hwSym("png_set_acTL", pnglib);
aPNG_write_frame_head = hwSym("png_write_frame_head", pnglib);
aPNG_write_frame_tail = hwSym("png_write_frame_tail", pnglib);
aPNG_set_acTL = (P_png_set_acTL) hwSym("png_set_acTL", pnglib);
aPNG_write_frame_head = (P_png_write_frame_head) hwSym("png_write_frame_head", pnglib);
aPNG_write_frame_tail = (P_png_write_frame_tail) hwSym("png_write_frame_tail", pnglib);
#endif
#ifdef _WIN32
aPNG_set_acTL = GetProcAddress("png_set_acTL", pnglib);
aPNG_write_frame_head = GetProcAddress("png_write_frame_head", pnglib);
aPNG_write_frame_tail = GetProcAddress("png_write_frame_tail", pnglib);
aPNG_set_acTL = (P_png_set_acTL) GetProcAddress("png_set_acTL", pnglib);
aPNG_write_frame_head = (P_png_write_frame_head) GetProcAddress("png_write_frame_head", pnglib);
aPNG_write_frame_tail = (P_png_write_frame_tail) GetProcAddress("png_write_frame_tail", pnglib);
#endif
return (aPNG_set_acTL && aPNG_write_frame_head && aPNG_write_frame_tail);
#endif
@ -1017,7 +1017,7 @@ static void M_PNGFrame(png_structp png_ptr, png_infop png_info_ptr, png_bytep pn
png_uint_32 pitch = png_get_rowbytes(png_ptr, png_info_ptr);
PNG_CONST png_uint_32 width = vid.width / downscale;
PNG_CONST png_uint_32 height = vid.height / downscale;
png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep));
png_bytepp row_pointers = (png_bytepp) png_malloc(png_ptr, height * sizeof (png_bytep));
png_uint_32 x, y;
png_uint_16 framedelay = (png_uint_16)cv_apng_delay.value;
@ -1025,7 +1025,7 @@ static void M_PNGFrame(png_structp png_ptr, png_infop png_info_ptr, png_bytep pn
for (y = 0; y < height; y++)
{
row_pointers[y] = malloc(pitch * sizeof(png_byte));
row_pointers[y] = (png_bytep) malloc(pitch * sizeof(png_byte));
for (x = 0; x < width; x++)
row_pointers[y][x] = png_buf[x * downscale];
png_buf += pitch * (downscale * downscale);

View file

@ -4971,7 +4971,7 @@ sector_t *P_FindPlayerTrigger(player_t *player, line_t *sourceline)
return loopsector;
}
return false;
return NULL;
}
boolean P_IsPlayerValid(size_t playernum)

View file

@ -15,8 +15,12 @@ target_sources(SRB2SDL2 PRIVATE
if("${CMAKE_SYSTEM_NAME}" MATCHES Windows)
target_sources(SRB2SDL2 PRIVATE
../win32/win_dbg.c
../win32/Srb2win.rc)
../win32/win_dbg.c)
if("${CMAKE_C_COMPILER_ID}" MATCHES clang)
target_sources(SRB2SDL2 PRIVATE
../win32/Srb2win.rc)
endif()
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)

View file

@ -2048,7 +2048,7 @@ void I_Error(const char *error, ...)
W_Shutdown();
#if defined (PARANOIA) && defined (__CYGWIN__)
*(INT32 *)2 = 4; //Alam: Debug!
*(volatile INT32 *)0 = 4; //Alam: Debug!
#endif
exit(-1);

View file

@ -45,7 +45,7 @@ if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}")
"SDL2MIXER_MP3 ON"
"SDL2MIXER_MP3_DRMP3 ON"
"SDL2MIXER_MIDI ON"
"SDL2MIXER_OPUS ON"
"SDL2MIXER_OPUS OFF"
"SDL2MIXER_VORBIS STB"
"SDL2MIXER_WAVE ON"
)

View file

@ -0,0 +1,18 @@
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER clang -target x86_64-pc-windows-gnu)
set(CMAKE_CXX_COMPILER clang++ -target x86_64-pc-windows-gnu)
# Set that this is clang.
set(CMAKE_C_COMPILER_ID clang)
set(CMAKE_CXX_COMPILER_ID clang)
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View file

@ -0,0 +1,17 @@
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
# set the root path
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)