X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=CMake%2FFollyCompiler.cmake;h=70dfe378674771683bfc3af03fac6a476f13bafb;hb=090b0ac74a96e4f3acca6c45cbc747eece365679;hp=29d2ca2e5ad951e6ac4ed688f50f08e4841d127b;hpb=c2e28878d8f88359599da03080fbbe71dac2e80f;p=folly.git diff --git a/CMake/FollyCompiler.cmake b/CMake/FollyCompiler.cmake index 29d2ca2e..70dfe378 100755 --- a/CMake/FollyCompiler.cmake +++ b/CMake/FollyCompiler.cmake @@ -1,7 +1,9 @@ # Some additional configuration options. option(MSVC_ENABLE_ALL_WARNINGS "If enabled, pass /Wall to the compiler." ON) +option(MSVC_ENABLE_CPP_LATEST "If enabled, pass /std:c++latest to the compiler" ON) option(MSVC_ENABLE_DEBUG_INLINING "If enabled, enable inlining in the debug configuration. This allows /Zc:inline to be far more effective." OFF) 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) +option(MSVC_ENABLE_LEAN_AND_MEAN_WINDOWS "If enabled, define WIN32_LEAN_AND_MEAN to include a smaller subset of Windows.h" ON) option(MSVC_ENABLE_LTCG "If enabled, use Link Time Code Generation for Release builds." OFF) option(MSVC_ENABLE_PARALLEL_BUILD "If enabled, build multiple source files in parallel." ON) option(MSVC_ENABLE_STATIC_ANALYSIS "If enabled, do more complex static analysis and generate warnings appropriately." OFF) @@ -9,6 +11,15 @@ option(MSVC_USE_STATIC_RUNTIME "If enabled, build against the static, rather tha # Alas, option() doesn't support string values. 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.") +# Add a pretty drop-down selector for these values when using the GUI. +set_property( + CACHE MSVC_FAVORED_ARCHITECTURE + PROPERTY STRINGS + blend + AMD64 + ATOM + INTEL64 +) # Validate, and then add the favored architecture. 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") message(FATAL_ERROR "MSVC_FAVORED_ARCHITECTURE must be set to one of exactly, 'blend', 'AMD64', 'INTEL64', or 'ATOM'! Got '${MSVC_FAVORED_ARCHITECTURE}' instead!") @@ -32,6 +43,20 @@ if (MSVC_USE_STATIC_RUNTIME) endforeach() endif() +# The Ninja generator doesn't de-dup the exception mode flag, so remove the +# default flag so that MSVC doesn't warn about it on every single file. +if ("${CMAKE_GENERATOR}" STREQUAL "Ninja") + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if (${flag_var} MATCHES "/EHsc") + string(REGEX REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}") + endif() + endforeach() +endif() + # In order for /Zc:inline, which speeds up the build significantly, to work # we need to remove the /Ob0 parameter that CMake adds by default, because that # would normally disable all inlining. @@ -46,8 +71,8 @@ function(apply_folly_compile_options_to_target THETARGET) # The general options passed: target_compile_options(${THETARGET} PUBLIC - #/std:c++latest # Build in C++17 mode /EHa # Enable both SEH and C++ Exceptions. + /GF # There are bugs with constexpr StringPiece when string pooling is disabled. /Zc:referenceBinding # Disallow temporaries from binding to non-const lvalue references. /Zc:rvalueCast # Enforce the standard rules for explicit type conversion. /Zc:implicitNoexcept # Enable implicit noexcept specifications where required, such as destructors. @@ -55,6 +80,8 @@ function(apply_folly_compile_options_to_target THETARGET) /Zc:threadSafeInit # Enable thread-safe function-local statics initialization. /Zc:throwingNew # Assume operator new throws on failure. + $<$:/std:c++latest> # Build in C++ Latest mode if requested. + # This is only supported by MSVC 2017 $<$:/permissive-> # Be mean, don't allow bad non-standard stuff (C++/CLI, __declspec, etc. are all left intact). PRIVATE @@ -69,14 +96,12 @@ function(apply_folly_compile_options_to_target THETARGET) # Debug builds $<$: /Gy- # Disable function level linking. - /GF- # Disable string pooling. $<$:/Ob2> # Add /Ob2 if allowing inlining in debug mode. > # Non-debug builds $<$>: - /GF # Enable string pooling. (this is enabled by default by the optimization level, but we enable it here for clarity) /Gw # Optimize global data. (-fdata-sections) /Gy # Enable function level linking. (-ffunction-sections) /Qpar # Enable parallel code generation. @@ -223,15 +248,14 @@ function(apply_folly_compile_options_to_target THETARGET) # And the extra defines: target_compile_definitions(${THETARGET} PUBLIC - _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. - 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. - _WINSOCK_DEPRECATED_NO_WARNINGS # Don't deprecate pieces of winsock - WIN32_LEAN_AND_MEAN # Don't include most of Windows.h - _STL_EXTRA_DISABLED_WARNINGS=4365\ 4774\ 4775\ 4987 + _STL_EXTRA_DISABLED_WARNINGS=4774\ 4987 + + $<$:_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. + $<$:WIN32_LEAN_AND_MEAN> # Don't include most of Windows.h ) # Ignore a warning about an object file not defining any symbols,