From: Christopher Dykes Date: Mon, 22 May 2017 22:19:00 +0000 (-0700) Subject: Shift the job of defining NOMINMAX into source rather than the build system X-Git-Tag: v2017.05.29.00~18 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=887367cae9e579cd1b715265a4f1b089beda71da;p=folly.git Shift the job of defining NOMINMAX into source rather than the build system 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 --- diff --git a/CMake/FollyCompiler.cmake b/CMake/FollyCompiler.cmake index 31184ec9..00654096 100755 --- a/CMake/FollyCompiler.cmake +++ b/CMake/FollyCompiler.cmake @@ -235,7 +235,6 @@ function(apply_folly_compile_options_to_target THETARGET) # And the extra defines: target_compile_definitions(${THETARGET} PUBLIC - 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. _CRT_NONSTDC_NO_WARNINGS # Don't deprecate posix names of functions. _CRT_SECURE_NO_WARNINGS # Don't deprecate the non _s versions of various standard library functions, because safety is for chumps. _SCL_SECURE_NO_WARNINGS # Don't deprecate the non _s versions of various standard library functions, because safety is for chumps. diff --git a/folly/io/async/AsyncSignalHandler.h b/folly/io/async/AsyncSignalHandler.h index bd8cffff..f4b6bdf6 100644 --- a/folly/io/async/AsyncSignalHandler.h +++ b/folly/io/async/AsyncSignalHandler.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include #include namespace folly { diff --git a/folly/io/async/AsyncTimeout.h b/folly/io/async/AsyncTimeout.h index e7754a12..5a4b2da0 100644 --- a/folly/io/async/AsyncTimeout.h +++ b/folly/io/async/AsyncTimeout.h @@ -25,7 +25,6 @@ #include #include -#include #include #include diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index fe6dcf1e..487af054 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -45,9 +45,9 @@ #include #include #include +#include #include -#include // libevent namespace folly { diff --git a/folly/io/async/EventUtil.h b/folly/io/async/EventUtil.h index 86de9fa9..2ba9af4f 100644 --- a/folly/io/async/EventUtil.h +++ b/folly/io/async/EventUtil.h @@ -21,7 +21,8 @@ #pragma once #include -#include // libevent + +#include namespace folly { diff --git a/folly/portability/Event.h b/folly/portability/Event.h index 0d1526ab..9adb7786 100644 --- a/folly/portability/Event.h +++ b/folly/portability/Event.h @@ -16,12 +16,16 @@ #pragma once +#ifdef _MSC_VER +// This needs to be before the libevent include. +# include +#endif + #include #ifdef _MSC_VER # include # include -# include #endif namespace folly { diff --git a/folly/portability/Windows.h b/folly/portability/Windows.h index 2cb0bda8..7ccfde8c 100755 --- a/folly/portability/Windows.h +++ b/folly/portability/Windows.h @@ -37,6 +37,18 @@ #include // 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 #include