# Some additional configuration options.\r
option(MSVC_ENABLE_ALL_WARNINGS "If enabled, pass /Wall to the compiler." ON)\r
+option(MSVC_ENABLE_CPP_LATEST "If enabled, pass /std:c++latest to the compiler" ON)\r
option(MSVC_ENABLE_DEBUG_INLINING "If enabled, enable inlining in the debug configuration. This allows /Zc:inline to be far more effective." OFF)\r
option(MSVC_ENABLE_FAST_LINK "If enabled, pass /DEBUG:FASTLINK to the linker. This makes linking faster, but the gtest integration for Visual Studio can't currently handle the .pdbs generated." OFF)\r
+option(MSVC_ENABLE_LEAN_AND_MEAN_WINDOWS "If enabled, define WIN32_LEAN_AND_MEAN to include a smaller subset of Windows.h" ON)\r
option(MSVC_ENABLE_LTCG "If enabled, use Link Time Code Generation for Release builds." OFF)\r
option(MSVC_ENABLE_PARALLEL_BUILD "If enabled, build multiple source files in parallel." ON)\r
option(MSVC_ENABLE_STATIC_ANALYSIS "If enabled, do more complex static analysis and generate warnings appropriately." OFF)\r
\r
# Alas, option() doesn't support string values.\r
set(MSVC_FAVORED_ARCHITECTURE "blend" CACHE STRING "One of 'blend', 'AMD64', 'INTEL64', or 'ATOM'. This tells the compiler to generate code optimized to run best on the specified architecture.")\r
+# Add a pretty drop-down selector for these values when using the GUI.\r
+set_property(\r
+ CACHE MSVC_FAVORED_ARCHITECTURE\r
+ PROPERTY STRINGS\r
+ blend\r
+ AMD64\r
+ ATOM\r
+ INTEL64\r
+)\r
# Validate, and then add the favored architecture.\r
if (NOT MSVC_FAVORED_ARCHITECTURE STREQUAL "blend" AND NOT MSVC_FAVORED_ARCHITECTURE STREQUAL "AMD64" AND NOT MSVC_FAVORED_ARCHITECTURE STREQUAL "INTEL64" AND NOT MSVC_FAVORED_ARCHITECTURE STREQUAL "ATOM")\r
message(FATAL_ERROR "MSVC_FAVORED_ARCHITECTURE must be set to one of exactly, 'blend', 'AMD64', 'INTEL64', or 'ATOM'! Got '${MSVC_FAVORED_ARCHITECTURE}' instead!")\r
endforeach()\r
endif()\r
\r
+# The Ninja generator doesn't de-dup the exception mode flag, so remove the\r
+# default flag so that MSVC doesn't warn about it on every single file.\r
+if ("${CMAKE_GENERATOR}" STREQUAL "Ninja")\r
+ foreach(flag_var\r
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE\r
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO\r
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE\r
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)\r
+ if (${flag_var} MATCHES "/EHsc")\r
+ string(REGEX REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}")\r
+ endif()\r
+ endforeach()\r
+endif()\r
+\r
# In order for /Zc:inline, which speeds up the build significantly, to work\r
# we need to remove the /Ob0 parameter that CMake adds by default, because that\r
# would normally disable all inlining.\r
# The general options passed:\r
target_compile_options(${THETARGET}\r
PUBLIC\r
- #/std:c++latest # Build in C++17 mode\r
/EHa # Enable both SEH and C++ Exceptions.\r
+ /GF # There are bugs with constexpr StringPiece when string pooling is disabled.\r
/Zc:referenceBinding # Disallow temporaries from binding to non-const lvalue references.\r
/Zc:rvalueCast # Enforce the standard rules for explicit type conversion.\r
/Zc:implicitNoexcept # Enable implicit noexcept specifications where required, such as destructors.\r
/Zc:strictStrings # Don't allow conversion from a string literal to mutable characters.\r
/Zc:threadSafeInit # Enable thread-safe function-local statics initialization.\r
/Zc:throwingNew # Assume operator new throws on failure.\r
- /permissive- # Be mean, don't allow bad non-standard stuff (C++/CLI, __declspec, etc. are all left intact).\r
+\r
+ $<$<BOOL:${MSVC_ENABLE_CPP_LATEST}>:/std:c++latest> # Build in C++ Latest mode if requested.\r
+\r
+ # This is only supported by MSVC 2017\r
+ $<$<BOOL:${MSVC_IS_2017}>:/permissive-> # Be mean, don't allow bad non-standard stuff (C++/CLI, __declspec, etc. are all left intact).\r
PRIVATE\r
/bigobj # Support objects with > 65k sections. Needed due to templates.\r
/favor:${MSVC_FAVORED_ARCHITECTURE} # Architecture to prefer when generating code.\r
# Debug builds\r
$<$<CONFIG:DEBUG>:\r
/Gy- # Disable function level linking.\r
- /GF- # Disable string pooling.\r
\r
$<$<BOOL:${MSVC_ENABLE_DEBUG_INLINING}>:/Ob2> # Add /Ob2 if allowing inlining in debug mode.\r
>\r
\r
# Non-debug builds\r
$<$<NOT:$<CONFIG:DEBUG>>:\r
- /GF # Enable string pooling. (this is enabled by default by the optimization level, but we enable it here for clarity)\r
/Gw # Optimize global data. (-fdata-sections)\r
/Gy # Enable function level linking. (-ffunction-sections)\r
/Qpar # Enable parallel code generation.\r
/wd4366 # result of unary '&' operator may be unaligned\r
/wd4587 # behavior change; constructor no longer implicitly called\r
/wd4592 # symbol will be dynamically initialized (implementation limitation)\r
+ /wd4628 # digraphs not supported with -Ze\r
/wd4723 # potential divide by 0\r
/wd4724 # potential mod by 0\r
/wd4868 # compiler may not enforce left-to-right evaluation order\r
# And the extra defines:\r
target_compile_definitions(${THETARGET}\r
PUBLIC\r
- _HAS_AUTO_PTR_ETC=1 # We're building in C++ 17 mode, but certain dependencies (Boost) still have dependencies on unary_function and binary_function, so we have to make sure not to remove them.\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
- _WINSOCK_DEPRECATED_NO_WARNINGS # Don't deprecate pieces of winsock\r
- WIN32_LEAN_AND_MEAN # Don't include most of Windows.h\r
\r
- _STL_EXTRA_DISABLED_WARNINGS=4365\ 4774\ 4775\ 4987\r
+ _STL_EXTRA_DISABLED_WARNINGS=4774\ 4987\r
+\r
+ $<$<BOOL:${MSVC_ENABLE_CPP_LATEST}>:_HAS_AUTO_PTR_ETC=1> # We're building in C++ 17 or greater mode, but certain dependencies (Boost) still have dependencies on unary_function and binary_function, so we have to make sure not to remove them.\r
+ $<$<BOOL:${MSVC_ENABLE_LEAN_AND_MEAN_WINDOWS}>:WIN32_LEAN_AND_MEAN> # Don't include most of Windows.h\r
)\r
\r
# Ignore a warning about an object file not defining any symbols,\r