cmake: Add exception handling support to MSVC compile flags
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 10 Apr 2018 20:18:33 +0000 (22:18 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 10 Apr 2018 21:06:33 +0000 (23:06 +0200)
Since STL types may throw, MSVC needs to get told to support
exceptions by specifying the /EHsc flag. Otherwise, it warns about
the lack thereof, even though Quassel itself does not use nor handle
exceptions.

Closes GH-350.

(cherry picked from commit 7a8ea3eee1dcff4eaa5398d1cf5739fa32eccd9e)

cmake/QuasselCompileSettings.cmake

index 9f3e00a..f48dfb2 100644 (file)
@@ -66,12 +66,15 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
 
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
 
-# For MSVC, at least do a version sanity check
+# For MSVC, at least do a version sanity check...
 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "18.0")
         message(WARNING "Your compiler is too old; we expect at least Visual Studio Nov 2013 CTP (MSVC 18). Your build will likely fail.")
     endif()
 
+    # ... and enable exception handling (required for STL types)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
+
 # Unknown/unsupported compiler
 else()
     message(WARNING "Unknown or unsupported compiler. Make sure to enable C++11 support. Good luck.")