diff options
-rw-r--r-- | base/logging.h | 62 | ||||
-rw-r--r-- | build/internal/release_impl_official.scons | 3 | ||||
-rw-r--r-- | build/internal/release_impl_official.vsprops | 1 |
3 files changed, 64 insertions, 2 deletions
diff --git a/base/logging.h b/base/logging.h index 85c57b3..062ce8e 100644 --- a/base/logging.h +++ b/base/logging.h @@ -258,7 +258,64 @@ std::string* MakeCheckOpString(const int& v1, const int& v2, const char* names) // foo.CheckThatFoo(); // #endif +#ifdef OFFICIAL_BUILD +// We want to have optimized code for an official build so we remove DLOGS and +// DCHECK from the executable. + +#define DLOG(severity) \ + true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) + +#define DLOG_IF(severity, condition) \ + true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) + +#define DLOG_ASSERT(condition) \ + true ? (void) 0 : LOG_ASSERT(condition) + +enum { DEBUG_MODE = 0 }; + +// This macro can be followed by a sequence of stream parameters in +// non-debug mode. The DCHECK and friends macros use this so that +// the expanded expression DCHECK(foo) << "asdf" is still syntactically +// valid, even though the expression will get optimized away. +#define NDEBUG_EAT_STREAM_PARAMETERS \ + logging::LogMessage(__FILE__, __LINE__).stream() + +#define DCHECK(condition) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_EQ(val1, val2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_NE(val1, val2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_LE(val1, val2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_LT(val1, val2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_GE(val1, val2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_GT(val1, val2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_STREQ(str1, str2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_STRCASEEQ(str1, str2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_STRNE(str1, str2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#define DCHECK_STRCASENE(str1, str2) \ + while (false) NDEBUG_EAT_STREAM_PARAMETERS + +#else #ifndef NDEBUG +// On a regular debug build, we want to have DCHECKS and DLOGS enabled. #define DLOG(severity) LOG(severity) #define DLOG_IF(severity, condition) LOG_IF(severity, condition) @@ -312,7 +369,8 @@ DECLARE_DCHECK_STROP_IMPL(_stricmp, false) #define DCHECK_BOUND(B,A) DCHECK(B <= (sizeof(A)/sizeof(A[0]))) #else // NDEBUG - +// On a regular release build we want to be able to enable DCHECKS through the +// command line. #define DLOG(severity) \ true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) @@ -407,6 +465,7 @@ DEFINE_DCHECK_OP_IMPL(GT, > ) #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) +#endif // OFFICIAL_BUILD #define NOTREACHED() DCHECK(false) @@ -541,4 +600,3 @@ inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) { #endif #endif // BASE_LOGGING_H_ - diff --git a/build/internal/release_impl_official.scons b/build/internal/release_impl_official.scons index b64ab91..94e9670 100644 --- a/build/internal/release_impl_official.scons +++ b/build/internal/release_impl_official.scons @@ -28,6 +28,9 @@ if env.Bit('windows'): '/GT', # VCCLCompilerTool.EnableFiberSafeOptimizations="true" '/GL', # VCCLCompilerTool.WholeProgramOptimization="true" ], + CPPDEFINES = [ + 'OFFICIAL_BUILD', + ], LINKFLAGS = [ '/LTCG', # VCLinkerTool.LinkTimeCodeGeneration="1" ], diff --git a/build/internal/release_impl_official.vsprops b/build/internal/release_impl_official.vsprops index c9a4401..12899c7 100644 --- a/build/internal/release_impl_official.vsprops +++ b/build/internal/release_impl_official.vsprops @@ -7,6 +7,7 @@ > <Tool Name="VCCLCompilerTool" + PreprocessorDefinitions="OFFICIAL_BUILD" Optimization="3" InlineFunctionExpansion="2" EnableIntrinsicFunctions="true" |