Skip to content

Commit

Permalink
build(win): Fix windows.h pre-definitions
Browse files Browse the repository at this point in the history
* Avoid possible double define of NOMINMAX in platform.h
* More "NO" definitions in the several files where we do include
  windows.h to make the include less expensive.

Fixes 3964

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Aug 27, 2023
1 parent b445bc6 commit db972dc
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 21 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
15 changes: 12 additions & 3 deletions src/libutil/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
#include <OpenImageIO/ustring.h>

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

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

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOMINMAX
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# ifndef VC_EXTRALEAN
# define VC_EXTRALEAN
# endif
# ifndef NOMINMAX
# define NOMINMAX
# endif
# ifndef NOGDI
# define NOGDI
# endif
# include <windows.h>
#else
# include <dlfcn.h>
Expand Down
15 changes: 12 additions & 3 deletions src/libutil/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,18 @@
#include <OpenImageIO/ustring.h>

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

# include <shellapi.h>
Expand Down
15 changes: 12 additions & 3 deletions src/libutil/sysutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@
#include <OpenImageIO/platform.h>

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

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

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

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

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

Expand Down

0 comments on commit db972dc

Please sign in to comment.