diff --git a/cmake/platform/msvc.cmake b/cmake/platform/msvc.cmake index 551d4342c..bb1cf5923 100644 --- a/cmake/platform/msvc.cmake +++ b/cmake/platform/msvc.cmake @@ -36,7 +36,7 @@ SET(RP_CXX_FLAGS_COMMON "${RP_CXX_FLAGS_COMMON} /MP") # Test for MSVC-specific compiler flags. # /utf-8 was added in MSVC 2015. INCLUDE(CheckCCompilerFlag) -FOREACH(FLAG_TEST "/sdl" "/guard:cf" "/utf-8") +FOREACH(FLAG_TEST "/sdl" "/utf-8" "/guard:cf" "/guard:ehcont") # CMake doesn't like certain characters in variable names. STRING(REGEX REPLACE "/|:|=" "_" FLAG_TEST_VARNAME "${FLAG_TEST}") @@ -44,24 +44,31 @@ FOREACH(FLAG_TEST "/sdl" "/guard:cf" "/utf-8") IF(CFLAG_${FLAG_TEST_VARNAME}) SET(RP_C_FLAGS_COMMON "${RP_C_FLAGS_COMMON} ${FLAG_TEST}") SET(RP_CXX_FLAGS_COMMON "${RP_CXX_FLAGS_COMMON} ${FLAG_TEST}") - # "/guard:cf" must be added to linker flags in addition to CFLAGS. - IF(FLAG_TEST STREQUAL "/guard:cf") + # "/guard:cf" and "/guard:ehcont" must be added to linker flags in addition to CFLAGS. + IF(FLAG_TEST STREQUAL "/guard:cf" OR FLAG_TEST STREQUAL "/guard:ehcont") SET(RP_EXE_LINKER_FLAGS_COMMON "${RP_EXE_LINKER_FLAGS_COMMON} ${FLAG_TEST}") SET(RP_SHARED_LINKER_FLAGS_COMMON "${RP_SHARED_LINKER_FLAGS_COMMON} ${FLAG_TEST}") SET(RP_MODULE_LINKER_FLAGS_COMMON "${RP_MODULE_LINKER_FLAGS_COMMON} ${FLAG_TEST}") - ENDIF(FLAG_TEST STREQUAL "/guard:cf") + ENDIF(FLAG_TEST STREQUAL "/guard:cf" OR FLAG_TEST STREQUAL "/guard:ehcont") ENDIF(CFLAG_${FLAG_TEST_VARNAME}) UNSET(CFLAG_${FLAG_TEST_VARNAME}) ENDFOREACH() +# Enable /SAFESEH. (i386 only) +IF(_MSVC_C_ARCHITECTURE_FAMILY MATCHES "^([iI]?[xX3]86)$") + SET(RP_EXE_LINKER_FLAGS_COMMON "${RP_EXE_LINKER_FLAGS_COMMON} /SAFESEH") + SET(RP_SHARED_LINKER_FLAGS_COMMON "${RP_SHARED_LINKER_FLAGS_COMMON} /SAFESEH") + SET(RP_MODULE_LINKER_FLAGS_COMMON "${RP_MODULE_LINKER_FLAGS_COMMON} /SAFESEH") +ENDIF() + # MSVC 2019: Enable /CETCOMPAT. # NOTE: i386/amd64 only. (last checked in MSVC 2022 [17.0]) # - LINK : fatal error LNK1246: '/CETCOMPAT' not compatible with 'ARM' target machine; link without '/CETCOMPAT' # - LINK : fatal error LNK1246: '/CETCOMPAT' not compatible with 'ARM64' target machine; link without '/CETCOMPAT' IF(MSVC_VERSION GREATER 1919 AND _MSVC_C_ARCHITECTURE_FAMILY MATCHES "^([iI]?[xX3]86)|([xX]64)$") - SET(RP_EXE_LINKER_FLAGS_COMMON "${RP_EXE_LINKER_FLAGS_COMMON} /CETCOMPAT") - SET(RP_SHARED_LINKER_FLAGS_COMMON "${RP_SHARED_LINKER_FLAGS_COMMON} /CETCOMPAT") - SET(RP_MODULE_LINKER_FLAGS_COMMON "${RP_MODULE_LINKER_FLAGS_COMMON} /CETCOMPAT") + SET(RP_EXE_LINKER_FLAGS_COMMON "${RP_EXE_LINKER_FLAGS_COMMON} /CETCOMPAT") + SET(RP_SHARED_LINKER_FLAGS_COMMON "${RP_SHARED_LINKER_FLAGS_COMMON} /CETCOMPAT") + SET(RP_MODULE_LINKER_FLAGS_COMMON "${RP_MODULE_LINKER_FLAGS_COMMON} /CETCOMPAT") ENDIF() # MSVC: C/C++ conformance settings