Make cxx exceptions controllable (#4591)
* Make cxx exceptions controllable
Found a possible link error if we compile spirv-tools by using VS2019 and link with VS2017 for another project, unresolved symbols as _CxxFrameHandler4 and __GSHandlerCheck_EH4 will be thrown. As Visual Studio updated its c++ exceptions libs.
https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/
So we are making cxx exceptions controllable via a CMake option `ENABLE_EXCEPTIONS_ON_MSVC`.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 01e3b16..70caf85 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -164,6 +164,7 @@
# Note this target provides no API stability guarantees.
#
# Ideally, all of these will go away - see https://github.com/KhronosGroup/SPIRV-Tools/issues/3909.
+option(ENABLE_EXCEPTIONS_ON_MSVC "Build SPIRV-TOOLS with c++ exceptions enabled in MSVC" ON)
option(SPIRV_TOOLS_BUILD_STATIC "Build ${SPIRV_TOOLS}-static target. ${SPIRV_TOOLS} will alias to ${SPIRV_TOOLS}-static or ${SPIRV_TOOLS}-shared based on BUILD_SHARED_LIBS" ON)
if(SPIRV_TOOLS_BUILD_STATIC)
set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}-static)
@@ -215,7 +216,9 @@
if (MSVC)
# Specify /EHs for exception handling. This makes using SPIRV-Tools as
# dependencies in other projects easier.
- target_compile_options(${TARGET} PRIVATE /EHs)
+ if(ENABLE_EXCEPTIONS_ON_MSVC)
+ target_compile_options(${TARGET} PRIVATE /EHs)
+ endif()
endif()
# For MinGW cross compile, statically link to the C++ runtime.