Skip to content

Commit

Permalink
Remove need to define NOMINMAX on none windows.
Browse files Browse the repository at this point in the history
This is a quick fix, a better solution is to move to using std::min/std::max that will require a larger refactor.
  • Loading branch information
OmniBlade committed Jun 16, 2024
1 parent 2de948c commit 5c6e612
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")

Expand Down
5 changes: 3 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -199,6 +199,7 @@
"BUILD_VANILLARA": "OFF",
"MAP_EDITORTD": "OFF",
"MAP_EDITORRA": "OFF",
"VC_CXX_FLAGS": "-fpermissive;-w;-Wwrite-strings;-Werror=write-strings",
"BUILD_TOOLS": "OFF"
}
},
Expand Down
2 changes: 1 addition & 1 deletion common/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion redalert/jshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ template <class T> 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;
Expand Down
2 changes: 1 addition & 1 deletion tiberiandawn/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Map(screen) class heirarchy.
³ InfantryTypeClass AircraftTypeClass
*/

#ifdef NOMINMAX
#if !defined _WIN32 || defined NOMINMAX
inline int min(int a, int b)
{
return a < b ? a : b;
Expand Down

0 comments on commit 5c6e612

Please sign in to comment.