Avoid relying on max() from windows.h

Unfortunately, windows.h breaks the standard library because it
defines max() as a macro by default.

To fix this, add NOMINMAX (and WIN32_LEAN_AND_MEAN for good measure) to
the compile options. Ideally, this would be set on a per-target basis,
but with so many OBJECT targets, that is really tedious. Luckily,
add_compile_definitions() is scoped to the current directory and sub-
directories only.
This commit is contained in:
Johannes Kauffmann
2022-09-11 02:04:55 +02:00
committed by Kai Blaschke
parent 91a0b0be23
commit 6edb9d01dd
3 changed files with 2 additions and 6 deletions

View File

@ -20,6 +20,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Additional preprocessor definitions for Windows builds
add_compile_definitions(
NOMINMAX
WIN32_LEAN_AND_MEAN
USE_FTGL
USE_NATIVE_GLEW
STBI_NO_DDS

View File

@ -74,7 +74,6 @@
#if defined( __WIN32__ ) || defined( _WIN32 ) || defined( WIN32 )
#define SOIL_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wingdi.h>
#include <GL/gl.h>

View File

@ -51,13 +51,8 @@ TextureManager::TextureManager(std::vector<std::string>& textureSearchPaths, int
// blur5 = 64 <- user sees this as "blur3"
if (!(i&1) || (i<2))
{
#if defined WIN32 && defined max
w = max(16, w / 2);
h = max(16, h / 2);
#else
w = std::max(16, w / 2);
h = std::max(16, h / 2);
#endif /** WIN32 */
}
int w2 = ((w+3)/16)*16;
int h2 = ((h+3)/4)*4;