Skip to content

Commit

Permalink
build(win): Fix windows.h pre-definitions (#3965)
Browse files Browse the repository at this point in the history
* Avoid possible double define of NOMINMAX in platform.h
* Move other Windows symbol definitions into the cmake file instead of
  repeating them in certain .cpp files.

Fixes #3964

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Aug 28, 2023
1 parent b445bc6 commit 83c8853
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 24 deletions.
8 changes: 5 additions & 3 deletions src/include/OpenImageIO/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
# include <intrin.h>
#endif

//Avoid min and max being defined
#if defined(_WIN32)
#define NOMINMAX
// Avoid min and max being defined for any subsequent include of windows.h
#ifdef _WIN32
# ifndef NOMINMAX
# define NOMINMAX
# endif
#endif

#include <OpenImageIO/oiioversion.h>
Expand Down
1 change: 1 addition & 0 deletions src/libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (NOT OIIO_USING_FMT_LOCAL)
endif ()

if (WIN32)
add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX -DNOGDI -DVC_EXTRALEAN)
target_link_libraries (OpenImageIO_Util PRIVATE psapi)
endif()

Expand Down
3 changes: 0 additions & 3 deletions src/libutil/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include <OpenImageIO/ustring.h>

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# include <windows.h>

# include <direct.h>
Expand Down
3 changes: 0 additions & 3 deletions src/libutil/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#include <OpenImageIO/platform.h>

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# include <windows.h>
#else
# include <dlfcn.h>
Expand Down
6 changes: 1 addition & 5 deletions src/libutil/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@
#include <OpenImageIO/ustring.h>

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# include <windows.h>

# include <shellapi.h>
# include <windows.h>
#endif


Expand Down
4 changes: 0 additions & 4 deletions src/libutil/sysutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
#include <OpenImageIO/platform.h>

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# include <windows.h>

# define DEFINE_CONSOLEV2_PROPERTIES
# include <cstdio>
# include <io.h>
Expand Down
3 changes: 0 additions & 3 deletions src/libutil/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
#include <boost/container/flat_map.hpp>

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# include <windows.h>
#endif

Expand Down
3 changes: 0 additions & 3 deletions src/libutil/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#include <OpenImageIO/timer.h>

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# include <windows.h>
#endif

Expand Down

0 comments on commit 83c8853

Please sign in to comment.