Shift the job of defining NOMINMAX into source rather than the build system
authorChristopher Dykes <cdykes@fb.com>
Mon, 22 May 2017 22:19:00 +0000 (15:19 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 22 May 2017 22:20:02 +0000 (15:20 -0700)
Summary:
This makes it easier to consume Folly from a non-cmake project.
Note that this also requires making libevent, which was previously categorized as a semi-portable header into a non-portable header, meaning it can't be referenced directly. (libevent includes `Windows.h` in one of its headers -_-....)

Reviewed By: yfeldblum

Differential Revision: D5106051

fbshipit-source-id: 5ce2d4188c9036d6ab206af3036c8fd4b09516a4

CMake/FollyCompiler.cmake
folly/io/async/AsyncSignalHandler.h
folly/io/async/AsyncTimeout.h
folly/io/async/EventBase.h
folly/io/async/EventUtil.h
folly/portability/Event.h
folly/portability/Windows.h

index 31184ec983b5e50fa024f61f0f35d0230f2dfa4d..006540961d61d59848edbeb1bc4eaf82389bd186 100755 (executable)
@@ -235,7 +235,6 @@ function(apply_folly_compile_options_to_target THETARGET)
   # And the extra defines:\r
   target_compile_definitions(${THETARGET}\r
     PUBLIC\r
-      NOMINMAX # This is needed because, for some absurd reason, one of the windows headers tries to define "min" and "max" as macros, which messes up most uses of std::numeric_limits.\r
       _CRT_NONSTDC_NO_WARNINGS # Don't deprecate posix names of functions.\r
       _CRT_SECURE_NO_WARNINGS # Don't deprecate the non _s versions of various standard library functions, because safety is for chumps.\r
       _SCL_SECURE_NO_WARNINGS # Don't deprecate the non _s versions of various standard library functions, because safety is for chumps.\r
index bd8cffff3f24f58a15bceeb8e7db79fa95bf564f..f4b6bdf6b606b511adfc0920c4ccaca131369b9d 100644 (file)
@@ -16,7 +16,7 @@
 #pragma once
 
 #include <folly/io/async/EventBase.h>
-#include <event.h>
+#include <folly/portability/Event.h>
 #include <map>
 
 namespace folly {
index e7754a12e05f6a8eaff6fd15acfd589055712a98..5a4b2da0597244dd8ec54ab112983627a6580b9a 100644 (file)
@@ -25,7 +25,6 @@
 #include <folly/portability/Event.h>
 
 #include <boost/noncopyable.hpp>
-#include <event.h>
 #include <memory>
 #include <utility>
 
index fe6dcf1eb8a2d48642ed78c63e4eab2a1df09073..487af0547f09071c83bd1dd669a7645b2c3b5ee7 100644 (file)
@@ -45,9 +45,9 @@
 #include <folly/io/async/HHWheelTimer.h>
 #include <folly/io/async/Request.h>
 #include <folly/io/async/TimeoutManager.h>
+#include <folly/portability/Event.h>
 #include <glog/logging.h>
 
-#include <event.h>  // libevent
 
 namespace folly {
 
index 86de9fa9f76fdb44495b7d85fdb3c4acd27a2908..2ba9af4ffaad45e5b617325d6181f0aabe6593bd 100644 (file)
@@ -21,7 +21,8 @@
 #pragma once
 
 #include <functional>
-#include <event.h>  // libevent
+
+#include <folly/portability/Event.h>
 
 namespace folly {
 
index 0d1526abf57785c2ed3822d7bbb85db037bf11da..9adb7786568ff2f44e0e437a253dddcd25203560 100644 (file)
 
 #pragma once
 
+#ifdef _MSC_VER
+// This needs to be before the libevent include.
+# include <folly/portability/Windows.h>
+#endif
+
 #include <event.h>
 
 #ifdef _MSC_VER
 # include <event2/event_compat.h>
 # include <folly/portability/Fcntl.h>
-# include <folly/portability/Windows.h>
 #endif
 
 namespace folly {
index 2cb0bda86769d89cfbf9c35457635ba66394348c..7ccfde8c01a99eafd109ff4ef9d574d6851291bf 100755 (executable)
 #include <direct.h> // nolint
 #endif
 
+#if defined(min) || defined(max)
+#error Windows.h needs to be included by this header, or else NOMINMAX needs \
+ to be defined before including it yourself.
+#endif
+
+// This is needed because, for some absurd reason, one of the windows headers
+// tries to define "min" and "max" as macros, which messes up most uses of
+// std::numeric_limits.
+#ifndef NOMINMAX
+#define NOMINMAX 1
+#endif
+
 #include <WinSock2.h>
 #include <Windows.h>