Move the definition of NOMINMAX to source files

Defining the NOMINMAX macro in our build system doesn't work if an
alternative build system is used.

Always define WIN32_LEAN_AND_MEAN before including <windows.h>.

Change-Id: I2f80e51c5553b8d37eebaea27ad0431b1ed20046
diff --git a/aom_ports/aom_once.h b/aom_ports/aom_once.h
index 354ed9d..680120f 100644
--- a/aom_ports/aom_once.h
+++ b/aom_ports/aom_once.h
@@ -39,6 +39,8 @@
  */
 
 #if CONFIG_MULTITHREAD && defined(_WIN32)
+#undef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 /* Declare a per-compilation-unit state variable to track the progress
  * of calling func() only once. This must be at global scope because
diff --git a/aom_ports/aom_timer.h b/aom_ports/aom_timer.h
index 9a876eb..642c5a0 100644
--- a/aom_ports/aom_timer.h
+++ b/aom_ports/aom_timer.h
@@ -23,9 +23,10 @@
 /*
  * Win32 specific includes
  */
-#ifndef WIN32_LEAN_AND_MEAN
+#undef NOMINMAX
+#define NOMINMAX
+#undef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
-#endif
 #include <windows.h>
 #else
 /*
diff --git a/aom_ports/x86.h b/aom_ports/x86.h
index f390dfa..d44d386 100644
--- a/aom_ports/x86.h
+++ b/aom_ports/x86.h
@@ -148,6 +148,10 @@
 #endif
 
 #if defined(_MSC_VER) && _MSC_VER >= 1700
+#undef NOMINMAX
+#define NOMINMAX
+#undef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #if WINAPI_FAMILY_PARTITION(WINAPI_FAMILY_APP)
 #define getenv(x) NULL
diff --git a/build/cmake/aom_configure.cmake b/build/cmake/aom_configure.cmake
index 39e5c53..d3c09628 100644
--- a/build/cmake/aom_configure.cmake
+++ b/build/cmake/aom_configure.cmake
@@ -242,9 +242,6 @@
   # The default _WIN32_WINNT value in MinGW is 0x0502 (Windows XP with SP2). Set
   # it to 0x0601 (Windows 7).
   add_compiler_flag_if_supported("-D_WIN32_WINNT=0x0601")
-  # Prevent windows.h from defining the min and max macros. This allows us to
-  # use std::min and std::max.
-  add_compiler_flag_if_supported("-DNOMINMAX")
   # Quiet warnings related to fopen, printf, etc.
   add_compiler_flag_if_supported("-D_CRT_SECURE_NO_WARNINGS")
 endif()