From 499cec544c80faffbaad0d242297cc4593b25cab Mon Sep 17 00:00:00 2001 From: OmniBlade Date: Sat, 15 Jun 2024 22:38:48 +0100 Subject: [PATCH] Remove need to define NOMINMAX on none windows. This is a quick fix, a better solution is to move to using std::min/std::max that will require a larger refactor. --- CMakeLists.txt | 26 ++++++++++++- CMakePresets.json | 4 +- common/packet.cpp | 2 +- redalert/jshell.h | 2 +- tiberiandawn/function.h | 84 ++++++++++++++++++++--------------------- 5 files changed, 71 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7c8eec9..0c8115a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,10 +85,34 @@ else() endif() if(WIN32) - add_definitions(-DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX) set(COMMON_LIBS winmm) endif() +if(NOT MSVC) + # GCC and Clang don't check new allocations by default while MSVC does. + message(STATUS "Checking whether compiler supports -fcheck-new") + check_cxx_compiler_flag("-Werror -fcheck-new" HAVE_CHECK_NEW) + + if(HAVE_CHECK_NEW) + message(STATUS "yes") + list(APPEND VC_CXX_FLAGS -fcheck-new) + else() + message(STATUS "no") + endif() + + # Some platforms default to an unsigned char, this fixes that. + message(STATUS "Checking whether compiler supports -fsigned-char") + check_cxx_compiler_flag("-Werror -fsigned-char" HAVE_SIGNED_CHAR) + + if(HAVE_SIGNED_CHAR) + message(STATUS "yes") + list(APPEND VC_CXX_FLAGS -fsigned-char) + else() + message(STATUS "no") + endif() +endif() + set(VANILLA_DEFS "") set(VANILLA_LIBS "") diff --git a/CMakePresets.json b/CMakePresets.json index 2290a57d..3e90c08f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -110,7 +110,7 @@ "CMAKE_C_FLAGS_DEBUG": "-g3 -Og", "CMAKE_CXX_FLAGS_RELEASE": "-O3 -g3 -DNDEBUG", "CMAKE_C_FLAGS_RELEASE": "-O3 -g3 -DNDEBUG", - "VC_CXX_FLAGS": "-w;-Wwrite-strings;-Werror=write-strings;-fcheck-new;-DNOMINMAX", + "VC_CXX_FLAGS": "-w;-Wwrite-strings;-Werror=write-strings", "MAP_EDITORTD": "ON", "MAP_EDITORRA": "ON", "BUILD_TOOLS": "ON" @@ -178,7 +178,7 @@ "CMAKE_C_FLAGS_RELEASE": "-O3 -g -DNDEBUG", "CMAKE_EXE_LINKER_FLAGS": "-static-libstdc++ -static-libgcc", "CMAKE_SHARESD_LINKER_FLAGS": "-static-libstdc++ -static-libgcc", - "VC_CXX_FLAGS": "-fpermissive;-w;-Wwrite-strings;-Werror=write-strings;-fcheck-new;-fsigned-char;-DNOMINMAX", + "VC_CXX_FLAGS": "-w;-Wwrite-strings;-Werror=write-strings", "MAP_EDITORTD": "ON", "MAP_EDITORRA": "ON", "BUILD_TOOLS": "ON" diff --git a/common/packet.cpp b/common/packet.cpp index 010ae72c..da29423f 100644 --- a/common/packet.cpp +++ b/common/packet.cpp @@ -38,7 +38,7 @@ #include "packet.h" #include "endianness.h" -#ifdef NOMINMAX +#if !defined _WIN32 || defined NOMINMAX inline int min(int a, int b) { return a < b ? a : b; diff --git a/redalert/jshell.h b/redalert/jshell.h index 6a68d792..15ec5526 100644 --- a/redalert/jshell.h +++ b/redalert/jshell.h @@ -80,7 +80,7 @@ template inline T operator~(T t1) return ((T)(~(int)t1)); } -#ifdef NOMINMAX +#if !defined _WIN32 || defined NOMINMAX inline int min(int a, int b) { return a < b ? a : b; diff --git a/tiberiandawn/function.h b/tiberiandawn/function.h index 454679a6..d05d12e3 100644 --- a/tiberiandawn/function.h +++ b/tiberiandawn/function.h @@ -39,56 +39,56 @@ Map(screen) class heirarchy. MapeditClass(most derived class)-- scenario editor - ³ MouseClass-- handles mouse animation and display control - ³ ScrollClass-- map scroll handler - ³ HelpClass-- pop + � MouseClass-- handles mouse animation and display control + � ScrollClass-- map scroll handler + � HelpClass-- pop - up help text handler - ³ TabClass-- file folder tab screen mode control dispatcher - ³ SidebarClass-- displays and controls construction list sidebar - ³ PowerClass-- display power production + � TabClass-- file folder tab screen mode control dispatcher + � SidebarClass-- displays and controls construction list sidebar + � PowerClass-- display power production / consumption bargraph - ³ RadarClass-- displays and controls radar map - ³ DisplayClass-- general tactical map display handler - ³ MapClass-- general tactical map data handler - ³ GScreenClass(pure virtual base class)-- generic screen control + � RadarClass-- displays and controls radar map + � DisplayClass-- general tactical map display handler + � MapClass-- general tactical map data handler + � GScreenClass(pure virtual base class)-- generic screen control AbstractClass - ³ - ³ - ³ - ³ ObjectClass - ³ - ÚÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄ¿ - AnimClass ³ TemplateClass ³ ÃÄ FuseClass ³ TerrainClass - ³ ³ ÃÄ FlyClass ³ - ³ ³ BulletClass ³ OverlayClass MissionClass SmudgeClass - ³ RadioClass - ³ - ÃÄ CrewClass - ÃÄ FlasherClass - ÃÄ StageClass - ÃÄ CargoClass TechnoClass - ³ - ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ FootClass BuildingClass - ³ - ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ DriveClass InfantryClass ÃÄ FlyClass - ³ AircraftClass TurretClass - ³ TarComClass - ³ UnitClass + � + � + � + � ObjectClass + � + ����������������������������������������������������������������Ŀ + AnimClass � TemplateClass � �� FuseClass � TerrainClass + � � �� FlyClass � + � � BulletClass � OverlayClass MissionClass SmudgeClass + � RadioClass + � + �� CrewClass + �� FlasherClass + �� StageClass + �� CargoClass TechnoClass + � + �����������������������������������������������������Ŀ FootClass BuildingClass + � + ����������������������������Ŀ DriveClass InfantryClass �� FlyClass + � AircraftClass TurretClass + � TarComClass + � UnitClass AbstractTypeClass - ³ ObjectTypeClass - ³ - ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ - ³ ³ ³ ³ TechnoTypeClass ³ ³ ³ - ³ BulletTypeClass ³ ³ - ³ TemplateTypeClass ³ - ÚÄÄÄÄÄÄÄÄÁÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ TerrainTypeClass - ³ ³ ³ ³ UnitTypeClass ³ BuildingTypeClass ³ - ³ InfantryTypeClass AircraftTypeClass + � ObjectTypeClass + � + �����������������������������������������������������Ŀ + � � � � TechnoTypeClass � � � + � BulletTypeClass � � + � TemplateTypeClass � + �����������������������������������������Ŀ TerrainTypeClass + � � � � UnitTypeClass � BuildingTypeClass � + � InfantryTypeClass AircraftTypeClass */ -#ifdef NOMINMAX +#if !defined _WIN32 || defined NOMINMAX inline int min(int a, int b) { return a < b ? a : b;