VS: Disabling c++ exceptions and rtti in the toolchain file on Windows makes the Visual Studio debug configuration act like a release configuration
I am working on a personal project that disables C++ exceptions and RTTI. I am using Visual Studio 2019 Community Edition. I have upgraded to CMake 3.17 as soon as it came out and previously I was using CMake 3.16.X.
So far, on Windows, I have been disabling them in the toolchain file using the following way. This way allows me to propagate these constraints down to sub-projects or third-party dependencies.
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REPLACE /GR /GR- "${flag_var}" "${${flag_var}}")
string(REPLACE /EHsc /EHsc- "${flag_var}" "${${flag_var}}")
endforeach()
add_definitions(-D_HAS_EXCEPTIONS=0)
Since my upgrade to CMake 3.17, the Debug configuration in Visual Studio does not behave like an actual Debug configuration anymore. Instead, optimizations are turned on (/O2) and other flags such as /Zi are not enabled. Just using the above code in a toolchain file will reproduce the issue.
Is this way of disabling exceptions not supported anymore or have I been wrongly disabling exceptions and rtti in this way?