From d0484a9ea9331f2cedb080f06944d737343414f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 25 Apr 2021 19:41:07 +0200 Subject: [PATCH] CMake: Fix MSVC flags for Release/RelWithDebInfo See https://gitlab.kitware.com/cmake/cmake/-/issues/20812 Manually redefine MSVC flags to match Visual Studio defaults and ensure that Release builds generate debug info. --- CMake/FlagsOverride.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CMake/FlagsOverride.cmake b/CMake/FlagsOverride.cmake index 39c55aa62a..d52cf4b153 100644 --- a/CMake/FlagsOverride.cmake +++ b/CMake/FlagsOverride.cmake @@ -1,7 +1,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - foreach(f CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if("${${f}}" MATCHES "/Zi") - string(REGEX REPLACE "/Zi" "/Z7" "${f}" "${${f}}") - endif() - endforeach() -endif() \ No newline at end of file + # The default MSVC flags for Release and RelWithDebInfo are poorly chosen + # (see issue https://gitlab.kitware.com/cmake/cmake/-/issues/20812) + # By default, inlining is disabled for RelWithDebInfo. + # Manually redefine MSVC flags to match Visual Studio defaults + # and ensure that Release builds generate debug info. + foreach(f CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELEASE) + # optimize, define NDEBUG, generate debug info + set(${f} "/O2 /DNDEBUG /Z7") + endforeach() +endif()