cmake: add standard c++ exception handling on Windows

This commit is contained in:
Stefan Palicki
2025-07-23 17:29:05 -07:00
parent 6719f2dfa9
commit 608fc3ae0b
2 changed files with 7 additions and 9 deletions

View File

@ -84,10 +84,10 @@ if(UNIX)
endif()
elseif(WIN32)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
append(ONEDNN_SDL_COMPILER_FLAGS "/GS /Gy /guard:cf /DYNAMICBASE /sdl")
append(ONEDNN_SDL_COMPILER_FLAGS "/EHsr /GS /Gy /guard:cf /DYNAMICBASE /sdl")
append(ONEDNN_SDL_LINKER_FLAGS "/NXCOMPAT /LTCG")
elseif(CMAKE_BASE_NAME STREQUAL "icx")
append(ONEDNN_SDL_COMPILER_FLAGS "/GS /Gy /guard:cf /Wformat /Wformat-security")
append(ONEDNN_SDL_COMPILER_FLAGS "/EHs /GS /Gy /guard:cf /Wformat /Wformat-security")
append(ONEDNN_SDL_LINKER_FLAGS "/link /NXCOMPAT")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
append(ONEDNN_SDL_COMPILER_FLAGS "-Wformat -Wformat-security")

View File

@ -31,16 +31,14 @@
#include <unordered_map>
#include "oneapi/dnnl/dnnl_common.h"
/// @endcond
// __cpp_exceptions is referred from
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html
// gcc < 5 does not define __cpp_exceptions but __EXCEPTIONS,
// Microsoft C++ Compiler does not provide an option to disable exceptions
// If exceptions are enabled:
// - gcc < 5 only define __EXCEPTIONS
// - MSVC and Clang only define __cpp_exceptions
// - new gcc and icx/icpx define both
#ifndef DNNL_ENABLE_EXCEPTIONS
#if __cpp_exceptions || __EXCEPTIONS \
|| (defined(_MSC_VER) && !defined(__clang__))
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions)
#define DNNL_ENABLE_EXCEPTIONS 1
#else
#define DNNL_ENABLE_EXCEPTIONS 0