diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f61513b31..32ea71d1b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -201,7 +201,7 @@ add_custom_target(_SRB2_reconf ALL ) add_dependencies(SRB2SDL2 _SRB2_reconf) -if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") +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 @@ -609,16 +609,16 @@ endif() add_subdirectory(hud) add_subdirectory(modp_b64) -# 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 RelWithDebInfo OR SRB2_CONFIG_ALWAYS_MAKE_DEBUGLINK) message(STATUS "Will make separate debug symbols in *.debug") add_custom_command(TARGET SRB2SDL2 POST_BUILD - COMMAND ${OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $ $.debug + COMMAND ${CMAKE_OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $ $.debug # mold linker: .gnu_debuglink is present by default, so --add-gnu-debuglink would fail - COMMAND ${OBJCOPY} --strip-debug --remove-section=.gnu_debuglink $ - COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ + COMMAND ${CMAKE_OBJCOPY} --strip-debug --remove-section=.gnu_debuglink $ + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ ) endif() endif() @@ -626,14 +626,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 diff --git a/src/core/static_vec.hpp b/src/core/static_vec.hpp index c27b9b397..f31f17939 100644 --- a/src/core/static_vec.hpp +++ b/src/core/static_vec.hpp @@ -238,11 +238,12 @@ bool operator!=(const srb2::StaticVec& lhs, const srb2::StaticVec& template struct std::hash> { - uint64_t operator()(const srb2::StaticVec& input) const + size_t operator()(const srb2::StaticVec& 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(*itr); diff --git a/src/doomdef.h b/src/doomdef.h index 28d6aba89..77b30f535 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -558,6 +558,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 diff --git a/src/doomtype.h b/src/doomtype.h index 36025b319..6f2d80794 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -258,7 +258,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)) @@ -407,8 +407,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" diff --git a/src/stun.cpp b/src/stun.cpp index 11bc8cd74..a53930a50 100644 --- a/src/stun.cpp +++ b/src/stun.cpp @@ -12,18 +12,19 @@ /* https://tools.ietf.org/html/rfc5389 */ -#include - #if defined (__linux__) || defined (__FreeBSD__) #include #elif defined (_WIN32) #define _CRT_RAND_S +#include #elif defined (__APPLE__) #include #else #error "Need CSPRNG." #endif +#include + #include "doomdef.h" #include "d_clisrv.h" #include "command.h"