From a7001e5c7a9b53fb61ccec900f6f43d66c597d82 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Fri, 26 May 2017 14:03:46 -0700 Subject: [PATCH] Fix build with Ninja generator Summary: We were hitting a bug in CMake's Ninja generator that was causing it to incorrectly attempt to escape the closing quote on `_HAS_AUTO_PTR_ETC=1`, so remove the quotes, as they aren't actually needed. This also makes a few quality-of-life changes to make building Folly with Ninja slightly easier. Closes: https://github.com/facebook/folly/issues/604 Reviewed By: yfeldblum Differential Revision: D5134585 fbshipit-source-id: 3816e53774f7963b9b4fd8ddf68b83ff7afdefe1 --- CMake/FollyCompiler.cmake | 18 ++++++++++++++++-- CMakeLists.txt | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CMake/FollyCompiler.cmake b/CMake/FollyCompiler.cmake index 00654096..5b0058a7 100755 --- a/CMake/FollyCompiler.cmake +++ b/CMake/FollyCompiler.cmake @@ -43,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. @@ -241,8 +255,8 @@ function(apply_folly_compile_options_to_target THETARGET) _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 + $<$:_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, diff --git a/CMakeLists.txt b/CMakeLists.txt index c17760a2..97f9bcf9 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@ if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio 15( 2017)? Win64") elseif ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 14 2015 Win64") set(CMAKE_GENERATOR_TOOLSET "v140truev140") set(MSVC_IS_2017 OFF) +elseif ("${CMAKE_GENERATOR}" STREQUAL "Ninja") + message("Folly is being built with Ninja, so assuming VS 2017 is being used.") + set(MSVC_IS_2017 ON) else() message(FATAL_ERROR "This build script only supports building Folly on 64-bit Windows with Visual Studio 2015 or Visual Studio 2017.") endif() -- 2.34.1